9#include "ps2s/cpu_matrix.h"
12#include "ps2gl/glcontext.h"
13#include "ps2gl/indexed_renderer.h"
14#include "ps2gl/lighting.h"
15#include "ps2gl/material.h"
16#include "ps2gl/texture.h"
18#include "vu1_mem_indexed.h"
21 int inQuadsPerVert,
int outQuadsPerVert,
24 inQuadsPerVert, outQuadsPerVert, kInputGeomStart, name)
26 printf(
"Max number of vertices in indexed array is %d\n", (kInputBufSize - 4) / 3 - 3);
27 printf(
"giftag = 0x%04x, context length = 0x%04x (%d)\n",
28 kGifTag, kContextLength, kContextLength);
34 CVifSCDmaPacket& packet = glContext.GetVif1Packet();
38 AddVu1RendererContext(packet, primType, kContextStart);
43 packet.Base(kDoubleBufBase);
44 packet.Offset(kDoubleBufOffset);
53 bool doLighting = lighting.GetLightingEnabled();
55 float maxColorValue = GetMaxColorValue(XferTexCoords);
58 globalAmb = lighting.GetGlobalAmbient() * maxColorValue;
60 globalAmb.set(0, 0, 0, 0);
62 CImmMaterial& material = glContext.GetMaterialManager().GetImmMaterial();
63 cpu_vec_4 materialAmb = material.GetAmbient();
65 cpu_vec_4 materialEmm;
67 materialEmm = material.GetEmission() * maxColorValue;
69 materialEmm = glContext.GetMaterialManager().GetCurColor() * maxColorValue;
71 ConstantVertColor = materialAmb * globalAmb + materialEmm;
77 return Math::Max(geometry.GetTotalVertices() / 70, 1) * 1000;
87 deps.PerVtxMaterial = 1;
94 return !(pGLContext->GetImmLighting().GetLightingEnabled()
95 && !geometry.GetNormalsAreValid());
106 CVifSCDmaPacket& packet = pGLContext->GetVif1Packet();
108 int wordsPerVert = block.GetWordsPerVertex();
109 int wordsPerNormal = (block.GetNormalsAreValid()) ? block.GetWordsPerNormal() : 0;
110 int wordsPerTex = (block.GetTexCoordsAreValid()) ? block.GetWordsPerTexCoord() : 0;
111 int wordsPerColor = (block.GetColorsAreValid()) ? block.GetWordsPerColor() : 0;
113 InitXferBlock(packet, wordsPerVert, wordsPerNormal, wordsPerTex, wordsPerColor);
115 for (
int curArray = 0; curArray < block.GetNumArrays(); curArray++) {
117 const void *normals, *vertices, *texCoords, *colors;
118 vertices = block.GetVerticesAreValid() ? block.GetVertices(curArray) : NULL;
119 normals = block.GetNormalsAreValid() ? block.GetNormals(curArray) : NULL;
120 texCoords = block.GetTexCoordsAreValid() ? block.GetTexCoords(curArray) : NULL;
121 colors = block.GetColorsAreValid() ? block.GetColors(curArray) : NULL;
124 packet.Stcycl(1, 3).Nop();
127 int numIndices = block.GetNumIndices(curArray);
128 const void* indices = block.GetIndices(curArray);
129 int numVertices = block.GetArrayLength(curArray);
132 vertices, normals, texCoords, colors,
140 packet.Stmod(Vifs::AddModes::kOffset);
142 Vifs::tMask mask = { 3, 3, 3, 0,
147 static const float row[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
153 int numIndexQwords = numIndices / 16 + (numIndices % 16 > 0);
154 packet.Ref(Core::MakePtrNormal((
const unsigned int*)indices), numIndexQwords);
157 packet.OpenUnpack(Vifs::UnpackModes::s_16, kInputGeomStart,
158 Packet::kDoubleBuff, Packet::kMasked);
160 packet.CloseUnpack(numIndexQwords * 8);
169 packet.Stmod(Vifs::AddModes::kNone);
170 packet.OpenUnpack(Vifs::UnpackModes::v4_32, 0, Packet::kDoubleBuff);
172 packet += numVertices;
173 packet += numIndices / 2 + (numIndices & 1);
174 packet += numIndices;
177 packet.CloseUnpack();
181 packet.Strow(&ConstantVertColor);
182 packet.Stcycl(numVertices, 0);
183 Vifs::tMask mask = { 1, 1, 1, 3,
188 packet.OpenUnpack(Vifs::UnpackModes::v4_32, kTempAreaStart,
189 Packet::kDoubleBuff, Packet::kMasked);
190 packet.CloseUnpack(numVertices);
void XferBlock(CVifSCDmaPacket &packet, const void *vertices, const void *normals, const void *texCoords, const void *colors, int vu1Offset, int firstElement, int numToAdd)
void InitXferBlock(CVifSCDmaPacket &packet, int wordsPerVertex, int wordsPerNormal, int wordsPerTex, int wordsPerColor)
virtual int GetPacketQwordSize(const CGeometryBlock &geometry)
virtual void DrawIndexedArrays(CGeometryBlock &block)
Draw arrays of vertices that are accessed by index (i.e., glDrawElements)
virtual void InitContext(GLenum primType, tU32 rcChanges, bool userRcChanged)
virtual CRendererProps GetRenderContextDeps()
virtual bool GetCachePackets(const CGeometryBlock &geometry)