Changeset 745


Ignore:
Timestamp:
Mar 19, 2011, 12:52:14 PM (9 years ago)
Author:
sam
Message:

video: enforce shader-enabled GL implementations, getting rid of a lot
of code.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r711 r745  
    7979dnl Which version of OpenGL to use?
    8080ac_cv_my_have_gl="no"
    81 PKG_CHECK_MODULES(GLES1, glesv1_cm,
    82  [ac_cv_my_have_gl="yes"
    83   AC_DEFINE(HAVE_GLES_1X, 1, Define to 1 if GLES 1.x is available)
    84   GL_CFLAGS="${GLES1_CFLAGS}"
    85   GL_LIBS="${GLES1_LIBS}"],
    86  [:])
    8781PKG_CHECK_MODULES(GLES2, glesv2,
    8882 [ac_cv_my_have_gl="yes"
     
    9387AC_CHECK_LIB(GL, glLoadIdentity,
    9488 [ac_cv_my_have_gl="yes"
    95   AC_DEFINE(HAVE_GL_1X, 1, Define to 1 if GL 1.x is available)
    9689  AC_DEFINE(HAVE_GL_2X, 1, Define to 1 if GL 2.x is available)
    9790  GL_LIBS="-lGL"]) # FIXME: hackish
  • trunk/monsterz/monsterz.cpp

    r696 r745  
    2323using namespace lol;
    2424
    25 #if defined HAVE_GLES_1X || defined HAVE_GLES_2X
     25#if defined HAVE_GLES_2X
    2626#   include "eglapp.h"
    2727#else
     
    3737int main(int argc, char **argv)
    3838{
    39 #if defined HAVE_GLES_1X || defined HAVE_GLES_2X
     39#if defined HAVE_GLES_2X
    4040    EglApp app("Monsterz", vec2i(640, 480), 60.0f);
    4141#else
     
    4848
    4949    /* Register an input driver and some debug stuff */
    50 #if !defined HAVE_GLES_1X && !defined HAVE_GLES_2X
     50#if !defined HAVE_GLES_2X
    5151    new SdlInput();
    5252#endif
  • trunk/src/debugquad.cpp

    r735 r745  
    3333    int initialised;
    3434    float time;
    35 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3635    GLuint buflist[3];
    3736    Shader *shader;
    38 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X
    39     GLuint buflist[3];
    40 #endif
    4137    GLuint texlist[1];
    4238    uint8_t image[1][32 * 32 * 4];
     
    7167        if (data->initialised)
    7268        {
    73 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    7469            glDeleteBuffers(3, data->buflist);
    7570            Shader::Destroy(data->shader);
    76 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X
    77             glDeleteBuffers(3, data->buflist);
    78 #endif
    7971            glDeleteTextures(1, data->texlist);
    8072            data->initialised = 0;
     
    8375    else if (!data->initialised)
    8476    {
    85 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    8677        glGenBuffers(3, data->buflist);
    8778
     
    109100            "}\n";
    110101        data->shader = Shader::Create(vertexshader, fragmentshader);
    111 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X
    112         glGenBuffers(3, data->buflist);
    113 #endif
    114102        glGenTextures(1, data->texlist);
    115103
     
    166154    };
    167155
    168 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    169156    data->shader->Bind();
    170157    GLuint attr_pos, attr_col, attr_tex;
     
    198185    glDisableVertexAttribArray(attr_col);
    199186    glDisableVertexAttribArray(attr_tex);
    200 #elif defined HAVE_GL_1X || defined HAVE_GLES_1X
    201     /* Reset all model-view-projection matrices */
    202     glMatrixMode(GL_PROJECTION);
    203     glPushMatrix();
    204     glLoadIdentity();
    205     glMatrixMode(GL_MODELVIEW);
    206     glPushMatrix();
    207     glLoadIdentity();
    208 
    209     /* Set up state machine */
    210     glDisable(GL_DEPTH_TEST);
    211     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    212     glEnable(GL_TEXTURE_2D);
    213     glEnableClientState(GL_VERTEX_ARRAY);
    214     glEnableClientState(GL_COLOR_ARRAY);
    215     glEnable(GL_BLEND);
    216     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    217 
    218     /* Bind texture */
    219     glClientActiveTexture(GL_TEXTURE0);
    220     glBindTexture(GL_TEXTURE_2D, data->texlist[0]);
    221 
    222     /* Bind vertex, color and texture coordinate buffers */
    223 #if defined HAVE_GL_1X
    224     glBindBuffer(GL_ARRAY_BUFFER, data->buflist[0]);
    225     glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), verts, GL_STATIC_DRAW);
    226     glVertexPointer(2, GL_FLOAT, 0, NULL);
    227 
    228     glBindBuffer(GL_ARRAY_BUFFER, data->buflist[1]);
    229     glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), cols, GL_STATIC_DRAW);
    230     glColorPointer(4, GL_FLOAT, 0, NULL);
    231 
    232     glBindBuffer(GL_ARRAY_BUFFER, data->buflist[2]);
    233     glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), tcs, GL_STATIC_DRAW);
    234     glTexCoordPointer(2, GL_FLOAT, 0, NULL);
    235 #else
    236     glVertexPointer(2, GL_FLOAT, 0, verts);
    237     glColorPointer(4, GL_FLOAT, 0, cols);
    238     glTexCoordPointer(2, GL_FLOAT, 0, tcs);
    239 #endif
    240 
    241     /* Draw arrays */
    242     glDrawArrays(GL_TRIANGLES, 0, 6);
    243 
    244     /* Disable state machine features */
    245     glDisableClientState(GL_VERTEX_ARRAY);
    246     glDisableClientState(GL_COLOR_ARRAY);
    247     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    248 
    249     /* Restore matrices */
    250     glMatrixMode(GL_PROJECTION);
    251     glPopMatrix();
    252     glMatrixMode(GL_MODELVIEW);
    253     glPopMatrix();
    254 #endif
    255187}
    256188
  • trunk/src/eglapp.cpp

    r735 r745  
    9999        EGL_BUFFER_SIZE, 16,
    100100        EGL_RENDERABLE_TYPE,
    101 #if defined HAVE_GLES_1X
    102         EGL_OPENGL_ES_BIT,
    103 #elif defined HAVE_GLES_2X
     101#if defined HAVE_GLES_2X
    104102        EGL_OPENGL_ES2_BIT,
    105103#endif
     
    131129    EGLint ctxattr[] =
    132130    {
    133 #if defined HAVE_GLES_1X
    134         EGL_CONTEXT_CLIENT_VERSION, 1,
    135 #elif defined HAVE_GLES_2X
     131#if defined HAVE_GLES_2X
    136132        EGL_CONTEXT_CLIENT_VERSION, 2,
    137133#endif
  • trunk/src/lolgl.h

    r723 r745  
    2020
    2121/* Only define one GL platform */
    22 #if defined HAVE_GL_1X
    23 #   undef HAVE_GLES_1X
    24 #endif
    25 #if defined HAVE_GLES_2X
    26 #   undef HAVE_GL_1X
    27 #   undef HAVE_GLES_1X
    28 #endif
    2922#if defined HAVE_GL_2X
    30 #   undef HAVE_GL_1X
    31 #   undef HAVE_GLES_1X
    3223#   undef HAVE_GLES_2X
    3324#endif
    3425
    3526/* Include GL */
    36 #if defined HAVE_GL_1X || defined HAVE_GL_2X
     27#if defined HAVE_GL_2X
    3728#   if defined __APPLE__ && defined __MACH__
    3829#       include <OpenGL/gl.h>
     
    4031#       define GL_GLEXT_PROTOTYPES
    4132#       include <GL/gl.h>
    42 #   endif
    43 #elif defined HAVE_GLES_1X
    44 #   if defined __APPLE__ && defined __MACH__
    45 #       include <OpenGLES/ES1/gl.h>
    46 #       include <OpenGLES/ES1/glext.h>
    47 #   else
    48 #       include <GLES/gl.h>
    49 #       include <GLES/glext.h>
    5033#   endif
    5134#elif defined HAVE_GLES_2X
     
    6043
    6144/* Redefine some function names */
    62 #if defined HAVE_GL_1X
     45#if defined HAVE_GL_2X
    6346#   define glClearDepthf glClearDepth
    64 #elif defined HAVE_GL_2X
    65 #   define glClearDepthf glClearDepth
    66 #elif defined HAVE_GLES_1X
    67 #   define glGenVertexArrays glGenVertexArraysOES
    68 #   define glDeleteVertexArrays glDeleteVertexArraysOES
    6947#elif defined HAVE_GLES_2X
    7048#   define glGenVertexArrays glGenVertexArraysOES
  • trunk/src/scene.cpp

    r735 r745  
    3333};
    3434
    35 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3635extern Shader *stdshader;
    37 #endif
    3836extern mat4 model_matrix;
    3937
     
    156154    // XXX: end of debug stuff
    157155
    158 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    159156    GLuint uni_mat, uni_tex, attr_pos, attr_tex;
    160157    attr_pos = stdshader->GetAttribLocation("in_Position");
     
    170167    glEnable(GL_DEPTH_TEST);
    171168    glDepthFunc(GL_LEQUAL);
    172 #   if !defined HAVE_GLES_2X
     169#if defined HAVE_GL_2X
    173170    glEnable(GL_ALPHA_TEST);
    174171    glAlphaFunc(GL_GEQUAL, 0.01f);
    175 #   endif
     172#endif
    176173    glEnable(GL_BLEND);
    177174    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    178 #else
    179     glEnable(GL_DEPTH_TEST);
    180     glDepthFunc(GL_LEQUAL);
    181     glEnable(GL_ALPHA_TEST);
    182     glAlphaFunc(GL_GEQUAL, 0.01f);
    183     glEnable(GL_BLEND);
    184     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    185 
    186     glMatrixMode(GL_MODELVIEW);
    187     glPushMatrix();
    188     glLoadIdentity();
    189     glMultMatrixf(&model_matrix[0][0]);
    190 
    191     /* Set up state machine */
    192     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    193     glEnable(GL_TEXTURE_2D);
    194     glEnableClientState(GL_VERTEX_ARRAY);
    195 #endif
    196175
    197176    for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2)
     
    221200        }
    222201
    223 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    224202        stdshader->Bind();
    225 #endif
    226203
    227204        /* Bind texture */
     
    229206
    230207        /* Bind vertex, color and texture coordinate buffers */
    231 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    232 #   if !defined HAVE_GLES_2X
     208#if defined HAVE_GL_2X
    233209        glBindVertexArray(data->vao);
    234 #   endif
     210#endif
    235211        glEnableVertexAttribArray(attr_pos);
    236212        glEnableVertexAttribArray(attr_tex);
     
    245221                     texture, GL_STATIC_DRAW);
    246222        glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0);
    247 #elif defined HAVE_GL_1X
    248         glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]);
    249         glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat),
    250                      vertex, GL_STATIC_DRAW);
    251         glVertexPointer(3, GL_FLOAT, 0, NULL);
    252 
    253         glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]);
    254         glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat),
    255                      texture, GL_STATIC_DRAW);
    256         glTexCoordPointer(2, GL_FLOAT, 0, NULL);
    257 #else
    258         glVertexPointer(3, GL_FLOAT, 0, vertex);
    259         glTexCoordPointer(2, GL_FLOAT, 0, texture);
    260 #endif
    261223
    262224        /* Draw arrays */
    263225        glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6);
    264226
    265 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    266 #   if !defined HAVE_GLES_2X
     227#if defined HAVE_GL_2X
    267228        glBindVertexArray(0);
    268 #   endif
     229#endif
    269230        glDisableVertexAttribArray(attr_pos);
    270231        glDisableVertexAttribArray(attr_tex);
    271 #endif
    272232
    273233        free(vertex);
     
    275235    }
    276236
    277 #if defined HAVE_GL_1X || defined HAVE_GLES_1X
    278     /* Disable state machine features */
    279     glDisableClientState(GL_VERTEX_ARRAY);
    280     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    281 
    282     /* Restore matrices */
    283     glMatrixMode(GL_PROJECTION);
    284     glPopMatrix();
    285     glMatrixMode(GL_MODELVIEW);
    286     glPopMatrix();
    287 #endif
    288 
    289237    free(data->tiles);
    290238    data->tiles = 0;
  • trunk/src/shader.cpp

    r735 r745  
    3535
    3636private:
    37 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3837    GLuint prog_id, vert_id, frag_id;
    39 #endif
    4038    uint32_t vert_crc, frag_crc;
    4139
     
    7977  : data(new ShaderData())
    8078{
    81 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    8279    char buf[4096];
    8380    GLsizei len;
    84 #endif
    8581
    8682    data->vert_crc = Hash::Crc32(vert);
    87 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    8883    data->vert_id = glCreateShader(GL_VERTEX_SHADER);
    8984    glShaderSource(data->vert_id, 1, &vert, NULL);
     
    9388    if (len > 0)
    9489        Log::Error("failed to compile vertex shader: %s", buf);
    95 #endif
    9690
    9791    data->frag_crc = Hash::Crc32(frag);
    98 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    9992    data->frag_id = glCreateShader(GL_FRAGMENT_SHADER);
    10093    glShaderSource(data->frag_id, 1, &frag, NULL);
     
    111104    glLinkProgram(data->prog_id);
    112105    glValidateProgram(data->prog_id);
    113 #endif
    114106}
    115107
    116108int Shader::GetAttribLocation(char const *attr) const
    117109{
    118 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    119110    return glGetAttribLocation(data->prog_id, attr);
    120 #else
    121     (void)attr;
    122     return -1;
    123 #endif
    124111}
    125112
    126113int Shader::GetUniformLocation(char const *uni) const
    127114{
    128 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    129115    return glGetUniformLocation(data->prog_id, uni);
    130 #else
    131     (void)uni;
    132     return -1;
    133 #endif
    134116}
    135117
    136118void Shader::Bind() const
    137119{
    138 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    139120    glUseProgram(data->prog_id);
    140 #endif
    141121}
    142122
    143123Shader::~Shader()
    144124{
    145 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    146125    glDetachShader(data->prog_id, data->vert_id);
    147126    glDetachShader(data->prog_id, data->frag_id);
     
    149128    glDeleteShader(data->frag_id);
    150129    glDeleteProgram(data->prog_id);
    151 #endif
    152130    delete data;
    153131}
  • trunk/src/video.cpp

    r742 r745  
    3030#endif
    3131
    32 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3332Shader *stdshader;
    34 #endif
    3533mat4 proj_matrix, view_matrix, model_matrix;
    3634
    37 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3835static char const *vertexshader =
    39 #if !defined HAVE_GLES_2X
     36#if defined HAVE_GL_2X
    4037    "#version 130\n"
    4138#endif
     
    8885    "    vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n"
    8986#endif
    90 #if 1
     87#if 0
    9188    "    float mul = 2.0;\n"
    92     "    float dx1 = mod(gl_FragCoord.x, 2.0);\n"
    93     "    float dy1 = mod(gl_FragCoord.y, 2.0);\n"
    94     "    float t1 = mod(3.0 * dx1 + 2.0 * dy1, 4.0);\n"
     89    "    vec2 d1 = mod(vec2(gl_FragCoord), vec2(2.0, 2.0));\n"
     90    "    float t1 = mod(3.0 * d1.x + 2.0 * d1.y, 4.0);\n"
    9591    "    float dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);\n"
    9692    "    float dy2 = mod(floor(gl_FragCoord.y * 0.5), 2.0);\n"
     
    112108    "    gl_FragColor = col;\n"
    113109    "}\n";
    114 #endif
    115110
    116111/*
     
    130125    glClearDepthf(1.0);
    131126
    132 #if defined HAVE_GL_2X || defined HAVE_GLES_1X
     127#if defined HAVE_GL_2X
    133128    glShadeModel(GL_SMOOTH);
    134 #endif
    135 #if defined HAVE_GL_2X || defined HAVE_GLES_1X
    136129    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    137130#endif
    138131
    139 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    140132    stdshader = Shader::Create(vertexshader, fragmentshader);
    141 #endif
    142133}
    143134
     
    189180    view_matrix = mat4(1.0f);
    190181
    191 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    192182    stdshader->Bind(); /* Required on GLES 2.x? */
    193183    GLuint uni;
     
    196186    uni = stdshader->GetUniformLocation("view_matrix");
    197187    glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]);
    198 #else
    199     glMatrixMode(GL_PROJECTION);
    200     glLoadIdentity();
    201     glMultMatrixf(&proj_matrix[0][0]);
    202 
    203     /* Reset the model view matrix, just in case */
    204     glMatrixMode(GL_MODELVIEW);
    205     glLoadIdentity();
    206     glMultMatrixf(&view_matrix[0][0]);
    207 #endif
    208188}
    209189
     
    226206void Video::Destroy()
    227207{
    228 #if defined HAVE_GL_2X || defined HAVE_GLES_2X
    229208    Shader::Destroy(stdshader);
    230 #endif
    231209}
    232210
     
    237215    int width = v[2], height = v[3];
    238216
    239 #if defined HAVE_GL_1X || defined HAVE_GL_2X
     217#if defined HAVE_GL_2X
    240218    glPixelStorei(GL_PACK_ROW_LENGTH, 0);
    241219#endif
Note: See TracChangeset for help on using the changeset viewer.