From bf5c842bb57d311baa4f6304e30dae5fb9138889 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 20:46:49 -0500 Subject: [PATCH 1/3] (Glitch64) drawing rectangles from vector form of vertices --- Source/Glitch64/main.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Source/Glitch64/main.cpp b/Source/Glitch64/main.cpp index a3bfaa9ef..ce812d3e0 100644 --- a/Source/Glitch64/main.cpp +++ b/Source/Glitch64/main.cpp @@ -1786,26 +1786,44 @@ static void render_rectangle(int texture_number, int src_width, int src_height, int tex_width, int tex_height, int invert) { + GLfloat planar_vertex[2]; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glBegin(GL_QUADS); + glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); + + planar_vertex[0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertex[1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + glVertex2fv(planar_vertex); + glMultiTexCoord2fARB(texture_number, 0.0f, (float)src_height / (float)tex_height); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); + + planar_vertex[0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertex[1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; + glVertex2fv(planar_vertex); + glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, (float)src_height / (float)tex_height); - glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), - invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); + + planar_vertex[0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); + planar_vertex[1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; + glVertex2fv(planar_vertex); + glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, 0.0f); - glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); + + planar_vertex[0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); + planar_vertex[1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + glVertex2fv(planar_vertex); + glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); + + planar_vertex[0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertex[1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + glVertex2fv(planar_vertex); glEnd(); compile_shader(); From c904115353143fc0afebeee3534d84111857e57f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 20:51:47 -0500 Subject: [PATCH 2/3] (Glitch64) Use previous commit to vectorize rectangle to matrix. --- Source/Glitch64/main.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Source/Glitch64/main.cpp b/Source/Glitch64/main.cpp index ce812d3e0..660b86386 100644 --- a/Source/Glitch64/main.cpp +++ b/Source/Glitch64/main.cpp @@ -1786,44 +1786,41 @@ static void render_rectangle(int texture_number, int src_width, int src_height, int tex_width, int tex_height, int invert) { - GLfloat planar_vertex[2]; + GLfloat planar_vertices[5][2]; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + planar_vertices[0][0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertices[0][1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + planar_vertices[1][0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertices[1][1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; + planar_vertices[2][0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); + planar_vertices[2][1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; + planar_vertices[3][0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); + planar_vertices[3][1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + planar_vertices[4][0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertices[4][1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + glBegin(GL_QUADS); glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - - planar_vertex[0] = ((int)dst_x - widtho) / (float)(width / 2); - planar_vertex[1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; - glVertex2fv(planar_vertex); + glVertex2fv(planar_vertices[0]); glMultiTexCoord2fARB(texture_number, 0.0f, (float)src_height / (float)tex_height); - - planar_vertex[0] = ((int)dst_x - widtho) / (float)(width / 2); - planar_vertex[1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; - glVertex2fv(planar_vertex); + glVertex2fv(planar_vertices[1]); glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, (float)src_height / (float)tex_height); - - planar_vertex[0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); - planar_vertex[1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; - glVertex2fv(planar_vertex); + glVertex2fv(planar_vertices[2]); glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, 0.0f); - - planar_vertex[0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); - planar_vertex[1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; - glVertex2fv(planar_vertex); + glVertex2fv(planar_vertices[3]); glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); + glVertex2fv(planar_vertices[4]); - planar_vertex[0] = ((int)dst_x - widtho) / (float)(width / 2); - planar_vertex[1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; - glVertex2fv(planar_vertex); glEnd(); compile_shader(); From a82947b5bd36ed85139f1185c4ace0b59fd24a10 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 21:26:11 -0500 Subject: [PATCH 3/3] (Glitch64) vectorized depth bias triangle strip vertices --- Source/Glitch64/geometry.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Source/Glitch64/geometry.cpp b/Source/Glitch64/geometry.cpp index 12d53a937..adfcc52b7 100644 --- a/Source/Glitch64/geometry.cpp +++ b/Source/Glitch64/geometry.cpp @@ -228,9 +228,13 @@ grDepthMask( FxBool mask ) float biasFactor = 0; void FindBestDepthBias() { + GLfloat vertices[4][3]; float f, bestz = 0.25f; int x; - if (biasFactor) return; + + if (biasFactor) + return; + biasFactor = 64.0f; // default value glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_DEPTH_TEST); @@ -242,14 +246,28 @@ void FindBestDepthBias() glDisable(GL_ALPHA_TEST); glColor4ub(255,255,255,255); glDepthMask(GL_TRUE); - for (x=0, f=1.0f; f<=65536.0f; x+=4, f*=2.0f) { + + for (x = 0; x < 4; x++) + vertices[x][2] = 0.5; + + for (x = 0, f = 1.0f; f <= 65536.0f; x += 4, f *= 2.0f) { float z; + + vertices[0][0] = float(x + 4 - widtho) / (width / 2); + vertices[0][1] = float(0 + 0 - heighto) / (height / 2); + vertices[1][0] = float(x + 0 - widtho) / (width / 2); + vertices[1][1] = float(0 + 0 - heighto) / (height / 2); + vertices[2][0] = float(x + 4 - widtho) / (width / 2); + vertices[2][1] = float(0 + 4 - heighto) / (height / 2); + vertices[3][0] = float(x + 0 - widtho) / (width / 2); + vertices[3][1] = float(0 + 4 - heighto) / (height / 2); glPolygonOffset(0, f); + glBegin(GL_TRIANGLE_STRIP); - glVertex3f(float(x+4 - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5); - glVertex3f(float(x - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5); - glVertex3f(float(x+4 - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5); - glVertex3f(float(x - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5); + glVertex3fv(vertices[0]); + glVertex3fv(vertices[1]); + glVertex3fv(vertices[2]); + glVertex3fv(vertices[3]); glEnd(); glReadPixels(x+2, 2+viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);