mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-26 02:19:24 +01:00
remove redundant stuff from render loop
This commit is contained in:
parent
3fcc17b336
commit
5ed60e662e
@ -4,7 +4,7 @@ const GLchar *PassthroughVertShader110Src =
|
|||||||
"#version 110\n"
|
"#version 110\n"
|
||||||
"varying vec2 TexCoord0; \n"
|
"varying vec2 TexCoord0; \n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main(void)\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_Position = ftransform(); \n"
|
" gl_Position = ftransform(); \n"
|
||||||
" TexCoord0 = gl_MultiTexCoord0.xy; \n"
|
" TexCoord0 = gl_MultiTexCoord0.xy; \n"
|
||||||
@ -12,8 +12,8 @@ const GLchar *PassthroughVertShader110Src =
|
|||||||
|
|
||||||
const GLchar *PaletteFragShader110Src =
|
const GLchar *PaletteFragShader110Src =
|
||||||
"#version 110\n"
|
"#version 110\n"
|
||||||
"uniform sampler2D PaletteTex; \n"
|
|
||||||
"uniform sampler2D SurfaceTex; \n"
|
"uniform sampler2D SurfaceTex; \n"
|
||||||
|
"uniform sampler2D PaletteTex; \n"
|
||||||
"varying vec2 TexCoord0; \n"
|
"varying vec2 TexCoord0; \n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@ -81,8 +81,8 @@ const GLchar *PaletteFragShaderSrc =
|
|||||||
"#define COMPAT_PRECISION\n"
|
"#define COMPAT_PRECISION\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"\n"
|
"\n"
|
||||||
"uniform sampler2D PaletteTex;\n"
|
|
||||||
"uniform sampler2D SurfaceTex;\n"
|
"uniform sampler2D SurfaceTex;\n"
|
||||||
|
"uniform sampler2D PaletteTex;\n"
|
||||||
"COMPAT_VARYING vec4 TEX0;\n"
|
"COMPAT_VARYING vec4 TEX0;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
|
67
src/render.c
67
src/render.c
@ -92,7 +92,8 @@ DWORD WINAPI render_main(void)
|
|||||||
BOOL gotOpenglV3 = glGenFramebuffers && glBindFramebuffer && glFramebufferTexture2D && glDrawBuffers &&
|
BOOL gotOpenglV3 = glGenFramebuffers && glBindFramebuffer && glFramebufferTexture2D && glDrawBuffers &&
|
||||||
glCheckFramebufferStatus && glUniform4f && glActiveTexture && glUniform1i &&
|
glCheckFramebufferStatus && glUniform4f && glActiveTexture && glUniform1i &&
|
||||||
glGetAttribLocation && glGenBuffers && glBindBuffer && glBufferData && glVertexAttribPointer &&
|
glGetAttribLocation && glGenBuffers && glBindBuffer && glBufferData && glVertexAttribPointer &&
|
||||||
glEnableVertexAttribArray && glUniform2fv && glUniformMatrix4fv && glGenVertexArrays && glBindVertexArray;
|
glEnableVertexAttribArray && glUniform2fv && glUniformMatrix4fv && glGenVertexArrays && glBindVertexArray &&
|
||||||
|
glGetUniformLocation;
|
||||||
|
|
||||||
BOOL gotOpenglV2 = glGetUniformLocation && glActiveTexture && glUniform1i;
|
BOOL gotOpenglV2 = glGetUniformLocation && glActiveTexture && glUniform1i;
|
||||||
|
|
||||||
@ -150,17 +151,14 @@ DWORD WINAPI render_main(void)
|
|||||||
ddraw->render.viewport.width, ddraw->render.viewport.height);
|
ddraw->render.viewport.width, ddraw->render.viewport.height);
|
||||||
|
|
||||||
|
|
||||||
GLint surfaceUniLoc = -1, paletteUniLoc = -1, mainTexCoordAttrLoc = -1, mainVertexCoordAttrLoc = -1;
|
GLint mainTexCoordAttrLoc = -1, mainVertexCoordAttrLoc = -1;
|
||||||
GLuint mainVbos[3], mainVao;
|
GLuint mainVbos[3], mainVao;
|
||||||
if (paletteConvProgram)
|
if (paletteConvProgram)
|
||||||
{
|
{
|
||||||
surfaceUniLoc = glGetUniformLocation(paletteConvProgram, "SurfaceTex");
|
glUseProgram(paletteConvProgram);
|
||||||
paletteUniLoc = glGetUniformLocation(paletteConvProgram, "PaletteTex");
|
|
||||||
|
|
||||||
if (gotOpenglV3)
|
if (gotOpenglV3)
|
||||||
{
|
{
|
||||||
glUseProgram(paletteConvProgram);
|
|
||||||
|
|
||||||
mainVertexCoordAttrLoc = glGetAttribLocation(paletteConvProgram, "VertexCoord");
|
mainVertexCoordAttrLoc = glGetAttribLocation(paletteConvProgram, "VertexCoord");
|
||||||
mainTexCoordAttrLoc = glGetAttribLocation(paletteConvProgram, "TexCoord");
|
mainTexCoordAttrLoc = glGetAttribLocation(paletteConvProgram, "TexCoord");
|
||||||
|
|
||||||
@ -244,9 +242,21 @@ DWORD WINAPI render_main(void)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(paletteConvProgram, "MVPMatrix"), 1, GL_FALSE, mvpMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(paletteConvProgram, "MVPMatrix"), 1, GL_FALSE, mvpMatrix);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, surfaceTexId);
|
||||||
|
glUniform1i(glGetUniformLocation(paletteConvProgram, "SurfaceTex"), 0);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, paletteTexId);
|
||||||
|
glUniform1i(glGetUniformLocation(paletteConvProgram, "PaletteTex"), 1);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLint textureUniLoc = -1, frameCountUniLoc = -1;
|
GLint frameCountUniLoc = -1;
|
||||||
GLuint frameBufferId = 0;
|
GLuint frameBufferId = 0;
|
||||||
GLuint frameBufferTexId = 0;
|
GLuint frameBufferTexId = 0;
|
||||||
GLuint scaleVbos[3], scaleVao;
|
GLuint scaleVbos[3], scaleVao;
|
||||||
@ -257,7 +267,6 @@ DWORD WINAPI render_main(void)
|
|||||||
|
|
||||||
GLint vertexCoordAttrLoc = glGetAttribLocation(scaleProgram, "VertexCoord");
|
GLint vertexCoordAttrLoc = glGetAttribLocation(scaleProgram, "VertexCoord");
|
||||||
GLint texCoordAttrLoc = glGetAttribLocation(scaleProgram, "TexCoord");
|
GLint texCoordAttrLoc = glGetAttribLocation(scaleProgram, "TexCoord");
|
||||||
textureUniLoc = glGetUniformLocation(scaleProgram, "Texture");
|
|
||||||
frameCountUniLoc = glGetUniformLocation(scaleProgram, "FrameCount");
|
frameCountUniLoc = glGetUniformLocation(scaleProgram, "FrameCount");
|
||||||
|
|
||||||
glGenBuffers(3, scaleVbos);
|
glGenBuffers(3, scaleVbos);
|
||||||
@ -319,6 +328,7 @@ DWORD WINAPI render_main(void)
|
|||||||
glUniform2fv(glGetUniformLocation(scaleProgram, "TextureSize"), 1, textureSize);
|
glUniform2fv(glGetUniformLocation(scaleProgram, "TextureSize"), 1, textureSize);
|
||||||
glUniform2fv(glGetUniformLocation(scaleProgram, "InputSize"), 1, inputSize);
|
glUniform2fv(glGetUniformLocation(scaleProgram, "InputSize"), 1, inputSize);
|
||||||
glUniform1i(glGetUniformLocation(scaleProgram, "FrameDirection"), 1);
|
glUniform1i(glGetUniformLocation(scaleProgram, "FrameDirection"), 1);
|
||||||
|
glUniform1i(glGetUniformLocation(scaleProgram, "Texture"), 0);
|
||||||
|
|
||||||
const float mvpMatrix[16] = {
|
const float mvpMatrix[16] = {
|
||||||
1,0,0,0,
|
1,0,0,0,
|
||||||
@ -389,13 +399,16 @@ DWORD WINAPI render_main(void)
|
|||||||
glEnableVertexAttribArray(mainTexCoordAttrLoc);
|
glEnableVertexAttribArray(mainTexCoordAttrLoc);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
glUseProgram(paletteConvProgram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
BOOL useOpenGL = !(ddraw->autorenderer && (!paletteConvProgram || glGetError() != GL_NO_ERROR));
|
BOOL useOpenGL = !(ddraw->autorenderer && (!paletteConvProgram || glGetError() != GL_NO_ERROR));
|
||||||
@ -519,26 +532,15 @@ DWORD WINAPI render_main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paletteConvProgram)
|
|
||||||
{
|
|
||||||
glUseProgram(paletteConvProgram);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, paletteTexId);
|
|
||||||
glUniform1i(paletteUniLoc, 0);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, surfaceTexId);
|
|
||||||
glUniform1i(surfaceUniLoc, 1);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scaleProgram && paletteConvProgram)
|
if (scaleProgram && paletteConvProgram)
|
||||||
{
|
{
|
||||||
// draw surface into framebuffer
|
// draw surface into framebuffer
|
||||||
|
glUseProgram(paletteConvProgram);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, surfaceTexId);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, paletteTexId);
|
||||||
|
|
||||||
glViewport(0, 0, ddraw->width, ddraw->height);
|
glViewport(0, 0, ddraw->width, ddraw->height);
|
||||||
|
|
||||||
@ -550,20 +552,18 @@ DWORD WINAPI render_main(void)
|
|||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
glViewport(
|
glViewport(
|
||||||
ddraw->render.viewport.x, ddraw->render.viewport.y,
|
ddraw->render.viewport.x, ddraw->render.viewport.y,
|
||||||
ddraw->render.viewport.width, ddraw->render.viewport.height);
|
ddraw->render.viewport.width, ddraw->render.viewport.height);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
// apply filter
|
// apply filter
|
||||||
|
|
||||||
glUseProgram(scaleProgram);
|
glUseProgram(scaleProgram);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, frameBufferTexId);
|
glBindTexture(GL_TEXTURE_2D, frameBufferTexId);
|
||||||
glUniform1i(textureUniLoc, 0);
|
|
||||||
|
|
||||||
static int frames = 1;
|
static int frames = 1;
|
||||||
if (frameCountUniLoc != -1)
|
if (frameCountUniLoc != -1)
|
||||||
@ -589,11 +589,6 @@ DWORD WINAPI render_main(void)
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scaleProgram && !paletteConvProgram)
|
|
||||||
glUseProgram(0);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
SwapBuffers(ddraw->render.hDC);
|
SwapBuffers(ddraw->render.hDC);
|
||||||
|
|
||||||
if (maxfps > 0)
|
if (maxfps > 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user