Changeset 674


Ignore:
Timestamp:
Feb 21, 2011, 1:08:46 AM (9 years ago)
Author:
sam
Message:

The engine now builds for GL and GL ES 1.x and 2.x, and runs for each
one except GL ES 2.x for now.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r673 r674  
    9494 [ac_cv_my_have_gl="yes"
    9595  AC_DEFINE(HAVE_GL_1X, 1, Define to 1 if GL 1.x is available)
     96  AC_DEFINE(HAVE_GL_2X, 1, Define to 1 if GL 2.x is available)
    9697  GL_LIBS="-lGL"]) # FIXME: hackish
    9798if test "${ac_cv_my_have_gl}" = "no"; then
  • trunk/src/debugsphere.cpp

    r673 r674  
    144144
    145145    float a = sinf(data->time);
     146#if 0
    146147    float b = sinf(data->time * 0.5f);
     148#endif
    147149
    148150    int const ndiv = 2;
     
    159161                         vertex_parser, normal_parser);
    160162
     163#if 0 // FIXME: does not work with GLES2
    161164    glEnableClientState(GL_VERTEX_ARRAY);
    162165    glEnableClientState(GL_NORMAL_ARRAY);
     
    188191    glDisableClientState(GL_VERTEX_ARRAY);
    189192    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     193#endif
    190194
    191195    free(vertex);
  • trunk/src/lolgl.h

    r673 r674  
    1717#define __DH_LOLGL_H__
    1818
     19#define GL_GLEXT_PROTOTYPES
     20
     21/* Only define one GL platform */
    1922#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
     29#if defined HAVE_GL_2X
     30#   undef HAVE_GL_1X
     31#   undef HAVE_GLES_1X
     32#   undef HAVE_GLES_2X
     33#endif
     34
     35/* Include GL */
     36#if defined HAVE_GL_1X || defined HAVE_GL_2X
    2037#   if defined __APPLE__ && defined __MACH__
    2138#       include <OpenGL/gl.h>
     
    2643#elif defined HAVE_GLES_1X
    2744#   include <GLES/gl.h>
     45#   include <GLES/glext.h>
    2846#elif defined HAVE_GLES_2X
    29 #   include <GLES2/gl.h>
     47#   include <GLES2/gl2.h>
     48#   include <GLES2/gl2ext.h>
     49#endif
     50
     51/* Redefine some function names */
     52#if defined HAVE_GL_1X
     53#   define glClearDepthf glClearDepth
     54#elif defined HAVE_GL_2X
     55#   define glClearDepthf glClearDepth
     56#elif defined HAVE_GLES_1X
     57#   define glGenVertexArrays glGenVertexArraysOES
     58#   define glDeleteVertexArrays glDeleteVertexArraysOES
     59#elif defined HAVE_GLES_2X
     60#   define glGenVertexArrays glGenVertexArraysOES
     61#   define glDeleteVertexArrays glDeleteVertexArraysOES
     62#   define glBindVertexArray glBindVertexArrayOES
    3063#endif
    3164
  • trunk/src/scene.cpp

    r673 r674  
    3131};
    3232
    33 #if LOL_EXPERIMENTAL
     33#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3434extern Shader *stdshader;
    3535#endif
     
    5757    float angle;
    5858
    59 #if LOL_EXPERIMENTAL
     59#if defined HAVE_GL_2X
    6060    GLuint vao;
    6161#endif
     
    8282    data->nbufs = 0;
    8383
    84 #if LOL_EXPERIMENTAL
     84#if defined HAVE_GL_2X
    8585    glGenVertexArrays(1, &data->vao);
    8686#endif
     
    9292     * Change the architecture to make sure of that. */
    9393    glDeleteBuffers(data->nbufs, data->bufs);
    94 #if LOL_EXPERIMENTAL
     94#if defined HAVE_GL_2X
    9595    glDeleteVertexArrays(1, &data->vao);
    9696#endif
     
    154154    // XXX: end of debug stuff
    155155
    156 #if LOL_EXPERIMENTAL
     156#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    157157    GLuint uni, attr_pos, attr_tex;
    158158    uni = stdshader->GetUniformLocation("model_matrix");
     
    160160    attr_tex = stdshader->GetAttribLocation("in_TexCoord");
    161161
     162    stdshader->Bind();
    162163    glUniformMatrix4fv(uni, 1, GL_FALSE, &model_matrix[0][0]);
     164
    163165    glEnable(GL_DEPTH_TEST);
    164166    glDepthFunc(GL_LEQUAL);
     167#   if !defined HAVE_GLES_2X
    165168    glEnable(GL_ALPHA_TEST);
    166169    glAlphaFunc(GL_GEQUAL, 0.01f);
     170#   endif
    167171    glEnable(GL_BLEND);
    168172    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    205209        }
    206210
    207 #if LOL_EXPERIMENTAL
     211#if defined HAVE_GL_2X
    208212        glBindVertexArray(data->vao);
     213        glEnableVertexAttribArray(attr_pos);
     214        glEnableVertexAttribArray(attr_tex);
     215#elif defined HAVE_GLES_2X
     216        glEnableVertexAttribArray(attr_pos);
     217        glEnableVertexAttribArray(attr_tex);
    209218#else
    210219        glEnableClientState(GL_VERTEX_ARRAY);
     
    212221#endif
    213222
     223#if defined HAVE_GL_2X
    214224        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]);
    215225        glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat),
    216226                     vertex, GL_STATIC_DRAW);
    217 #if LOL_EXPERIMENTAL
    218227        glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0);
    219         glEnableVertexAttribArray(attr_pos);
    220 #else
     228#elif defined HAVE_GLES_2X
     229        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]);
     230        glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, vertex);
     231#elif defined HAVE_GL_1X
     232        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]);
     233        glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat),
     234                     vertex, GL_STATIC_DRAW);
    221235        glVertexPointer(3, GL_FLOAT, 0, NULL);
    222 #endif
    223 
     236#else
     237        glVertexPointer(3, GL_FLOAT, 0, vertex);
     238#endif
     239
     240#if defined HAVE_GL_2X
    224241        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]);
    225242        glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat),
    226243                     texture, GL_STATIC_DRAW);
    227 #if LOL_EXPERIMENTAL
    228244        glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0);
    229         glEnableVertexAttribArray(attr_tex);
    230 #else
     245#elif defined HAVE_GLES_2X
     246        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]);
     247        glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texture);
     248#elif defined HAVE_GL_1X
     249        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]);
     250        glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat),
     251                     texture, GL_STATIC_DRAW);
    231252        glTexCoordPointer(2, GL_FLOAT, 0, NULL);
    232 #endif
    233 
    234 #if LOL_EXPERIMENTAL
     253#else
     254        glTexCoordPointer(2, GL_FLOAT, 0, texture);
     255#endif
     256
     257#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    235258        stdshader->Bind();
    236259#endif
     
    239262        glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6);
    240263
    241 #if LOL_EXPERIMENTAL
     264#if defined HAVE_GL_2X
    242265        glBindVertexArray(0);
     266        glDisableVertexAttribArray(attr_pos);
     267        glDisableVertexAttribArray(attr_tex);
     268#elif defined HAVE_GLES_2X
     269        glDisableVertexAttribArray(attr_pos);
     270        glDisableVertexAttribArray(attr_tex);
    243271#else
    244272        glDisableClientState(GL_VERTEX_ARRAY);
  • trunk/src/shader.cpp

    r673 r674  
    3333
    3434private:
     35#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3536    GLuint prog_id, vert_id, frag_id;
     37#endif
    3638    uint32_t vert_crc, frag_crc;
    3739
     
    7577  : data(new ShaderData())
    7678{
     79#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    7780    char buf[4096];
    7881    GLsizei len;
     82#endif
    7983
    8084    data->vert_crc = Hash::Crc32(vert);
     85#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    8186    data->vert_id = glCreateShader(GL_VERTEX_SHADER);
    8287    glShaderSource(data->vert_id, 1, &vert, NULL);
     
    8691    if (len > 0)
    8792        fprintf(stderr, "ERROR: failed to compile vertex shader: %s", buf);
     93#endif
    8894
    8995    data->frag_crc = Hash::Crc32(frag);
     96#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    9097    data->frag_id = glCreateShader(GL_FRAGMENT_SHADER);
    9198    glShaderSource(data->frag_id, 1, &frag, NULL);
     
    102109    glLinkProgram(data->prog_id);
    103110    glValidateProgram(data->prog_id);
     111#endif
    104112}
    105113
    106114int Shader::GetAttribLocation(char const *attr) const
    107115{
     116#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    108117    return glGetAttribLocation(data->prog_id, attr);
     118#else
     119    (void)attr;
     120    return -1;
     121#endif
    109122}
    110123
    111124int Shader::GetUniformLocation(char const *uni) const
    112125{
     126#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    113127    return glGetUniformLocation(data->prog_id, uni);
     128#else
     129    (void)uni;
     130    return -1;
     131#endif
    114132}
    115133
    116134void Shader::Bind() const
    117135{
     136#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    118137    glUseProgram(data->prog_id);
     138#endif
    119139}
    120140
    121141Shader::~Shader()
    122142{
     143#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    123144    glDetachShader(data->prog_id, data->vert_id);
    124145    glDetachShader(data->prog_id, data->frag_id);
     
    126147    glDeleteShader(data->frag_id);
    127148    glDeleteProgram(data->prog_id);
     149#endif
    128150    delete data;
    129151}
  • trunk/src/video.cpp

    r673 r674  
    2424#include "lolgl.h"
    2525
    26 #if LOL_EXPERIMENTAL
     26#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    2727Shader *stdshader;
    2828#endif
    2929mat4 proj_matrix, view_matrix, model_matrix;
    3030
    31 #if LOL_EXPERIMENTAL
     31#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    3232static char const *vertexshader =
    3333    "#version 130\n"
     
    6161    //"                           + vec4(pass_Color, 1.0));\n"
    6262    "    gl_FragColor = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n"
     63    //"    gl_FragColor = vec4(0.5, 1.0, 0.0, 0.5);\n"
    6364    "}\n";
    6465#endif
     
    7475
    7576    glEnable(GL_TEXTURE_2D);
     77#if defined HAVE_GL_2X || defined HAVE_GLES_1X
    7678    glShadeModel(GL_SMOOTH);
     79#endif
    7780    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    78     glClearDepth(1.0);
    79 
     81    glClearDepthf(1.0);
     82
     83#if defined HAVE_GL_2X || defined HAVE_GLES_1X
    8084    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    81 
    82 #if LOL_EXPERIMENTAL
     85#endif
     86
     87#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    8388    stdshader = Shader::Create(vertexshader, fragmentshader);
    8489#endif
     
    127132    view_matrix = mat4(1.0f);
    128133
    129 #if LOL_EXPERIMENTAL
     134#if defined HAVE_GL_2X || defined HAVE_GLES_2X
     135    stdshader->Bind(); /* Required on GLES 2.x? */
    130136    GLuint uni;
    131137    uni = stdshader->GetUniformLocation("proj_matrix");
     
    163169void Video::Destroy()
    164170{
    165 #if LOL_EXPERIMENTAL
     171#if defined HAVE_GL_2X || defined HAVE_GLES_2X
    166172    Shader::Destroy(stdshader);
    167173#endif
     
    174180    int width = v[2], height = v[3];
    175181
     182#if defined HAVE_GL_1X || defined HAVE_GL_2X
    176183    glPixelStorei(GL_PACK_ROW_LENGTH, 0);
     184#endif
    177185    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    178186
Note: See TracChangeset for help on using the changeset viewer.