summaryrefslogblamecommitdiffstats
path: root/src/render/RenderBuffer.cpp
blob: 4225619f2c47c84034b35abad61352e8d8cc53d8 (plain) (tree)
1
2
3
4
5
6
7
8
9



                         

                               
 

                                                               
 

                                     










                                                                                                                     
                                                                       
                                      
                                                                        

                                                                          
                                                                           
















                                                                                            
                                                                                                                                  











                                                                                                                    
#include "common.h"
#include "patcher.h"
#include "RenderBuffer.h"

int32 TempBufferVerticesStored;
int32 TempBufferIndicesStored;

RwIm3DVertex TempBufferRenderVertices[TEMPBUFFERVERTSIZE];
RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE];

int RenderBuffer::VerticesToBeStored;
int RenderBuffer::IndicesToBeStored;

void
RenderBuffer::ClearRenderBuffer(void)
{
	TempBufferVerticesStored = 0;
	TempBufferIndicesStored = 0;
}

void
RenderBuffer::StartStoring(int numIndices, int numVertices, RwImVertexIndex **indexStart, RwIm3DVertex **vertexStart)
{
	if(TempBufferIndicesStored + numIndices >= TEMPBUFFERINDEXSIZE)
		RenderStuffInBuffer();
	if(TempBufferVerticesStored + numVertices >= TEMPBUFFERVERTSIZE)
		RenderStuffInBuffer();
        *indexStart = &TempBufferRenderIndexList[TempBufferIndicesStored];
        *vertexStart = &TempBufferRenderVertices[TempBufferVerticesStored];
        IndicesToBeStored = numIndices;
        VerticesToBeStored = numVertices;
}

void
RenderBuffer::StopStoring(void)
{
	int i;
	for(i = TempBufferIndicesStored; i < TempBufferIndicesStored+IndicesToBeStored; i++)
		TempBufferRenderIndexList[i] += TempBufferVerticesStored;
	TempBufferIndicesStored += IndicesToBeStored;
	TempBufferVerticesStored += VerticesToBeStored;
}

void
RenderBuffer::RenderStuffInBuffer(void)
{
	if(TempBufferVerticesStored && RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){
		RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored);
		RwIm3DEnd();
	}
	ClearRenderBuffer();
}

STARTPATCHES
	InjectHook(0x517620, RenderBuffer::ClearRenderBuffer, PATCH_JUMP);
	InjectHook(0x517640, RenderBuffer::StartStoring, PATCH_JUMP);
	InjectHook(0x5176B0, RenderBuffer::StopStoring, PATCH_JUMP);
	InjectHook(0x5177C0, RenderBuffer::RenderStuffInBuffer, PATCH_JUMP);
ENDPATCHES