Beautify some tabs.

This commit is contained in:
Ryan Houdek 2012-12-26 10:33:45 -06:00
parent e2489196e4
commit 2d4c3c7c91
2 changed files with 120 additions and 123 deletions

View File

@ -29,15 +29,15 @@
namespace HwRasterizer namespace HwRasterizer
{ {
float efbHalfWidth; float efbHalfWidth;
float efbHalfHeight; float efbHalfHeight;
bool hasTexture; bool hasTexture;
u8 *temp; u8 *temp;
// Programs // Programs
static GLuint colProg, texProg, clearProg; static GLuint colProg, texProg, clearProg;
// Color // Color
static GLint col_apos = -1, col_atex = -1; static GLint col_apos = -1, col_atex = -1;
// Tex // Tex
@ -58,9 +58,7 @@ namespace HwRasterizer
"varying " PREC " vec4 TexCoordOut;\n" "varying " PREC " vec4 TexCoordOut;\n"
"uniform " TEXTYPE " Texture;\n" "uniform " TEXTYPE " Texture;\n"
"void main() {\n" "void main() {\n"
" " PREC " vec4 tmpcolor;\n" " gl_FragColor = " TEXFUNC "(Texture, TexCoordOut.xy);\n"
" tmpcolor = " TEXFUNC "(Texture, TexCoordOut.xy);\n"
" gl_FragColor = tmpcolor;\n"
"}\n"; "}\n";
// Clear shader // Clear shader
static const char *fragclearText = static const char *fragclearText =
@ -74,7 +72,7 @@ namespace HwRasterizer
"attribute vec4 TexCoordIn;\n " "attribute vec4 TexCoordIn;\n "
"varying vec4 TexCoordOut;\n " "varying vec4 TexCoordOut;\n "
"void main() {\n" "void main() {\n"
" gl_Position = pos;\n" " gl_Position = pos;\n"
" TexCoordOut = TexCoordIn;\n" " TexCoordOut = TexCoordIn;\n"
"}\n"; "}\n";
static const char *vertclearText = static const char *vertclearText =
@ -104,13 +102,13 @@ namespace HwRasterizer
clear_ucol = glGetUniformLocation(clearProg, "Color"); clear_ucol = glGetUniformLocation(clearProg, "Color");
} }
void Init() void Init()
{ {
efbHalfWidth = EFB_WIDTH / 2.0f; efbHalfWidth = EFB_WIDTH / 2.0f;
efbHalfHeight = 480 / 2.0f; efbHalfHeight = 480 / 2.0f;
temp = (u8*)AllocateMemoryPages(TEMP_SIZE); temp = (u8*)AllocateMemoryPages(TEMP_SIZE);
} }
void Shutdown() void Shutdown()
{ {
glDeleteProgram(colProg); glDeleteProgram(colProg);
@ -150,10 +148,10 @@ namespace HwRasterizer
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
static float width, height; static float width, height;
void LoadTexture() void LoadTexture()
{ {
FourTexUnits &texUnit = bpmem.tex[0]; FourTexUnits &texUnit = bpmem.tex[0];
u32 imageAddr = texUnit.texImage3[0].image_base; u32 imageAddr = texUnit.texImage3[0].image_base;
// Texture Rectangle uses pixel coordinates // Texture Rectangle uses pixel coordinates
// While GLES uses texture coordinates // While GLES uses texture coordinates
#ifdef USE_GLES #ifdef USE_GLES
@ -163,36 +161,36 @@ namespace HwRasterizer
width = 1; width = 1;
height = 1; height = 1;
#endif #endif
TexCacheEntry &cacheEntry = textures[imageAddr]; TexCacheEntry &cacheEntry = textures[imageAddr];
cacheEntry.Update(); cacheEntry.Update();
glBindTexture(TEX2D, cacheEntry.texture); glBindTexture(TEX2D, cacheEntry.texture);
glTexParameteri(TEX2D, GL_TEXTURE_MAG_FILTER, texUnit.texMode0[0].mag_filter ? GL_LINEAR : GL_NEAREST); glTexParameteri(TEX2D, GL_TEXTURE_MAG_FILTER, texUnit.texMode0[0].mag_filter ? GL_LINEAR : GL_NEAREST);
glTexParameteri(TEX2D, GL_TEXTURE_MIN_FILTER, (texUnit.texMode0[0].min_filter >= 4) ? GL_LINEAR : GL_NEAREST); glTexParameteri(TEX2D, GL_TEXTURE_MIN_FILTER, (texUnit.texMode0[0].min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
void BeginTriangles() void BeginTriangles()
{ {
// disabling depth test sometimes allows more things to be visible // disabling depth test sometimes allows more things to be visible
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND); glEnable(GL_BLEND);
hasTexture = bpmem.tevorders[0].enable0; hasTexture = bpmem.tevorders[0].enable0;
if (hasTexture) if (hasTexture)
LoadTexture(); LoadTexture();
} }
void EndTriangles() void EndTriangles()
{ {
glBindTexture(TEX2D, 0); glBindTexture(TEX2D, 0);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
void DrawColorVertex(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2) void DrawColorVertex(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
{ {
float x0 = (v0->screenPosition.x / efbHalfWidth) - 1.0f; float x0 = (v0->screenPosition.x / efbHalfWidth) - 1.0f;
float y0 = 1.0f - (v0->screenPosition.y / efbHalfHeight); float y0 = 1.0f - (v0->screenPosition.y / efbHalfHeight);
float z0 = v0->screenPosition.z / (float)0x00ffffff; float z0 = v0->screenPosition.z / (float)0x00ffffff;
@ -200,11 +198,11 @@ namespace HwRasterizer
float x1 = (v1->screenPosition.x / efbHalfWidth) - 1.0f; float x1 = (v1->screenPosition.x / efbHalfWidth) - 1.0f;
float y1 = 1.0f - (v1->screenPosition.y / efbHalfHeight); float y1 = 1.0f - (v1->screenPosition.y / efbHalfHeight);
float z1 = v1->screenPosition.z / (float)0x00ffffff; float z1 = v1->screenPosition.z / (float)0x00ffffff;
float x2 = (v2->screenPosition.x / efbHalfWidth) - 1.0f; float x2 = (v2->screenPosition.x / efbHalfWidth) - 1.0f;
float y2 = 1.0f - (v2->screenPosition.y / efbHalfHeight); float y2 = 1.0f - (v2->screenPosition.y / efbHalfHeight);
float z2 = v2->screenPosition.z / (float)0x00ffffff; float z2 = v2->screenPosition.z / (float)0x00ffffff;
float r0 = v0->color[0][OutputVertexData::RED_C] / 255.0f; float r0 = v0->color[0][OutputVertexData::RED_C] / 255.0f;
float g0 = v0->color[0][OutputVertexData::GRN_C] / 255.0f; float g0 = v0->color[0][OutputVertexData::GRN_C] / 255.0f;
float b0 = v0->color[0][OutputVertexData::BLU_C] / 255.0f; float b0 = v0->color[0][OutputVertexData::BLU_C] / 255.0f;
@ -223,9 +221,9 @@ namespace HwRasterizer
{ x2, y2, z2 } { x2, y2, z2 }
}; };
static const GLfloat col[3][4] = { static const GLfloat col[3][4] = {
{ r0, g0, b0, 1.0f }, { r0, g0, b0, 1.0f },
{ r1, g1, b1, 1.0f }, { r1, g1, b1, 1.0f },
{ r2, g2, b2, 1.0f } { r2, g2, b2, 1.0f }
}; };
{ {
glUseProgram(colProg); glUseProgram(colProg);
@ -239,10 +237,10 @@ namespace HwRasterizer
glDisableVertexAttribArray(col_apos); glDisableVertexAttribArray(col_apos);
} }
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
void DrawTextureVertex(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2) void DrawTextureVertex(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
{ {
float x0 = (v0->screenPosition.x / efbHalfWidth) - 1.0f; float x0 = (v0->screenPosition.x / efbHalfWidth) - 1.0f;
float y0 = 1.0f - (v0->screenPosition.y / efbHalfHeight); float y0 = 1.0f - (v0->screenPosition.y / efbHalfHeight);
float z0 = v0->screenPosition.z; float z0 = v0->screenPosition.z;
@ -250,7 +248,7 @@ namespace HwRasterizer
float x1 = (v1->screenPosition.x / efbHalfWidth) - 1.0f; float x1 = (v1->screenPosition.x / efbHalfWidth) - 1.0f;
float y1 = 1.0f - (v1->screenPosition.y / efbHalfHeight); float y1 = 1.0f - (v1->screenPosition.y / efbHalfHeight);
float z1 = v1->screenPosition.z; float z1 = v1->screenPosition.z;
float x2 = (v2->screenPosition.x / efbHalfWidth) - 1.0f; float x2 = (v2->screenPosition.x / efbHalfWidth) - 1.0f;
float y2 = 1.0f - (v2->screenPosition.y / efbHalfHeight); float y2 = 1.0f - (v2->screenPosition.y / efbHalfHeight);
float z2 = v2->screenPosition.z; float z2 = v2->screenPosition.z;
@ -262,7 +260,7 @@ namespace HwRasterizer
float t1 = v1->texCoords[0].y / height; float t1 = v1->texCoords[0].y / height;
float s2 = v2->texCoords[0].x / width; float s2 = v2->texCoords[0].x / width;
float t2 = v2->texCoords[0].y / width; float t2 = v2->texCoords[0].y / height;
static const GLfloat verts[3][3] = { static const GLfloat verts[3][3] = {
{ x0, y0, z0 }, { x0, y0, z0 },
@ -287,28 +285,28 @@ namespace HwRasterizer
glDisableVertexAttribArray(tex_apos); glDisableVertexAttribArray(tex_apos);
} }
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2) void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
{ {
if (hasTexture) if (hasTexture)
DrawTextureVertex(v0, v1, v2); DrawTextureVertex(v0, v1, v2);
else else
DrawColorVertex(v0, v1, v2); DrawColorVertex(v0, v1, v2);
} }
void Clear() void Clear()
{ {
u8 r = (bpmem.clearcolorAR & 0x00ff); u8 r = (bpmem.clearcolorAR & 0x00ff);
u8 g = (bpmem.clearcolorGB & 0xff00) >> 8; u8 g = (bpmem.clearcolorGB & 0xff00) >> 8;
u8 b = (bpmem.clearcolorGB & 0x00ff); u8 b = (bpmem.clearcolorGB & 0x00ff);
u8 a = (bpmem.clearcolorAR & 0xff00) >> 8; u8 a = (bpmem.clearcolorAR & 0xff00) >> 8;
GLfloat left = (GLfloat)bpmem.copyTexSrcXY.x / efbHalfWidth - 1.0f; GLfloat left = (GLfloat)bpmem.copyTexSrcXY.x / efbHalfWidth - 1.0f;
GLfloat top = 1.0f - (GLfloat)bpmem.copyTexSrcXY.y / efbHalfHeight; GLfloat top = 1.0f - (GLfloat)bpmem.copyTexSrcXY.y / efbHalfHeight;
GLfloat right = (GLfloat)(left + bpmem.copyTexSrcWH.x + 1) / efbHalfWidth - 1.0f; GLfloat right = (GLfloat)(left + bpmem.copyTexSrcWH.x + 1) / efbHalfWidth - 1.0f;
GLfloat bottom = 1.0f - (GLfloat)(top + bpmem.copyTexSrcWH.y + 1) / efbHalfHeight; GLfloat bottom = 1.0f - (GLfloat)(top + bpmem.copyTexSrcWH.y + 1) / efbHalfHeight;
GLfloat depth = (GLfloat)bpmem.clearZValue / (GLfloat)0x00ffffff; GLfloat depth = (GLfloat)bpmem.clearZValue / (GLfloat)0x00ffffff;
static const GLfloat verts[4][3] = { static const GLfloat verts[4][3] = {
{ left, top, depth }, { left, top, depth },
{ right, top, depth }, { right, top, depth },
@ -324,62 +322,61 @@ namespace HwRasterizer
glDisableVertexAttribArray(col_apos); glDisableVertexAttribArray(col_apos);
} }
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
TexCacheEntry::TexCacheEntry() TexCacheEntry::TexCacheEntry()
{ {
Create(); Create();
} }
void TexCacheEntry::Create() void TexCacheEntry::Create()
{ {
FourTexUnits &texUnit = bpmem.tex[0]; FourTexUnits &texUnit = bpmem.tex[0];
texImage0.hex = texUnit.texImage0[0].hex; texImage0.hex = texUnit.texImage0[0].hex;
texImage1.hex = texUnit.texImage1[0].hex; texImage1.hex = texUnit.texImage1[0].hex;
texImage2.hex = texUnit.texImage2[0].hex; texImage2.hex = texUnit.texImage2[0].hex;
texImage3.hex = texUnit.texImage3[0].hex; texImage3.hex = texUnit.texImage3[0].hex;
texTlut.hex = texUnit.texTlut[0].hex; texTlut.hex = texUnit.texTlut[0].hex;
int width = texImage0.width; int width = texImage0.width;
int height = texImage0.height; int height = texImage0.height;
DebugUtil::GetTextureBGRA(temp, 0, 0, width, height); DebugUtil::GetTextureBGRA(temp, 0, 0, width, height);
glGenTextures(1, (GLuint *)&texture); glGenTextures(1, (GLuint *)&texture);
glBindTexture(TEX2D, texture); glBindTexture(TEX2D, texture);
#ifdef USE_GLES #ifdef USE_GLES
glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp); glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp);
#else #else
glTexImage2D(TEX2D, 0, GL_RGBA8, (GLsizei)width, (GLsizei)height, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp); glTexImage2D(TEX2D, 0, GL_RGBA8, (GLsizei)width, (GLsizei)height, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp);
#endif #endif
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
void TexCacheEntry::Destroy() void TexCacheEntry::Destroy()
{ {
if (texture == 0) if (texture == 0)
return; return;
glDeleteTextures(1, &texture); glDeleteTextures(1, &texture);
texture = 0; texture = 0;
} }
void TexCacheEntry::Update() void TexCacheEntry::Update()
{ {
FourTexUnits &texUnit = bpmem.tex[0]; FourTexUnits &texUnit = bpmem.tex[0];
// extra checks cause textures to be reloaded much more
if (texUnit.texImage0[0].hex != texImage0.hex ||
//texUnit.texImage1[0].hex != texImage1.hex ||
//texUnit.texImage2[0].hex != texImage2.hex ||
texUnit.texImage3[0].hex != texImage3.hex ||
texUnit.texTlut[0].hex != texTlut.hex)
{
Destroy();
Create();
}
}
// extra checks cause textures to be reloaded much more
if (texUnit.texImage0[0].hex != texImage0.hex ||
//texUnit.texImage1[0].hex != texImage1.hex ||
//texUnit.texImage2[0].hex != texImage2.hex ||
texUnit.texImage3[0].hex != texImage3.hex ||
texUnit.texTlut[0].hex != texTlut.hex)
{
Destroy();
Create();
}
}
} }

View File

@ -41,7 +41,7 @@ void SWRenderer::Init()
void SWRenderer::Shutdown() void SWRenderer::Shutdown()
{ {
glDeleteProgram(program); glDeleteProgram(program);
glDeleteTextures(1, &s_RenderTarget); glDeleteTextures(1, &s_RenderTarget);
#ifndef USE_GLES #ifndef USE_GLES
delete s_pfont; delete s_pfont;
s_pfont = 0; s_pfont = 0;
@ -79,12 +79,12 @@ void CreateShaders()
void SWRenderer::Prepare() void SWRenderer::Prepare()
{ {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
glGenTextures(1, &s_RenderTarget); glGenTextures(1, &s_RenderTarget);
CreateShaders(); CreateShaders();
#ifndef USE_GLES #ifndef USE_GLES
s_pfont = new RasterFont(); s_pfont = new RasterFont();
glEnable(GL_TEXTURE_RECTANGLE_ARB); glEnable(GL_TEXTURE_RECTANGLE_ARB);
#endif #endif
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
@ -106,7 +106,7 @@ void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
void SWRenderer::DrawDebugText() void SWRenderer::DrawDebugText()
{ {
char debugtext_buffer[8192]; char debugtext_buffer[8192];
char *p = debugtext_buffer; char *p = debugtext_buffer;
p[0] = 0; p[0] = 0;
@ -134,21 +134,21 @@ void SWRenderer::DrawDebugText()
void SWRenderer::DrawTexture(u8 *texture, int width, int height) void SWRenderer::DrawTexture(u8 *texture, int width, int height)
{ {
GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth(); GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight(); GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();
// Update GLViewPort // Update GLViewPort
glViewport(0, 0, glWidth, glHeight); glViewport(0, 0, glWidth, glHeight);
glScissor(0, 0, glWidth, glHeight); glScissor(0, 0, glWidth, glHeight);
glBindTexture(TEX2D, s_RenderTarget); glBindTexture(TEX2D, s_RenderTarget);
glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
glTexParameteri(TEX2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(TEX2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(TEX2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(TEX2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GLfloat u_max = (GLfloat)width; GLfloat u_max = (GLfloat)width;
GLfloat v_max = (GLfloat)glHeight; GLfloat v_max = (GLfloat)glHeight;
static const GLfloat verts[4][2] = { static const GLfloat verts[4][2] = {
{ -1, -1}, // Left top { -1, -1}, // Left top
@ -174,30 +174,30 @@ void SWRenderer::DrawTexture(u8 *texture, int width, int height)
#endif #endif
glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts); glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts); glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts);
glEnableVertexAttribArray(attr_pos); glEnableVertexAttribArray(attr_pos);
glEnableVertexAttribArray(attr_tex); glEnableVertexAttribArray(attr_tex);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glUniform1i(uni_tex, 0); glUniform1i(uni_tex, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(attr_pos); glDisableVertexAttribArray(attr_pos);
glDisableVertexAttribArray(attr_tex); glDisableVertexAttribArray(attr_tex);
glBindTexture(TEX2D, 0); glBindTexture(TEX2D, 0);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
} }
void SWRenderer::SwapBuffer() void SWRenderer::SwapBuffer()
{ {
DrawDebugText(); DrawDebugText();
glFlush(); glFlush();
GLInterface->Swap(); GLInterface->Swap();
swstats.ResetFrame(); swstats.ResetFrame();
#ifndef USE_GLES #ifndef USE_GLES
glClearDepth(1.0f); glClearDepth(1.0f);
#endif #endif
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);