00001
00002
00003 This file is subject to the terms and conditions of the GNU Lesser
00004 General Public License Version 2.1. See the file "COPYING" in the
00005 main directory of this archive for more details. */
00006
00007 #ifndef ps2gl_base_renderer_h
00008 #define ps2gl_base_renderer_h
00009
00010 #include "ps2gl/renderer.h"
00011
00012 #include "ps2s/cpu_vector.h"
00013 #include "ps2s/gs.h"
00014
00015
00016 * code common to ps2gl's built-in renderers
00017 */
00018
00019 class CBaseRenderer : public CRenderer {
00020 protected:
00021
00022 bool XferVertices, XferColors, XferNormals, XferTexCoords;
00023
00024 bool VifDoubleBuffered;
00025
00026
00027 float CurTexCoord[2];
00028 cpu_vec_xyz CurNormal;
00029 CDmaPacket *TexCoordBuf, *NormalBuf;
00030
00031 int WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
00032 unsigned int VertexUnpackMode, NormalUnpackMode;
00033 unsigned int TexCoordUnpackMode, ColorUnpackMode;
00034 Vifs::tMask VertexUnpackMask, NormalUnpackMask;
00035 Vifs::tMask TexCoordUnpackMask, ColorUnpackMask;
00036
00037 int InputQuadsPerVert, OutputQuadsPerVert;
00038 int InputGeomOffset;
00039
00040 void *MicrocodePacket;
00041
00042 const char *Name;
00043
00044 CBaseRenderer( void *packet,
00045 int inQuadsPerVert, int outQuadsPerVert,
00046 int inGeomOffset, const char *name)
00047 : XferVertices(true), VifDoubleBuffered(true),
00048 WordsPerVertex(0), WordsPerNormal(0), WordsPerTexCoord(0), WordsPerColor(0),
00049 InputQuadsPerVert(inQuadsPerVert), OutputQuadsPerVert(outQuadsPerVert),
00050 InputGeomOffset(inGeomOffset),
00051 MicrocodePacket(packet),
00052 Name(name)
00053 {}
00054
00055 CBaseRenderer( void *packet, CRendererProps caps, CRendererProps reqs,
00056 int inQuadsPerVert, int outQuadsPerVert,
00057 int inGeomOffset, const char *name)
00058 : CRenderer(caps, reqs),
00059 XferVertices(true), VifDoubleBuffered(true),
00060 WordsPerVertex(0), WordsPerNormal(0), WordsPerTexCoord(0), WordsPerColor(0),
00061 InputQuadsPerVert(inQuadsPerVert), OutputQuadsPerVert(outQuadsPerVert),
00062 InputGeomOffset(inGeomOffset),
00063 MicrocodePacket(packet),
00064 Name(name)
00065 {}
00066
00067 void SetVifDoubleBuffered( bool db ) { VifDoubleBuffered = db; }
00068
00069
00070 void GetUnpackAttribs( int numWords, unsigned int &mode, Vifs::tMask &mask );
00071
00072
00073 void InitXferBlock( CVifSCDmaPacket &packet,
00074 int wordsPerVertex, int wordsPerNormal,
00075 int wordsPerTex, int wordsPerColor );
00076
00077
00078 void XferBlock( CVifSCDmaPacket &packet,
00079 const void *vertices, const void *normals,
00080 const void *texCoords, const void *colors,
00081 int vu1Offset, int firstElement, int numToAdd );
00082
00083
00084 void XferVectors( CVifSCDmaPacket &packet, unsigned int *dataStart,
00085 int startOffset, int numVectors, int wordsPerVec,
00086 Vifs::tMask unpackMask, tU32 unpackMode,
00087 int vu1MemOffset );
00088
00089
00090 void AddVu1RendererContext( CVifSCDmaPacket &packet, GLenum primType, int vu1Offset );
00091 tGifTag BuildGiftag( GLenum primType );
00092 void CacheRendererState();
00093
00094 float GetMaxColorValue( bool texEnabled ) {
00095
00096
00097
00098 return (texEnabled) ? 128.0f : 255.0f;
00099 }
00100 public:
00101 virtual void Load();
00102 virtual const char* GetName() { return Name; }
00103 };
00104
00105 #endif // ps2gl_base_renderer_h