From d18820d3207fec81ce2dc6f5bc77c08d81656fab Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 19 Mar 2011 11:52:14 +0000 Subject: [PATCH] video: enforce shader-enabled GL implementations, getting rid of a lot of code. --- configure.ac | 7 ----- src/debugquad.cpp | 68 ----------------------------------------------- src/eglapp.cpp | 8 ++---- src/lolgl.h | 26 ++---------------- src/scene.cpp | 64 +++++--------------------------------------- src/shader.cpp | 22 --------------- src/video.cpp | 34 +++++------------------- 7 files changed, 16 insertions(+), 213 deletions(-) diff --git a/configure.ac b/configure.ac index 8fd1dd9f..eb3bb030 100644 --- a/configure.ac +++ b/configure.ac @@ -78,12 +78,6 @@ AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") dnl Which version of OpenGL to use? ac_cv_my_have_gl="no" -PKG_CHECK_MODULES(GLES1, glesv1_cm, - [ac_cv_my_have_gl="yes" - AC_DEFINE(HAVE_GLES_1X, 1, Define to 1 if GLES 1.x is available) - GL_CFLAGS="${GLES1_CFLAGS}" - GL_LIBS="${GLES1_LIBS}"], - [:]) PKG_CHECK_MODULES(GLES2, glesv2, [ac_cv_my_have_gl="yes" AC_DEFINE(HAVE_GLES_2X, 1, Define to 1 if GLES 2.x is available) @@ -92,7 +86,6 @@ PKG_CHECK_MODULES(GLES2, glesv2, [:]) AC_CHECK_LIB(GL, glLoadIdentity, [ac_cv_my_have_gl="yes" - AC_DEFINE(HAVE_GL_1X, 1, Define to 1 if GL 1.x is available) AC_DEFINE(HAVE_GL_2X, 1, Define to 1 if GL 2.x is available) GL_LIBS="-lGL"]) # FIXME: hackish if test "${ac_cv_my_have_gl}" = "no"; then diff --git a/src/debugquad.cpp b/src/debugquad.cpp index 585674a5..7bbe02ea 100644 --- a/src/debugquad.cpp +++ b/src/debugquad.cpp @@ -32,12 +32,8 @@ class DebugQuadData private: int initialised; float time; -#if defined HAVE_GL_2X || defined HAVE_GLES_2X GLuint buflist[3]; Shader *shader; -#elif defined HAVE_GL_1X || defined HAVE_GLES_1X - GLuint buflist[3]; -#endif GLuint texlist[1]; uint8_t image[1][32 * 32 * 4]; }; @@ -70,19 +66,14 @@ void DebugQuad::TickDraw(float deltams) { if (data->initialised) { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X glDeleteBuffers(3, data->buflist); Shader::Destroy(data->shader); -#elif defined HAVE_GL_1X || defined HAVE_GLES_1X - glDeleteBuffers(3, data->buflist); -#endif glDeleteTextures(1, data->texlist); data->initialised = 0; } } else if (!data->initialised) { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X glGenBuffers(3, data->buflist); static char const *vertexshader = @@ -108,9 +99,6 @@ void DebugQuad::TickDraw(float deltams) " gl_FragColor = col * tex;\n" "}\n"; data->shader = Shader::Create(vertexshader, fragmentshader); -#elif defined HAVE_GL_1X || defined HAVE_GLES_1X - glGenBuffers(3, data->buflist); -#endif glGenTextures(1, data->texlist); glEnable(GL_TEXTURE_2D); @@ -165,7 +153,6 @@ void DebugQuad::TickDraw(float deltams) { 0.0f, 0.0f }, { 1.0f, 1.0f }, { 1.0f, 0.0f }, }; -#if defined HAVE_GL_2X || defined HAVE_GLES_2X data->shader->Bind(); GLuint attr_pos, attr_col, attr_tex; attr_pos = data->shader->GetAttribLocation("in_Position"); @@ -197,61 +184,6 @@ void DebugQuad::TickDraw(float deltams) glDisableVertexAttribArray(attr_pos); glDisableVertexAttribArray(attr_col); glDisableVertexAttribArray(attr_tex); -#elif defined HAVE_GL_1X || defined HAVE_GLES_1X - /* Reset all model-view-projection matrices */ - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - /* Set up state machine */ - glDisable(GL_DEPTH_TEST); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable(GL_TEXTURE_2D); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - /* Bind texture */ - glClientActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, data->texlist[0]); - - /* Bind vertex, color and texture coordinate buffers */ -#if defined HAVE_GL_1X - glBindBuffer(GL_ARRAY_BUFFER, data->buflist[0]); - glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), verts, GL_STATIC_DRAW); - glVertexPointer(2, GL_FLOAT, 0, NULL); - - glBindBuffer(GL_ARRAY_BUFFER, data->buflist[1]); - glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), cols, GL_STATIC_DRAW); - glColorPointer(4, GL_FLOAT, 0, NULL); - - glBindBuffer(GL_ARRAY_BUFFER, data->buflist[2]); - glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), tcs, GL_STATIC_DRAW); - glTexCoordPointer(2, GL_FLOAT, 0, NULL); -#else - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(4, GL_FLOAT, 0, cols); - glTexCoordPointer(2, GL_FLOAT, 0, tcs); -#endif - - /* Draw arrays */ - glDrawArrays(GL_TRIANGLES, 0, 6); - - /* Disable state machine features */ - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - /* Restore matrices */ - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -#endif } DebugQuad::~DebugQuad() diff --git a/src/eglapp.cpp b/src/eglapp.cpp index 2b95ce92..78056fa6 100644 --- a/src/eglapp.cpp +++ b/src/eglapp.cpp @@ -98,9 +98,7 @@ EglApp::EglApp(char const *title, vec2i res, float fps) : { EGL_BUFFER_SIZE, 16, EGL_RENDERABLE_TYPE, -#if defined HAVE_GLES_1X - EGL_OPENGL_ES_BIT, -#elif defined HAVE_GLES_2X +#if defined HAVE_GLES_2X EGL_OPENGL_ES2_BIT, #endif EGL_NONE @@ -130,9 +128,7 @@ EglApp::EglApp(char const *title, vec2i res, float fps) : EGLint ctxattr[] = { -#if defined HAVE_GLES_1X - EGL_CONTEXT_CLIENT_VERSION, 1, -#elif defined HAVE_GLES_2X +#if defined HAVE_GLES_2X EGL_CONTEXT_CLIENT_VERSION, 2, #endif EGL_NONE diff --git a/src/lolgl.h b/src/lolgl.h index 29f671f8..61de7d2a 100644 --- a/src/lolgl.h +++ b/src/lolgl.h @@ -19,35 +19,18 @@ #define GL_GLEXT_PROTOTYPES /* Only define one GL platform */ -#if defined HAVE_GL_1X -# undef HAVE_GLES_1X -#endif -#if defined HAVE_GLES_2X -# undef HAVE_GL_1X -# undef HAVE_GLES_1X -#endif #if defined HAVE_GL_2X -# undef HAVE_GL_1X -# undef HAVE_GLES_1X # undef HAVE_GLES_2X #endif /* Include GL */ -#if defined HAVE_GL_1X || defined HAVE_GL_2X +#if defined HAVE_GL_2X # if defined __APPLE__ && defined __MACH__ # include # else # define GL_GLEXT_PROTOTYPES # include # endif -#elif defined HAVE_GLES_1X -# if defined __APPLE__ && defined __MACH__ -# include -# include -# else -# include -# include -# endif #elif defined HAVE_GLES_2X # if defined __APPLE__ && defined __MACH__ # include @@ -59,13 +42,8 @@ #endif /* Redefine some function names */ -#if defined HAVE_GL_1X -# define glClearDepthf glClearDepth -#elif defined HAVE_GL_2X +#if defined HAVE_GL_2X # define glClearDepthf glClearDepth -#elif defined HAVE_GLES_1X -# define glGenVertexArrays glGenVertexArraysOES -# define glDeleteVertexArrays glDeleteVertexArraysOES #elif defined HAVE_GLES_2X # define glGenVertexArrays glGenVertexArraysOES # define glDeleteVertexArrays glDeleteVertexArraysOES diff --git a/src/scene.cpp b/src/scene.cpp index 4142a773..d9401da4 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -32,9 +32,7 @@ struct Tile int x, y, z, o; }; -#if defined HAVE_GL_2X || defined HAVE_GLES_2X extern Shader *stdshader; -#endif extern mat4 model_matrix; /* @@ -155,7 +153,6 @@ void Scene::Render() // XXX: rename to Blit() model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f); // XXX: end of debug stuff -#if defined HAVE_GL_2X || defined HAVE_GLES_2X GLuint uni_mat, uni_tex, attr_pos, attr_tex; attr_pos = stdshader->GetAttribLocation("in_Position"); attr_tex = stdshader->GetAttribLocation("in_TexCoord"); @@ -169,31 +166,13 @@ void Scene::Render() // XXX: rename to Blit() glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); -# if !defined HAVE_GLES_2X - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GEQUAL, 0.01f); -# endif - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#else - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); +#if defined HAVE_GL_2X glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GEQUAL, 0.01f); +#endif glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glMultMatrixf(&model_matrix[0][0]); - - /* Set up state machine */ - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable(GL_TEXTURE_2D); - glEnableClientState(GL_VERTEX_ARRAY); -#endif - for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2) { /* Generate new vertex / texture coord buffers if necessary */ @@ -220,18 +199,15 @@ void Scene::Render() // XXX: rename to Blit() vertex + 18 * (j - i), texture + 12 * (j - i)); } -#if defined HAVE_GL_2X || defined HAVE_GLES_2X stdshader->Bind(); -#endif /* Bind texture */ Tiler::Bind(data->tiles[i].code); /* Bind vertex, color and texture coordinate buffers */ -#if defined HAVE_GL_2X || defined HAVE_GLES_2X -# if !defined HAVE_GLES_2X +#if defined HAVE_GL_2X glBindVertexArray(data->vao); -# endif +#endif glEnableVertexAttribArray(attr_pos); glEnableVertexAttribArray(attr_tex); @@ -244,48 +220,20 @@ void Scene::Render() // XXX: rename to Blit() glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), texture, GL_STATIC_DRAW); glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); -#elif defined HAVE_GL_1X - glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]); - glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat), - vertex, GL_STATIC_DRAW); - glVertexPointer(3, GL_FLOAT, 0, NULL); - - glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]); - glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), - texture, GL_STATIC_DRAW); - glTexCoordPointer(2, GL_FLOAT, 0, NULL); -#else - glVertexPointer(3, GL_FLOAT, 0, vertex); - glTexCoordPointer(2, GL_FLOAT, 0, texture); -#endif /* Draw arrays */ glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); -#if defined HAVE_GL_2X || defined HAVE_GLES_2X -# if !defined HAVE_GLES_2X +#if defined HAVE_GL_2X glBindVertexArray(0); -# endif +#endif glDisableVertexAttribArray(attr_pos); glDisableVertexAttribArray(attr_tex); -#endif free(vertex); free(texture); } -#if defined HAVE_GL_1X || defined HAVE_GLES_1X - /* Disable state machine features */ - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - /* Restore matrices */ - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -#endif - free(data->tiles); data->tiles = 0; data->ntiles = 0; diff --git a/src/shader.cpp b/src/shader.cpp index 3684c097..39c7b623 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -34,9 +34,7 @@ class ShaderData friend class Shader; private: -#if defined HAVE_GL_2X || defined HAVE_GLES_2X GLuint prog_id, vert_id, frag_id; -#endif uint32_t vert_crc, frag_crc; /* Global shader cache */ @@ -78,13 +76,10 @@ void Shader::Destroy(Shader *shader) Shader::Shader(char const *vert, char const *frag) : data(new ShaderData()) { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X char buf[4096]; GLsizei len; -#endif data->vert_crc = Hash::Crc32(vert); -#if defined HAVE_GL_2X || defined HAVE_GLES_2X data->vert_id = glCreateShader(GL_VERTEX_SHADER); glShaderSource(data->vert_id, 1, &vert, NULL); glCompileShader(data->vert_id); @@ -92,10 +87,8 @@ Shader::Shader(char const *vert, char const *frag) glGetShaderInfoLog(data->vert_id, sizeof(buf), &len, buf); if (len > 0) Log::Error("failed to compile vertex shader: %s", buf); -#endif data->frag_crc = Hash::Crc32(frag); -#if defined HAVE_GL_2X || defined HAVE_GLES_2X data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(data->frag_id, 1, &frag, NULL); glCompileShader(data->frag_id); @@ -110,45 +103,30 @@ Shader::Shader(char const *vert, char const *frag) glLinkProgram(data->prog_id); glValidateProgram(data->prog_id); -#endif } int Shader::GetAttribLocation(char const *attr) const { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X return glGetAttribLocation(data->prog_id, attr); -#else - (void)attr; - return -1; -#endif } int Shader::GetUniformLocation(char const *uni) const { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X return glGetUniformLocation(data->prog_id, uni); -#else - (void)uni; - return -1; -#endif } void Shader::Bind() const { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X glUseProgram(data->prog_id); -#endif } Shader::~Shader() { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X glDetachShader(data->prog_id, data->vert_id); glDetachShader(data->prog_id, data->frag_id); glDeleteShader(data->vert_id); glDeleteShader(data->frag_id); glDeleteProgram(data->prog_id); -#endif delete data; } diff --git a/src/video.cpp b/src/video.cpp index a36390c2..5d68df0f 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -29,14 +29,11 @@ namespace lol vec2i saved_viewport; #endif -#if defined HAVE_GL_2X || defined HAVE_GLES_2X Shader *stdshader; -#endif mat4 proj_matrix, view_matrix, model_matrix; -#if defined HAVE_GL_2X || defined HAVE_GLES_2X static char const *vertexshader = -#if !defined HAVE_GLES_2X +#if defined HAVE_GL_2X "#version 130\n" #endif "\n" @@ -87,11 +84,10 @@ static char const *fragmentshader = #else " vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n" #endif -#if 1 +#if 0 " float mul = 2.0;\n" - " float dx1 = mod(gl_FragCoord.x, 2.0);\n" - " float dy1 = mod(gl_FragCoord.y, 2.0);\n" - " float t1 = mod(3.0 * dx1 + 2.0 * dy1, 4.0);\n" + " vec2 d1 = mod(vec2(gl_FragCoord), vec2(2.0, 2.0));\n" + " float t1 = mod(3.0 * d1.x + 2.0 * d1.y, 4.0);\n" " float dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);\n" " float dy2 = mod(floor(gl_FragCoord.y * 0.5), 2.0);\n" " float t2 = mod(3.0 * dx2 + 2.0 * dy2, 4.0);\n" @@ -111,7 +107,6 @@ static char const *fragmentshader = #endif " gl_FragColor = col;\n" "}\n"; -#endif /* * Public Video class @@ -129,16 +124,12 @@ void Video::Setup(int width, int height) glClearColor(0.1f, 0.2f, 0.3f, 0.0f); glClearDepthf(1.0); -#if defined HAVE_GL_2X || defined HAVE_GLES_1X +#if defined HAVE_GL_2X glShadeModel(GL_SMOOTH); -#endif -#if defined HAVE_GL_2X || defined HAVE_GLES_1X glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); #endif -#if defined HAVE_GL_2X || defined HAVE_GLES_2X stdshader = Shader::Create(vertexshader, fragmentshader); -#endif } void Video::SetFov(float theta) @@ -188,23 +179,12 @@ void Video::SetFov(float theta) view_matrix = mat4(1.0f); -#if defined HAVE_GL_2X || defined HAVE_GLES_2X stdshader->Bind(); /* Required on GLES 2.x? */ GLuint uni; uni = stdshader->GetUniformLocation("proj_matrix"); glUniformMatrix4fv(uni, 1, GL_FALSE, &proj_matrix[0][0]); uni = stdshader->GetUniformLocation("view_matrix"); glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]); -#else - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMultMatrixf(&proj_matrix[0][0]); - - /* Reset the model view matrix, just in case */ - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMultMatrixf(&view_matrix[0][0]); -#endif } void Video::SetDepth(bool set) @@ -225,9 +205,7 @@ void Video::Clear() void Video::Destroy() { -#if defined HAVE_GL_2X || defined HAVE_GLES_2X Shader::Destroy(stdshader); -#endif } void Video::Capture(uint32_t *buffer) @@ -236,7 +214,7 @@ void Video::Capture(uint32_t *buffer) glGetIntegerv(GL_VIEWPORT, v); int width = v[2], height = v[3]; -#if defined HAVE_GL_1X || defined HAVE_GL_2X +#if defined HAVE_GL_2X glPixelStorei(GL_PACK_ROW_LENGTH, 0); #endif glPixelStorei(GL_PACK_ALIGNMENT, 1);