summaryrefslogtreecommitdiff
path: root/src/render/RenderBuffer.cpp
blob: 9a1ed58dd96adca43b3f4561dfb491e2c36dfad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "common.h"
#include "patcher.h"
#include "RenderBuffer.h"

int32 &TempBufferVerticesStored = *(int32*)0x8F5F78;
int32 &TempBufferIndicesStored = *(int32*)0x8F1A4C;

RwIm3DVertex *TempVertexBuffer = (RwIm3DVertex*)0x862330;
RwImVertexIndex *TempBufferRenderIndexList = (RwImVertexIndex*)0x846288;

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 >= 1024)
		RenderStuffInBuffer();
	if(TempBufferVerticesStored + numVertices >= 256)
		RenderStuffInBuffer();
        *indexStart = &TempBufferRenderIndexList[TempBufferIndicesStored];
        *vertexStart = &TempVertexBuffer[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(TempVertexBuffer, 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