of code.legacy
@@ -78,12 +78,6 @@ AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") | |||||
dnl Which version of OpenGL to use? | dnl Which version of OpenGL to use? | ||||
ac_cv_my_have_gl="no" | 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, | PKG_CHECK_MODULES(GLES2, glesv2, | ||||
[ac_cv_my_have_gl="yes" | [ac_cv_my_have_gl="yes" | ||||
AC_DEFINE(HAVE_GLES_2X, 1, Define to 1 if GLES 2.x is available) | 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_CHECK_LIB(GL, glLoadIdentity, | ||||
[ac_cv_my_have_gl="yes" | [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) | AC_DEFINE(HAVE_GL_2X, 1, Define to 1 if GL 2.x is available) | ||||
GL_LIBS="-lGL"]) # FIXME: hackish | GL_LIBS="-lGL"]) # FIXME: hackish | ||||
if test "${ac_cv_my_have_gl}" = "no"; then | if test "${ac_cv_my_have_gl}" = "no"; then | ||||
@@ -32,12 +32,8 @@ class DebugQuadData | |||||
private: | private: | ||||
int initialised; | int initialised; | ||||
float time; | float time; | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
GLuint buflist[3]; | GLuint buflist[3]; | ||||
Shader *shader; | Shader *shader; | ||||
#elif defined HAVE_GL_1X || defined HAVE_GLES_1X | |||||
GLuint buflist[3]; | |||||
#endif | |||||
GLuint texlist[1]; | GLuint texlist[1]; | ||||
uint8_t image[1][32 * 32 * 4]; | uint8_t image[1][32 * 32 * 4]; | ||||
}; | }; | ||||
@@ -70,19 +66,14 @@ void DebugQuad::TickDraw(float deltams) | |||||
{ | { | ||||
if (data->initialised) | if (data->initialised) | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
glDeleteBuffers(3, data->buflist); | glDeleteBuffers(3, data->buflist); | ||||
Shader::Destroy(data->shader); | Shader::Destroy(data->shader); | ||||
#elif defined HAVE_GL_1X || defined HAVE_GLES_1X | |||||
glDeleteBuffers(3, data->buflist); | |||||
#endif | |||||
glDeleteTextures(1, data->texlist); | glDeleteTextures(1, data->texlist); | ||||
data->initialised = 0; | data->initialised = 0; | ||||
} | } | ||||
} | } | ||||
else if (!data->initialised) | else if (!data->initialised) | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
glGenBuffers(3, data->buflist); | glGenBuffers(3, data->buflist); | ||||
static char const *vertexshader = | static char const *vertexshader = | ||||
@@ -108,9 +99,6 @@ void DebugQuad::TickDraw(float deltams) | |||||
" gl_FragColor = col * tex;\n" | " gl_FragColor = col * tex;\n" | ||||
"}\n"; | "}\n"; | ||||
data->shader = Shader::Create(vertexshader, fragmentshader); | data->shader = Shader::Create(vertexshader, fragmentshader); | ||||
#elif defined HAVE_GL_1X || defined HAVE_GLES_1X | |||||
glGenBuffers(3, data->buflist); | |||||
#endif | |||||
glGenTextures(1, data->texlist); | glGenTextures(1, data->texlist); | ||||
glEnable(GL_TEXTURE_2D); | 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 }, | { 0.0f, 0.0f }, { 1.0f, 1.0f }, { 1.0f, 0.0f }, | ||||
}; | }; | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
data->shader->Bind(); | data->shader->Bind(); | ||||
GLuint attr_pos, attr_col, attr_tex; | GLuint attr_pos, attr_col, attr_tex; | ||||
attr_pos = data->shader->GetAttribLocation("in_Position"); | attr_pos = data->shader->GetAttribLocation("in_Position"); | ||||
@@ -197,61 +184,6 @@ void DebugQuad::TickDraw(float deltams) | |||||
glDisableVertexAttribArray(attr_pos); | glDisableVertexAttribArray(attr_pos); | ||||
glDisableVertexAttribArray(attr_col); | glDisableVertexAttribArray(attr_col); | ||||
glDisableVertexAttribArray(attr_tex); | 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() | DebugQuad::~DebugQuad() | ||||
@@ -98,9 +98,7 @@ EglApp::EglApp(char const *title, vec2i res, float fps) : | |||||
{ | { | ||||
EGL_BUFFER_SIZE, 16, | EGL_BUFFER_SIZE, 16, | ||||
EGL_RENDERABLE_TYPE, | 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, | EGL_OPENGL_ES2_BIT, | ||||
#endif | #endif | ||||
EGL_NONE | EGL_NONE | ||||
@@ -130,9 +128,7 @@ EglApp::EglApp(char const *title, vec2i res, float fps) : | |||||
EGLint ctxattr[] = | 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, | EGL_CONTEXT_CLIENT_VERSION, 2, | ||||
#endif | #endif | ||||
EGL_NONE | EGL_NONE | ||||
@@ -19,35 +19,18 @@ | |||||
#define GL_GLEXT_PROTOTYPES | #define GL_GLEXT_PROTOTYPES | ||||
/* Only define one GL platform */ | /* 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 | #if defined HAVE_GL_2X | ||||
# undef HAVE_GL_1X | |||||
# undef HAVE_GLES_1X | |||||
# undef HAVE_GLES_2X | # undef HAVE_GLES_2X | ||||
#endif | #endif | ||||
/* Include GL */ | /* Include GL */ | ||||
#if defined HAVE_GL_1X || defined HAVE_GL_2X | |||||
#if defined HAVE_GL_2X | |||||
# if defined __APPLE__ && defined __MACH__ | # if defined __APPLE__ && defined __MACH__ | ||||
# include <OpenGL/gl.h> | # include <OpenGL/gl.h> | ||||
# else | # else | ||||
# define GL_GLEXT_PROTOTYPES | # define GL_GLEXT_PROTOTYPES | ||||
# include <GL/gl.h> | # include <GL/gl.h> | ||||
# endif | # endif | ||||
#elif defined HAVE_GLES_1X | |||||
# if defined __APPLE__ && defined __MACH__ | |||||
# include <OpenGLES/ES1/gl.h> | |||||
# include <OpenGLES/ES1/glext.h> | |||||
# else | |||||
# include <GLES/gl.h> | |||||
# include <GLES/glext.h> | |||||
# endif | |||||
#elif defined HAVE_GLES_2X | #elif defined HAVE_GLES_2X | ||||
# if defined __APPLE__ && defined __MACH__ | # if defined __APPLE__ && defined __MACH__ | ||||
# include <OpenGLES/ES2/gl.h> | # include <OpenGLES/ES2/gl.h> | ||||
@@ -59,13 +42,8 @@ | |||||
#endif | #endif | ||||
/* Redefine some function names */ | /* 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 | # define glClearDepthf glClearDepth | ||||
#elif defined HAVE_GLES_1X | |||||
# define glGenVertexArrays glGenVertexArraysOES | |||||
# define glDeleteVertexArrays glDeleteVertexArraysOES | |||||
#elif defined HAVE_GLES_2X | #elif defined HAVE_GLES_2X | ||||
# define glGenVertexArrays glGenVertexArraysOES | # define glGenVertexArrays glGenVertexArraysOES | ||||
# define glDeleteVertexArrays glDeleteVertexArraysOES | # define glDeleteVertexArrays glDeleteVertexArraysOES | ||||
@@ -32,9 +32,7 @@ struct Tile | |||||
int x, y, z, o; | int x, y, z, o; | ||||
}; | }; | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
extern Shader *stdshader; | extern Shader *stdshader; | ||||
#endif | |||||
extern mat4 model_matrix; | 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); | model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f); | ||||
// XXX: end of debug stuff | // XXX: end of debug stuff | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
GLuint uni_mat, uni_tex, attr_pos, attr_tex; | GLuint uni_mat, uni_tex, attr_pos, attr_tex; | ||||
attr_pos = stdshader->GetAttribLocation("in_Position"); | attr_pos = stdshader->GetAttribLocation("in_Position"); | ||||
attr_tex = stdshader->GetAttribLocation("in_TexCoord"); | attr_tex = stdshader->GetAttribLocation("in_TexCoord"); | ||||
@@ -169,31 +166,13 @@ void Scene::Render() // XXX: rename to Blit() | |||||
glEnable(GL_TEXTURE_2D); | glEnable(GL_TEXTURE_2D); | ||||
glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | ||||
glDepthFunc(GL_LEQUAL); | 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); | glEnable(GL_ALPHA_TEST); | ||||
glAlphaFunc(GL_GEQUAL, 0.01f); | glAlphaFunc(GL_GEQUAL, 0.01f); | ||||
#endif | |||||
glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 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) | for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2) | ||||
{ | { | ||||
/* Generate new vertex / texture coord buffers if necessary */ | /* 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)); | vertex + 18 * (j - i), texture + 12 * (j - i)); | ||||
} | } | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
stdshader->Bind(); | stdshader->Bind(); | ||||
#endif | |||||
/* Bind texture */ | /* Bind texture */ | ||||
Tiler::Bind(data->tiles[i].code); | Tiler::Bind(data->tiles[i].code); | ||||
/* Bind vertex, color and texture coordinate buffers */ | /* 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); | glBindVertexArray(data->vao); | ||||
# endif | |||||
#endif | |||||
glEnableVertexAttribArray(attr_pos); | glEnableVertexAttribArray(attr_pos); | ||||
glEnableVertexAttribArray(attr_tex); | glEnableVertexAttribArray(attr_tex); | ||||
@@ -244,48 +220,20 @@ void Scene::Render() // XXX: rename to Blit() | |||||
glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), | glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), | ||||
texture, GL_STATIC_DRAW); | texture, GL_STATIC_DRAW); | ||||
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); | 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 */ | /* Draw arrays */ | ||||
glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); | 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); | glBindVertexArray(0); | ||||
# endif | |||||
#endif | |||||
glDisableVertexAttribArray(attr_pos); | glDisableVertexAttribArray(attr_pos); | ||||
glDisableVertexAttribArray(attr_tex); | glDisableVertexAttribArray(attr_tex); | ||||
#endif | |||||
free(vertex); | free(vertex); | ||||
free(texture); | 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); | free(data->tiles); | ||||
data->tiles = 0; | data->tiles = 0; | ||||
data->ntiles = 0; | data->ntiles = 0; | ||||
@@ -34,9 +34,7 @@ class ShaderData | |||||
friend class Shader; | friend class Shader; | ||||
private: | private: | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
GLuint prog_id, vert_id, frag_id; | GLuint prog_id, vert_id, frag_id; | ||||
#endif | |||||
uint32_t vert_crc, frag_crc; | uint32_t vert_crc, frag_crc; | ||||
/* Global shader cache */ | /* Global shader cache */ | ||||
@@ -78,13 +76,10 @@ void Shader::Destroy(Shader *shader) | |||||
Shader::Shader(char const *vert, char const *frag) | Shader::Shader(char const *vert, char const *frag) | ||||
: data(new ShaderData()) | : data(new ShaderData()) | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
char buf[4096]; | char buf[4096]; | ||||
GLsizei len; | GLsizei len; | ||||
#endif | |||||
data->vert_crc = Hash::Crc32(vert); | data->vert_crc = Hash::Crc32(vert); | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
data->vert_id = glCreateShader(GL_VERTEX_SHADER); | data->vert_id = glCreateShader(GL_VERTEX_SHADER); | ||||
glShaderSource(data->vert_id, 1, &vert, NULL); | glShaderSource(data->vert_id, 1, &vert, NULL); | ||||
glCompileShader(data->vert_id); | glCompileShader(data->vert_id); | ||||
@@ -92,10 +87,8 @@ Shader::Shader(char const *vert, char const *frag) | |||||
glGetShaderInfoLog(data->vert_id, sizeof(buf), &len, buf); | glGetShaderInfoLog(data->vert_id, sizeof(buf), &len, buf); | ||||
if (len > 0) | if (len > 0) | ||||
Log::Error("failed to compile vertex shader: %s", buf); | Log::Error("failed to compile vertex shader: %s", buf); | ||||
#endif | |||||
data->frag_crc = Hash::Crc32(frag); | data->frag_crc = Hash::Crc32(frag); | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | ||||
glShaderSource(data->frag_id, 1, &frag, NULL); | glShaderSource(data->frag_id, 1, &frag, NULL); | ||||
glCompileShader(data->frag_id); | glCompileShader(data->frag_id); | ||||
@@ -110,45 +103,30 @@ Shader::Shader(char const *vert, char const *frag) | |||||
glLinkProgram(data->prog_id); | glLinkProgram(data->prog_id); | ||||
glValidateProgram(data->prog_id); | glValidateProgram(data->prog_id); | ||||
#endif | |||||
} | } | ||||
int Shader::GetAttribLocation(char const *attr) const | int Shader::GetAttribLocation(char const *attr) const | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
return glGetAttribLocation(data->prog_id, attr); | return glGetAttribLocation(data->prog_id, attr); | ||||
#else | |||||
(void)attr; | |||||
return -1; | |||||
#endif | |||||
} | } | ||||
int Shader::GetUniformLocation(char const *uni) const | int Shader::GetUniformLocation(char const *uni) const | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
return glGetUniformLocation(data->prog_id, uni); | return glGetUniformLocation(data->prog_id, uni); | ||||
#else | |||||
(void)uni; | |||||
return -1; | |||||
#endif | |||||
} | } | ||||
void Shader::Bind() const | void Shader::Bind() const | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
glUseProgram(data->prog_id); | glUseProgram(data->prog_id); | ||||
#endif | |||||
} | } | ||||
Shader::~Shader() | Shader::~Shader() | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
glDetachShader(data->prog_id, data->vert_id); | glDetachShader(data->prog_id, data->vert_id); | ||||
glDetachShader(data->prog_id, data->frag_id); | glDetachShader(data->prog_id, data->frag_id); | ||||
glDeleteShader(data->vert_id); | glDeleteShader(data->vert_id); | ||||
glDeleteShader(data->frag_id); | glDeleteShader(data->frag_id); | ||||
glDeleteProgram(data->prog_id); | glDeleteProgram(data->prog_id); | ||||
#endif | |||||
delete data; | delete data; | ||||
} | } | ||||
@@ -29,14 +29,11 @@ namespace lol | |||||
vec2i saved_viewport; | vec2i saved_viewport; | ||||
#endif | #endif | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
Shader *stdshader; | Shader *stdshader; | ||||
#endif | |||||
mat4 proj_matrix, view_matrix, model_matrix; | mat4 proj_matrix, view_matrix, model_matrix; | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
static char const *vertexshader = | static char const *vertexshader = | ||||
#if !defined HAVE_GLES_2X | |||||
#if defined HAVE_GL_2X | |||||
"#version 130\n" | "#version 130\n" | ||||
#endif | #endif | ||||
"\n" | "\n" | ||||
@@ -87,11 +84,10 @@ static char const *fragmentshader = | |||||
#else | #else | ||||
" vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n" | " vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n" | ||||
#endif | #endif | ||||
#if 1 | |||||
#if 0 | |||||
" float mul = 2.0;\n" | " 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 dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);\n" | ||||
" float dy2 = mod(floor(gl_FragCoord.y * 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" | " float t2 = mod(3.0 * dx2 + 2.0 * dy2, 4.0);\n" | ||||
@@ -111,7 +107,6 @@ static char const *fragmentshader = | |||||
#endif | #endif | ||||
" gl_FragColor = col;\n" | " gl_FragColor = col;\n" | ||||
"}\n"; | "}\n"; | ||||
#endif | |||||
/* | /* | ||||
* Public Video class | * Public Video class | ||||
@@ -129,16 +124,12 @@ void Video::Setup(int width, int height) | |||||
glClearColor(0.1f, 0.2f, 0.3f, 0.0f); | glClearColor(0.1f, 0.2f, 0.3f, 0.0f); | ||||
glClearDepthf(1.0); | glClearDepthf(1.0); | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_1X | |||||
#if defined HAVE_GL_2X | |||||
glShadeModel(GL_SMOOTH); | glShadeModel(GL_SMOOTH); | ||||
#endif | |||||
#if defined HAVE_GL_2X || defined HAVE_GLES_1X | |||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | ||||
#endif | #endif | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
stdshader = Shader::Create(vertexshader, fragmentshader); | stdshader = Shader::Create(vertexshader, fragmentshader); | ||||
#endif | |||||
} | } | ||||
void Video::SetFov(float theta) | void Video::SetFov(float theta) | ||||
@@ -188,23 +179,12 @@ void Video::SetFov(float theta) | |||||
view_matrix = mat4(1.0f); | view_matrix = mat4(1.0f); | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
stdshader->Bind(); /* Required on GLES 2.x? */ | stdshader->Bind(); /* Required on GLES 2.x? */ | ||||
GLuint uni; | GLuint uni; | ||||
uni = stdshader->GetUniformLocation("proj_matrix"); | uni = stdshader->GetUniformLocation("proj_matrix"); | ||||
glUniformMatrix4fv(uni, 1, GL_FALSE, &proj_matrix[0][0]); | glUniformMatrix4fv(uni, 1, GL_FALSE, &proj_matrix[0][0]); | ||||
uni = stdshader->GetUniformLocation("view_matrix"); | uni = stdshader->GetUniformLocation("view_matrix"); | ||||
glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]); | 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) | void Video::SetDepth(bool set) | ||||
@@ -225,9 +205,7 @@ void Video::Clear() | |||||
void Video::Destroy() | void Video::Destroy() | ||||
{ | { | ||||
#if defined HAVE_GL_2X || defined HAVE_GLES_2X | |||||
Shader::Destroy(stdshader); | Shader::Destroy(stdshader); | ||||
#endif | |||||
} | } | ||||
void Video::Capture(uint32_t *buffer) | void Video::Capture(uint32_t *buffer) | ||||
@@ -236,7 +214,7 @@ void Video::Capture(uint32_t *buffer) | |||||
glGetIntegerv(GL_VIEWPORT, v); | glGetIntegerv(GL_VIEWPORT, v); | ||||
int width = v[2], height = v[3]; | 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); | glPixelStorei(GL_PACK_ROW_LENGTH, 0); | ||||
#endif | #endif | ||||
glPixelStorei(GL_PACK_ALIGNMENT, 1); | glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||||