move code around

This commit is contained in:
Arisotura 2019-05-10 15:59:46 +02:00
parent 92d67a17de
commit 13b0d13e23
1 changed files with 205 additions and 180 deletions

View File

@ -24,7 +24,7 @@
#include "NDS.h"
#include "GPU.h"
#include "Platform.h"
extern "C" u32 SDL_GetTicks();
namespace GPU3D
{
namespace GLRenderer43
@ -570,6 +570,7 @@ typedef struct
} RendererPolygon;
RendererPolygon PolygonList[2048];
int NumFinalPolys, NumOpaqueFinalPolys;
GLuint ClearVertexBufferID, ClearVertexArrayID;
@ -1094,108 +1095,12 @@ void BuildPolygons(RendererPolygon* polygons, int npolys)
NumVertices = vidx;
}
void VCount144()
void RenderSceneChunk(int y, int h)
{
}
void RenderFrame()
{
// SUCKY!!!!!!!!!!!!!!!!!!
// TODO: detect when VRAM blocks are modified!
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TexMemID);
for (int i = 0; i < 4; i++)
{
u32 mask = GPU::VRAMMap_Texture[i];
u8* vram;
if (!mask) continue;
else if (mask & (1<<0)) vram = GPU::VRAM_A;
else if (mask & (1<<1)) vram = GPU::VRAM_B;
else if (mask & (1<<2)) vram = GPU::VRAM_C;
else if (mask & (1<<3)) vram = GPU::VRAM_D;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i*128, 1024, 128, GL_RED_INTEGER, GL_UNSIGNED_BYTE, vram);
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, TexPalMemID);
for (int i = 0; i < 6; i++)
{
// 6 x 16K chunks
u32 mask = GPU::VRAMMap_TexPal[i];
u8* vram;
if (!mask) continue;
else if (mask & (1<<4)) vram = &GPU::VRAM_E[(i&3)*0x4000];
else if (mask & (1<<5)) vram = GPU::VRAM_F;
else if (mask & (1<<6)) vram = GPU::VRAM_G;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i*8, 1024, 8, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, vram);
}
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
glDisable(GL_BLEND);
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glColorMaski(1, GL_TRUE, GL_TRUE, GL_FALSE, GL_FALSE);
// clear buffers
// TODO: clear bitmap
// TODO: check whether 'clear polygon ID' affects translucent polyID
// (for example when alpha is 1..30)
{
glUseProgram(ClearShaderPlain[2]);
glDepthFunc(GL_ALWAYS);
glDepthMask(GL_TRUE);
u32 r = RenderClearAttr1 & 0x1F;
u32 g = (RenderClearAttr1 >> 5) & 0x1F;
u32 b = (RenderClearAttr1 >> 10) & 0x1F;
u32 fog = (RenderClearAttr1 >> 15) & 0x1;
u32 a = (RenderClearAttr1 >> 16) & 0x1F;
u32 polyid = (RenderClearAttr1 >> 24) & 0x3F;
u32 z = ((RenderClearAttr2 & 0x7FFF) * 0x200) + 0x1FF;
glStencilFunc(GL_ALWAYS, 0, 0xFF);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
/*if (r) r = r*2 + 1;
if (g) g = g*2 + 1;
if (b) b = b*2 + 1;*/
glUniform4ui(0, r, g, b, a);
glUniform1ui(1, z);
glUniform1ui(2, polyid);
glUniform1ui(3, fog);
glBindBuffer(GL_ARRAY_BUFFER, ClearVertexBufferID);
glBindVertexArray(ClearVertexArrayID);
glDrawArrays(GL_TRIANGLES, 0, 2*3);
}
glColorMaski(1, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
if (RenderNumPolygons)
{
// render shit here
u32 flags = 0;
if (RenderPolygonRAM[0]->WBuffer) flags |= RenderFlag_WBuffer;
int npolys = 0;
int firsttrans = -1;
for (int i = 0; i < RenderNumPolygons; i++)
{
if (RenderPolygonRAM[i]->Degenerate) continue;
SetupPolygon(&PolygonList[npolys], RenderPolygonRAM[i]);
if (firsttrans < 0 && RenderPolygonRAM[i]->Translucent)
firsttrans = npolys;
npolys++;
}
BuildPolygons(&PolygonList[0], npolys);
glBindBuffer(GL_ARRAY_BUFFER, VertexBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, NumVertices*7*4, VertexBuffer);
if (h != 192) glScissor(0, y*2, 256*2, h*2);
// pass 1: opaque pixels
@ -1218,21 +1123,21 @@ void RenderFrame()
u32 curkey;
bool lastwasshadow;bool darp;
//printf("morp %08X\n", RenderClearAttr1);
if (firsttrans > -1)
if (NumOpaqueFinalPolys > -1)
{
glColorMaski(1, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
if (PolygonList[firsttrans].PolyData->IsShadow) printf("!! GLORG!!! %08X\n", PolygonList[firsttrans].PolyData->Attr);
if (PolygonList[NumOpaqueFinalPolys].PolyData->IsShadow) printf("!! GLORG!!! %08X\n", PolygonList[NumOpaqueFinalPolys].PolyData->Attr);
// pass 2: if needed, render translucent pixels that are against background pixels
// when background alpha is zero, those need to be rendered with blending disabled
if ((RenderClearAttr1 & 0x001F0000) == 0)
{
iptr = PolygonList[firsttrans].Indices;
iptr = PolygonList[NumOpaqueFinalPolys].Indices;
curkey = 0xFFFFFFFF;
glDisable(GL_BLEND);
for (int i = firsttrans; i < npolys; i++)
for (int i = NumOpaqueFinalPolys; i < NumFinalPolys; i++)
{
RendererPolygon* rp = &PolygonList[i];
if (rp->RenderKey != curkey)
@ -1276,11 +1181,11 @@ if (PolygonList[firsttrans].PolyData->IsShadow) printf("!! GLORG!!! %08X\n", Pol
// pass 3: translucent pixels
iptr = PolygonList[firsttrans].Indices;
iptr = PolygonList[NumOpaqueFinalPolys].Indices;
curkey = 0xFFFFFFFF;
lastwasshadow = false; darp = false;
for (int i = firsttrans; i < npolys; i++)
for (int i = NumOpaqueFinalPolys; i < NumFinalPolys; i++)
{
RendererPolygon* rp = &PolygonList[i];
//printf("PASS 3 POLYGON %i: ATTR %08X (%d) | KEY %08X\n", i, rp->PolyData->Attr, (rp->PolyData->Attr>>4)&0x3, rp->RenderKey);
@ -1375,8 +1280,128 @@ if (PolygonList[firsttrans].PolyData->IsShadow) printf("!! GLORG!!! %08X\n", Pol
if (num) glDrawElements(GL_TRIANGLES, num, GL_UNSIGNED_SHORT, iptr);
}
}
glFlush();
}
void VCount144()
{
}
void RenderFrame()
{
// SUCKY!!!!!!!!!!!!!!!!!!
// TODO: detect when VRAM blocks are modified!
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TexMemID);
for (int i = 0; i < 4; i++)
{
u32 mask = GPU::VRAMMap_Texture[i];
u8* vram;
if (!mask) continue;
else if (mask & (1<<0)) vram = GPU::VRAM_A;
else if (mask & (1<<1)) vram = GPU::VRAM_B;
else if (mask & (1<<2)) vram = GPU::VRAM_C;
else if (mask & (1<<3)) vram = GPU::VRAM_D;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i*128, 1024, 128, GL_RED_INTEGER, GL_UNSIGNED_BYTE, vram);
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, TexPalMemID);
for (int i = 0; i < 6; i++)
{
// 6 x 16K chunks
u32 mask = GPU::VRAMMap_TexPal[i];
u8* vram;
if (!mask) continue;
else if (mask & (1<<4)) vram = &GPU::VRAM_E[(i&3)*0x4000];
else if (mask & (1<<5)) vram = GPU::VRAM_F;
else if (mask & (1<<6)) vram = GPU::VRAM_G;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i*8, 1024, 8, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, vram);
}
//u32 _start = SDL_GetTicks();
//glEnable(GL_SCISSOR_TEST);
//for (int sy=0; sy<384; sy+=96)
// {
//glScissor(0, sy, 512, 96);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
glDisable(GL_BLEND);
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glColorMaski(1, GL_TRUE, GL_TRUE, GL_FALSE, GL_FALSE);
// clear buffers
// TODO: clear bitmap
// TODO: check whether 'clear polygon ID' affects translucent polyID
// (for example when alpha is 1..30)
{
glUseProgram(ClearShaderPlain[2]);
glDepthFunc(GL_ALWAYS);
glDepthMask(GL_TRUE);
u32 r = RenderClearAttr1 & 0x1F;
u32 g = (RenderClearAttr1 >> 5) & 0x1F;
u32 b = (RenderClearAttr1 >> 10) & 0x1F;
u32 fog = (RenderClearAttr1 >> 15) & 0x1;
u32 a = (RenderClearAttr1 >> 16) & 0x1F;
u32 polyid = (RenderClearAttr1 >> 24) & 0x3F;
u32 z = ((RenderClearAttr2 & 0x7FFF) * 0x200) + 0x1FF;
glStencilFunc(GL_ALWAYS, 0, 0xFF);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
/*if (r) r = r*2 + 1;
if (g) g = g*2 + 1;
if (b) b = b*2 + 1;*/
glUniform4ui(0, r, g, b, a);
glUniform1ui(1, z);
glUniform1ui(2, polyid);
glUniform1ui(3, fog);
glBindBuffer(GL_ARRAY_BUFFER, ClearVertexBufferID);
glBindVertexArray(ClearVertexArrayID);
glDrawArrays(GL_TRIANGLES, 0, 2*3);
}
glColorMaski(1, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
if (RenderNumPolygons)
{
// render shit here
u32 flags = 0;
if (RenderPolygonRAM[0]->WBuffer) flags |= RenderFlag_WBuffer;
int npolys = 0;
int firsttrans = -1;
for (int i = 0; i < RenderNumPolygons; i++)
{
if (RenderPolygonRAM[i]->Degenerate) continue;
// zog.
//if (RenderPolygonRAM[i]->YBottom <= 96 || RenderPolygonRAM[i]->YTop >= 144) continue;
SetupPolygon(&PolygonList[npolys], RenderPolygonRAM[i]);
if (firsttrans < 0 && RenderPolygonRAM[i]->Translucent)
firsttrans = npolys;
npolys++;
}
NumFinalPolys = npolys;
NumOpaqueFinalPolys = firsttrans;
BuildPolygons(&PolygonList[0], npolys);
glBindBuffer(GL_ARRAY_BUFFER, VertexBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, NumVertices*7*4, VertexBuffer);
RenderSceneChunk(0, 192);
}
//}
//glFinish();u32 _end=SDL_GetTicks(); printf("render time: %d\n", _end-_start);s
if (false)
{