PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
base_renderer.h
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#ifndef ps2gl_base_renderer_h
8#define ps2gl_base_renderer_h
9
10#include "ps2gl/renderer.h"
11
12#include "ps2s/cpu_vector.h"
13#include "ps2s/gs.h"
14
15/********************************************
16 * code common to ps2gl's built-in renderers
17 */
18
19class CBaseRenderer : public CRenderer {
20protected:
21 // cache some state for use in DrawArrays
22 bool XferVertices, XferColors, XferNormals, XferTexCoords;
23
24 bool VifDoubleBuffered;
25
26 // cached in DrawArrays from geometry manager for XferBlock
27 float CurTexCoord[2];
28 cpu_vec_xyz CurNormal;
29 CDmaPacket *TexCoordBuf, *NormalBuf;
30
31 int WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
32 unsigned int VertexUnpackMode, NormalUnpackMode;
33 unsigned int TexCoordUnpackMode, ColorUnpackMode;
34 Vifs::tMask VertexUnpackMask, NormalUnpackMask;
35 Vifs::tMask TexCoordUnpackMask, ColorUnpackMask;
36
37 int InputQuadsPerVert, OutputQuadsPerVert;
38 int InputGeomOffset;
39
40 void* MicrocodePacket;
41 int MicrocodePacketSize;
42
43 const char* Name;
44
45 CBaseRenderer(void* packet, int packetSize,
46 int inQuadsPerVert, int outQuadsPerVert,
47 int inGeomOffset, const char* name)
48 : XferVertices(true)
49 , VifDoubleBuffered(true)
50 , WordsPerVertex(0)
51 , WordsPerNormal(0)
52 , WordsPerTexCoord(0)
53 , WordsPerColor(0)
54 , InputQuadsPerVert(inQuadsPerVert)
55 , OutputQuadsPerVert(outQuadsPerVert)
56 , InputGeomOffset(inGeomOffset)
57 , MicrocodePacket(packet)
58 , MicrocodePacketSize(packetSize)
59 , Name(name)
60 {
61 }
62
63 CBaseRenderer(void* packet, int packetSize, CRendererProps caps, CRendererProps reqs,
64 int inQuadsPerVert, int outQuadsPerVert,
65 int inGeomOffset, const char* name)
66 : CRenderer(caps, reqs)
67 , XferVertices(true)
68 , VifDoubleBuffered(true)
69 , WordsPerVertex(0)
70 , WordsPerNormal(0)
71 , WordsPerTexCoord(0)
72 , WordsPerColor(0)
73 , InputQuadsPerVert(inQuadsPerVert)
74 , OutputQuadsPerVert(outQuadsPerVert)
75 , InputGeomOffset(inGeomOffset)
76 , MicrocodePacket(packet)
77 , MicrocodePacketSize(packetSize)
78 , Name(name)
79 {
80 }
81
82 void SetVifDoubleBuffered(bool db) { VifDoubleBuffered = db; }
83
84 // used by InitXferBlock
85 void GetUnpackAttribs(int numWords, unsigned int& mode, Vifs::tMask& mask);
86
87 // called by DrawArrays
88 void InitXferBlock(CVifSCDmaPacket& packet,
89 int wordsPerVertex, int wordsPerNormal,
90 int wordsPerTex, int wordsPerColor);
91
92 // used by DrawBlock
93 void XferBlock(CVifSCDmaPacket& packet,
94 const void* vertices, const void* normals,
95 const void* texCoords, const void* colors,
96 int vu1Offset, int firstElement, int numToAdd);
97
98 // used by XferBlock
99 void XferVectors(CVifSCDmaPacket& packet, unsigned int* dataStart,
100 int startOffset, int numVectors, int wordsPerVec,
101 Vifs::tMask unpackMask, tU32 unpackMode,
102 int vu1MemOffset);
103
104 // used by InitContext
105 void AddVu1RendererContext(CVifSCDmaPacket& packet, GLenum primType, int vu1Offset);
106 tGifTag BuildGiftag(GLenum primType);
107 void CacheRendererState();
108
109 float GetMaxColorValue(bool texEnabled)
110 {
111 // when texturing in modulate mode, 100% of a channel occurs at
112 // 0.5 on the gs, so we want a color component value of 1.0 to map to
113 // 128, else 255
114 return (texEnabled) ? 128.0f : 255.0f;
115 }
116
117public:
118 virtual void Load();
119 virtual const char* GetName() { return Name; }
120};
121
122#endif // ps2gl_base_renderer_h
void XferBlock(CVifSCDmaPacket &packet, const void *vertices, const void *normals, const void *texCoords, const void *colors, int vu1Offset, int firstElement, int numToAdd)
virtual const char * GetName()
Return a pointer to the text name of this renderer.
virtual void Load()
Load the renderer into vu0/vu1 memory.
void InitXferBlock(CVifSCDmaPacket &packet, int wordsPerVertex, int wordsPerNormal, int wordsPerTex, int wordsPerColor)