mojoshader_opengl.c
branchtrunk
changeset 229 67a3d459d865
parent 226 4a2b3d0b535f
child 230 396aa372c7d8
equal deleted inserted replaced
228:fa70fd53eb59 229:67a3d459d865
    64 static float ps_register_file_f[8192 * 4];
    64 static float ps_register_file_f[8192 * 4];
    65 static int ps_register_file_i[2047 * 4];
    65 static int ps_register_file_i[2047 * 4];
    66 static uint8 ps_register_file_b[2047];
    66 static uint8 ps_register_file_b[2047];
    67 
    67 
    68 // GL stuff...
    68 // GL stuff...
       
    69 static int opengl_major = 0;
       
    70 static int opengl_minor = 0;
    69 static MOJOSHADER_glProgram *bound_program = NULL;
    71 static MOJOSHADER_glProgram *bound_program = NULL;
    70 static const char *profile = NULL;
    72 static const char *profile = NULL;
       
    73 
       
    74 // Entry points...
       
    75 typedef WINGDIAPI const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
       
    76 typedef WINGDIAPI void (APIENTRYP PFNGLDISABLECLIENTSTATEPROC) (GLenum array);
       
    77 typedef WINGDIAPI void (APIENTRYP PFNGLENABLECLIENTSTATEPROC) (GLenum array);
       
    78 typedef WINGDIAPI void (APIENTRYP PFNGLVERTEXPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
       
    79 
       
    80 static int have_base_opengl = 0;
       
    81 static int have_GL_ARB_shader_objects = 0;
       
    82 static int have_GL_ARB_vertex_shader = 0;
       
    83 static int have_GL_ARB_fragment_shader = 0;
       
    84 static int have_GL_ARB_shading_language_100 = 0;
       
    85 static PFNGLGETSTRINGPROC pglGetString = NULL;
       
    86 static PFNGLDELETEOBJECTARBPROC pglDeleteObject = NULL;
       
    87 static PFNGLATTACHOBJECTARBPROC pglAttachObject = NULL;
       
    88 static PFNGLCOMPILESHADERARBPROC pglCompileShader = NULL;
       
    89 static PFNGLCREATEPROGRAMOBJECTARBPROC pglCreateProgramObject = NULL;
       
    90 static PFNGLCREATESHADEROBJECTARBPROC pglCreateShaderObject = NULL;
       
    91 static PFNGLDISABLECLIENTSTATEPROC pglDisableClientState = NULL;
       
    92 static PFNGLDISABLEVERTEXATTRIBARRAYARBPROC pglDisableVertexAttribArray = NULL;
       
    93 static PFNGLENABLECLIENTSTATEPROC pglEnableClientState = NULL;
       
    94 static PFNGLENABLEVERTEXATTRIBARRAYARBPROC pglEnableVertexAttribArray = NULL;
       
    95 static PFNGLGETATTRIBLOCATIONARBPROC pglGetAttribLocation = NULL;
       
    96 static PFNGLGETINFOLOGARBPROC pglGetInfoLog = NULL;
       
    97 static PFNGLGETOBJECTPARAMETERIVARBPROC pglGetObjectParameteriv = NULL;
       
    98 static PFNGLGETUNIFORMLOCATIONARBPROC pglGetUniformLocation = NULL;
       
    99 static PFNGLLINKPROGRAMARBPROC pglLinkProgram = NULL;
       
   100 static PFNGLSHADERSOURCEARBPROC pglShaderSource = NULL;
       
   101 static PFNGLUNIFORM1IARBPROC pglUniform1i = NULL;
       
   102 static PFNGLUNIFORM4FVARBPROC pglUniform4fv = NULL;
       
   103 static PFNGLUNIFORM4IVARBPROC pglUniform4iv = NULL;
       
   104 static PFNGLUSEPROGRAMOBJECTARBPROC pglUseProgramObject = NULL;
       
   105 static PFNGLVERTEXATTRIBPOINTERARBPROC pglVertexAttribPointer = NULL;
       
   106 static PFNGLVERTEXPOINTERPROC pglVertexPointer = NULL;
    71 
   107 
    72 
   108 
    73 // Error state...
   109 // Error state...
    74 static char error_buffer[1024] = { '\0' };
   110 static char error_buffer[1024] = { '\0' };
    75 
   111 
   108 {
   144 {
   109     return error_buffer;
   145     return error_buffer;
   110 } // MOJOSHADER_glGetError
   146 } // MOJOSHADER_glGetError
   111 
   147 
   112 
   148 
       
   149 static void *loadsym(void *(*lookup)(const char *fn), const char *fn, int *ext)
       
   150 {
       
   151     void *retval = NULL;
       
   152     if (lookup != NULL)
       
   153     {
       
   154         retval = lookup(fn);
       
   155         if (retval == NULL)
       
   156         {
       
   157             char arbfn[64];
       
   158             snprintf(arbfn, sizeof (arbfn), "%sARB", fn);
       
   159             retval = lookup(arbfn);
       
   160         } // if
       
   161     } // if
       
   162 
       
   163     if (retval == NULL)
       
   164         *ext = 0;
       
   165 
       
   166     return retval;
       
   167 } // loadsym
       
   168 
       
   169 static void lookup_entry_points(void *(*lookup)(const char *fnname))
       
   170 {
       
   171     #define DO_LOOKUP(ext, typ, fn) p##fn = (typ) loadsym(lookup, #fn, &have_##ext)
       
   172     DO_LOOKUP(base_opengl, PFNGLGETSTRINGPROC, glGetString);
       
   173     DO_LOOKUP(base_opengl, PFNGLDISABLECLIENTSTATEPROC, glDisableClientState);
       
   174     DO_LOOKUP(base_opengl, PFNGLENABLECLIENTSTATEPROC, glEnableClientState);
       
   175     DO_LOOKUP(base_opengl, PFNGLVERTEXPOINTERPROC, glVertexPointer);
       
   176     DO_LOOKUP(GL_ARB_shader_objects, PFNGLDELETEOBJECTARBPROC, glDeleteObject);
       
   177     DO_LOOKUP(GL_ARB_shader_objects, PFNGLATTACHOBJECTARBPROC, glAttachObject);
       
   178     DO_LOOKUP(GL_ARB_shader_objects, PFNGLCOMPILESHADERARBPROC, glCompileShader);
       
   179     DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATEPROGRAMOBJECTARBPROC, glCreateProgramObject);
       
   180     DO_LOOKUP(GL_ARB_shader_objects, PFNGLCREATESHADEROBJECTARBPROC, glCreateShaderObject);
       
   181     DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETINFOLOGARBPROC, glGetInfoLog);
       
   182     DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETOBJECTPARAMETERIVARBPROC, glGetObjectParameteriv);
       
   183     DO_LOOKUP(GL_ARB_shader_objects, PFNGLGETUNIFORMLOCATIONARBPROC, glGetUniformLocation);
       
   184     DO_LOOKUP(GL_ARB_shader_objects, PFNGLLINKPROGRAMARBPROC, glLinkProgram);
       
   185     DO_LOOKUP(GL_ARB_shader_objects, PFNGLSHADERSOURCEARBPROC, glShaderSource);
       
   186     DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM1IARBPROC, glUniform1i);
       
   187     DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4FVARBPROC, glUniform4fv);
       
   188     DO_LOOKUP(GL_ARB_shader_objects, PFNGLUNIFORM4IVARBPROC, glUniform4iv);
       
   189     DO_LOOKUP(GL_ARB_shader_objects, PFNGLUSEPROGRAMOBJECTARBPROC, glUseProgramObject);
       
   190     DO_LOOKUP(GL_ARB_vertex_shader, PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArray);
       
   191     DO_LOOKUP(GL_ARB_vertex_shader, PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArray);
       
   192     DO_LOOKUP(GL_ARB_vertex_shader, PFNGLGETATTRIBLOCATIONARBPROC, glGetAttribLocation);
       
   193     DO_LOOKUP(GL_ARB_vertex_shader, PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointer);
       
   194     #undef DO_LOOKUP
       
   195 } // lookup_entry_points
       
   196 
       
   197 
       
   198 static int verify_extension(const char *ext, int have, const char *extlist,
       
   199                             int major, int minor)
       
   200 {
       
   201     if (have == 0)
       
   202         return 0;  // don't bother checking, we're missing an entry point.
       
   203 
       
   204     // See if it's in the spec for this GL implementation's version.
       
   205     if ( ((opengl_major << 16) | (opengl_minor & 0xFFFF)) >=
       
   206          ((major << 16) | (minor & 0xFFFF)) )
       
   207         return 1;
       
   208 
       
   209     // Not available in the GL version, check the extension list.
       
   210     const char *ptr = strstr(extlist, ext);
       
   211     if (ptr == NULL)
       
   212         return 0;
       
   213 
       
   214     const char endchar = ptr[strlen(ext)];
       
   215     if ((endchar == '\0') || (endchar == ' '))
       
   216         return 1;  // extension is in the list.
       
   217 
       
   218     return 0;  // just not supported, fail.
       
   219 } // verify_extension
       
   220 
       
   221 
       
   222 static void parse_opengl_version(const char *verstr)
       
   223 {
       
   224     if (verstr == NULL)
       
   225         opengl_major = opengl_minor = 0;
       
   226     else
       
   227         sscanf(verstr, "%d.%d", &opengl_major, &opengl_minor);
       
   228 } // parse_opengl_version
       
   229 
       
   230 
       
   231 static int check_extensions(void *(*lookup)(const char *fnname))
       
   232 {
       
   233     have_base_opengl = 1;
       
   234     have_GL_ARB_shader_objects = 1;
       
   235     have_GL_ARB_vertex_shader = 1;
       
   236     have_GL_ARB_fragment_shader = 1;
       
   237     have_GL_ARB_shading_language_100 = 1;
       
   238 
       
   239     lookup_entry_points(lookup);
       
   240 
       
   241     if (!have_base_opengl)   // a function we should definitely have is MIA?
       
   242     {
       
   243         set_error("missing basic OpenGL entry points");
       
   244         return 0;
       
   245     } // if
       
   246 
       
   247     parse_opengl_version((const char *) pglGetString(GL_VERSION));
       
   248 
       
   249     const char *extlist = (const char *) pglGetString(GL_EXTENSIONS);
       
   250     if (extlist == NULL)
       
   251         extlist = "";  // just in case.
       
   252 
       
   253     #define VERIFY_EXT(ext, major, minor) \
       
   254         have_##ext = verify_extension(#ext, have_##ext, extlist, major, minor)
       
   255 
       
   256     VERIFY_EXT(GL_ARB_shader_objects, 2, 0);
       
   257     VERIFY_EXT(GL_ARB_vertex_shader, 2, 0);
       
   258     VERIFY_EXT(GL_ARB_fragment_shader, 2, 0);
       
   259     VERIFY_EXT(GL_ARB_shading_language_100, 2, 0);
       
   260 
       
   261     #undef VERIFY_EXT
       
   262 
       
   263     #define REQUIRE_GL_EXTENSION(x) \
       
   264         if (!have_##x) { set_error("This profile requires " #x); return 0; }
       
   265 
       
   266     if (strcmp(profile, MOJOSHADER_PROFILE_GLSL) == 0)
       
   267     {
       
   268         REQUIRE_GL_EXTENSION(GL_ARB_shader_objects);
       
   269         REQUIRE_GL_EXTENSION(GL_ARB_vertex_shader);
       
   270         REQUIRE_GL_EXTENSION(GL_ARB_fragment_shader);
       
   271         REQUIRE_GL_EXTENSION(GL_ARB_shading_language_100);
       
   272     } // if
       
   273 
       
   274     else
       
   275     {
       
   276         set_error("unknown profile");
       
   277         return 0;
       
   278     } // else
       
   279 
       
   280     #undef REQUIRE_GL_EXTENSION
       
   281 
       
   282     return 1;
       
   283 } // check_extensions
       
   284 
       
   285 
   113 int MOJOSHADER_glInit(const char *_profile,
   286 int MOJOSHADER_glInit(const char *_profile,
   114                       void *(*lookup)(const char *fnname),
   287                       void *(*lookup)(const char *fnname),
   115                       MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
   288                       MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
   116 {
   289 {
   117     error_buffer[0] = '\0';
   290     error_buffer[0] = '\0';
   119     if (strcmp(_profile, MOJOSHADER_PROFILE_GLSL) != 0)
   292     if (strcmp(_profile, MOJOSHADER_PROFILE_GLSL) != 0)
   120         profile = MOJOSHADER_PROFILE_GLSL;
   293         profile = MOJOSHADER_PROFILE_GLSL;
   121     else
   294     else
   122     {
   295     {
   123         set_error("unknown profile");
   296         set_error("unknown profile");
   124         return 0;
   297         goto init_fail;
   125     } // else
   298     } // else
   126 
   299 
   127     // !!! FIXME: lookup glGetString(), check extensions.
   300     if (!check_extensions(lookup))
       
   301         goto init_fail;
   128 
   302 
   129     malloc_fn = (m == NULL) ? internal_malloc : m;
   303     malloc_fn = (m == NULL) ? internal_malloc : m;
   130     free_fn = (f == NULL) ? internal_free : f;
   304     free_fn = (f == NULL) ? internal_free : f;
   131     malloc_data = d;
   305     malloc_data = d;
   132 
       
   133     // !!! FIXME: lookup other entry points.
       
   134 
   306 
   135     memset(vs_register_file_f, '\0', sizeof (vs_register_file_f));
   307     memset(vs_register_file_f, '\0', sizeof (vs_register_file_f));
   136     memset(vs_register_file_i, '\0', sizeof (vs_register_file_i));
   308     memset(vs_register_file_i, '\0', sizeof (vs_register_file_i));
   137     memset(vs_register_file_b, '\0', sizeof (vs_register_file_b));
   309     memset(vs_register_file_b, '\0', sizeof (vs_register_file_b));
   138     memset(ps_register_file_f, '\0', sizeof (ps_register_file_f));
   310     memset(ps_register_file_f, '\0', sizeof (ps_register_file_f));
   140     memset(ps_register_file_b, '\0', sizeof (ps_register_file_b));
   312     memset(ps_register_file_b, '\0', sizeof (ps_register_file_b));
   141 
   313 
   142     MOJOSHADER_glBindProgram(NULL);
   314     MOJOSHADER_glBindProgram(NULL);
   143 
   315 
   144     return 1;
   316     return 1;
       
   317 
       
   318 init_fail:
       
   319     opengl_major = 0;
       
   320     opengl_minor = 0;
       
   321     profile = NULL;
       
   322     malloc_fn = NULL;
       
   323     free_fn = NULL;
       
   324     malloc_data = NULL;
       
   325     lookup_entry_points(NULL);
       
   326     return 0;
   145 } // MOJOSHADER_glInit
   327 } // MOJOSHADER_glInit
   146 
   328 
   147 
   329 
   148 MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
   330 MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
   149                                                 const unsigned int bufsize)
   331                                                 const unsigned int bufsize)
   162     retval = (MOJOSHADER_glShader *) Malloc(sizeof (MOJOSHADER_glShader));
   344     retval = (MOJOSHADER_glShader *) Malloc(sizeof (MOJOSHADER_glShader));
   163     if (retval == NULL)
   345     if (retval == NULL)
   164         goto compile_shader_fail;
   346         goto compile_shader_fail;
   165 
   347 
   166     GLint ok = 0;
   348     GLint ok = 0;
   167     const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER_ARB : GL_VERTEX_SHADER_ARB;
   349     const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
   168     GLint shaderlen = (GLint) pd->output_len;
   350     GLint shaderlen = (GLint) pd->output_len;
   169     shader = pglCreateShaderObjectARB(shader_type);
   351     shader = pglCreateShaderObject(shader_type);
   170 
   352 
   171     pglShaderSourceARB(shader, 1, (const GLcharARB **) &pd->output, &shaderlen);
   353     pglShaderSource(shader, 1, (const GLchar **) &pd->output, &shaderlen);
   172     pglCompileShaderARB(shader);
   354     pglCompileShader(shader);
   173     pglGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
   355     pglGetObjectParameteriv(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
   174 
   356 
   175     if (!ok)
   357     if (!ok)
   176     {
   358     {
   177         GLsizei len = 0;
   359         GLsizei len = 0;
   178         pglGetInfoLogARB(shader, sizeof (error_buffer), &len,
   360         pglGetInfoLog(shader, sizeof (error_buffer), &len, (GLchar *) error_buffer);
   179                          (GLcharARB *) error_buffer);
       
   180         goto compile_shader_fail;
   361         goto compile_shader_fail;
   181     } // if
   362     } // if
   182 
   363 
   183     retval->parseData = pd;
   364     retval->parseData = pd;
   184     retval->handle = shader;
   365     retval->handle = shader;
   187 
   368 
   188 compile_shader_fail:
   369 compile_shader_fail:
   189     MOJOSHADER_freeParseData(pd);
   370     MOJOSHADER_freeParseData(pd);
   190     Free(retval);
   371     Free(retval);
   191     if (shader != 0)
   372     if (shader != 0)
   192         pglDeleteObjectARB(shader);
   373         pglDeleteObject(shader);
   193     return NULL;
   374     return NULL;
   194 } // MOJOSHADER_glCompileShader
   375 } // MOJOSHADER_glCompileShader
   195 
   376 
   196 
   377 
   197 static void shader_unref(MOJOSHADER_glShader *shader)
   378 static void shader_unref(MOJOSHADER_glShader *shader)
   201         const uint32 refcount = shader->refcount;
   382         const uint32 refcount = shader->refcount;
   202         if (refcount > 1)
   383         if (refcount > 1)
   203             shader->refcount--;
   384             shader->refcount--;
   204         else
   385         else
   205         {
   386         {
   206             pglDeleteObjectARB(shader->handle);
   387             pglDeleteObject(shader->handle);
   207             MOJOSHADER_freeParseData(shader->parseData);
   388             MOJOSHADER_freeParseData(shader->parseData);
   208             Free(shader);
   389             Free(shader);
   209         } // else
   390         } // else
   210     } // if
   391     } // if
   211 } // shader_unref
   392 } // shader_unref
   218         const uint32 refcount = program->refcount;
   399         const uint32 refcount = program->refcount;
   219         if (refcount > 1)
   400         if (refcount > 1)
   220             program->refcount--;
   401             program->refcount--;
   221         else
   402         else
   222         {
   403         {
   223             pglDeleteObjectARB(program->handle);
   404             pglDeleteObject(program->handle);
   224             shader_unref(program->vertex);
   405             shader_unref(program->vertex);
   225             shader_unref(program->fragment);
   406             shader_unref(program->fragment);
   226             Free(program->attributes);
   407             Free(program->attributes);
   227             Free(program->uniforms);
   408             Free(program->uniforms);
   228             Free(program);
   409             Free(program);
   239     const MOJOSHADER_uniform *u = pd->uniforms;
   420     const MOJOSHADER_uniform *u = pd->uniforms;
   240     const MOJOSHADER_shaderType shader_type = pd->shader_type;
   421     const MOJOSHADER_shaderType shader_type = pd->shader_type;
   241 
   422 
   242     for (i = 0; i < pd->uniform_count; i++)
   423     for (i = 0; i < pd->uniform_count; i++)
   243     {
   424     {
   244         const GLint loc = pglGetUniformLocationARB(program->handle, u[i].name);
   425         const GLint loc = pglGetUniformLocation(program->handle, u[i].name);
   245         if (loc != -1)  // maybe the Uniform was optimized out?
   426         if (loc != -1)  // maybe the Uniform was optimized out?
   246         {
   427         {
   247             UniformMap *map = &program->uniforms[program->uniform_count];
   428             UniformMap *map = &program->uniforms[program->uniform_count];
   248             map->shader_type = shader_type;
   429             map->shader_type = shader_type;
   249             map->uniform = &u[i];
   430             map->uniform = &u[i];
   260     const MOJOSHADER_parseData *pd = program->vertex->parseData;
   441     const MOJOSHADER_parseData *pd = program->vertex->parseData;
   261     const MOJOSHADER_attribute *a = pd->attributes;
   442     const MOJOSHADER_attribute *a = pd->attributes;
   262 
   443 
   263     for (i = 0; i < pd->attribute_count; i++)
   444     for (i = 0; i < pd->attribute_count; i++)
   264     {
   445     {
   265         const GLint loc = pglGetAttribLocationARB(program->handle, a->name);
   446         const GLint loc = pglGetAttribLocation(program->handle, a->name);
   266         if (loc != -1)  // maybe the Attribute was optimized out?
   447         if (loc != -1)  // maybe the Attribute was optimized out?
   267         {
   448         {
   268             AttributeMap *map = &program->attributes[program->attribute_count];
   449             AttributeMap *map = &program->attributes[program->attribute_count];
   269             map->attribute = &a[i];
   450             map->attribute = &a[i];
   270             map->location = (GLuint) loc;
   451             map->location = (GLuint) loc;
   279 {
   460 {
   280     if ((vshader == NULL) && (pshader == NULL))
   461     if ((vshader == NULL) && (pshader == NULL))
   281         return NULL;
   462         return NULL;
   282 
   463 
   283     MOJOSHADER_glProgram *retval = NULL;
   464     MOJOSHADER_glProgram *retval = NULL;
   284     const GLhandleARB program = pglCreateProgramObjectARB();
   465     const GLhandleARB program = pglCreateProgramObject();
   285 
   466 
   286     if (vshader != NULL) pglAttachObjectARB(program, vshader->handle);
   467     if (vshader != NULL) pglAttachObject(program, vshader->handle);
   287     if (pshader != NULL) pglAttachObjectARB(program, pshader->handle);
   468     if (pshader != NULL) pglAttachObject(program, pshader->handle);
   288 
   469 
   289     pglLinkProgramARB(program);
   470     pglLinkProgram(program);
   290 
   471 
   291     GLint ok = 0;
   472     GLint ok = 0;
   292     pglGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
   473     pglGetObjectParameteriv(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
   293     if (!ok)
   474     if (!ok)
   294     {
   475     {
   295         GLsizei len = 0;
   476         GLsizei len = 0;
   296         pglGetInfoLogARB(program, sizeof (error_buffer), &len,
   477         pglGetInfoLog(program, sizeof (error_buffer), &len, (GLchar *) error_buffer);
   297                          (GLcharARB *) error_buffer);
       
   298         goto link_program_fail;
   478         goto link_program_fail;
   299     } // if
   479     } // if
   300 
   480 
   301     retval = (MOJOSHADER_glProgram *) Malloc(sizeof (MOJOSHADER_glProgram));
   481     retval = (MOJOSHADER_glProgram *) Malloc(sizeof (MOJOSHADER_glProgram));
   302     if (retval == NULL)
   482     if (retval == NULL)
   342         Free(retval->uniforms);
   522         Free(retval->uniforms);
   343         Free(retval->attributes);
   523         Free(retval->attributes);
   344         Free(retval);
   524         Free(retval);
   345     } // if
   525     } // if
   346 
   526 
   347     pglDeleteObjectARB(program);
   527     pglDeleteObject(program);
   348     return NULL;
   528     return NULL;
   349 } // MOJOSHADER_glLinkProgram
   529 } // MOJOSHADER_glLinkProgram
   350 
   530 
   351 
   531 
   352 void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program)
   532 void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program)
   362     {
   542     {
   363         pglDisableClientState(GL_VERTEX_ARRAY);
   543         pglDisableClientState(GL_VERTEX_ARRAY);
   364         for (i = 0; i < bound_program->attribute_count; i++)
   544         for (i = 0; i < bound_program->attribute_count; i++)
   365         {
   545         {
   366             const AttributeMap *map = &bound_program->attributes[i];
   546             const AttributeMap *map = &bound_program->attributes[i];
   367             pglDisableVertexAttribArrayARB(map->location);
   547             pglDisableVertexAttribArray(map->location);
   368         } // if
   548         } // if
   369     } // for
   549     } // for
   370 
   550 
   371     if (program != NULL)
   551     if (program != NULL)
   372     {
   552     {
   373         handle = program->handle;
   553         handle = program->handle;
   374         program->refcount++;
   554         program->refcount++;
   375     } // if
   555     } // if
   376 
   556 
   377     pglUseProgramObjectARB(handle);
   557     pglUseProgramObject(handle);
   378     program_unref(bound_program);
   558     program_unref(bound_program);
   379     bound_program = program;
   559     bound_program = program;
   380 } // MOJOSHADER_glBindProgram
   560 } // MOJOSHADER_glBindProgram
   381 
   561 
   382 
   562 
   543 
   723 
   544     if (gl_index != 0)
   724     if (gl_index != 0)
   545     {
   725     {
   546         const GLenum gl_type = opengl_attr_type(type);
   726         const GLenum gl_type = opengl_attr_type(type);
   547         const GLboolean norm = (normalized) ? GL_TRUE : GL_FALSE;
   727         const GLboolean norm = (normalized) ? GL_TRUE : GL_FALSE;
   548         pglVertexAttribPointerARB(gl_index, size, gl_type, norm, stride, ptr);
   728         pglVertexAttribPointer(gl_index, size, gl_type, norm, stride, ptr);
   549         pglEnableVertexAttribArrayARB(gl_index);
   729         pglEnableVertexAttribArray(gl_index);
   550     } // if
   730     } // if
   551 } // MOJOSHADER_glSetVertexAttribute
   731 } // MOJOSHADER_glSetVertexAttribute
   552 
   732 
   553 
   733 
   554 void MOJOSHADER_glProgramReady(void)
   734 void MOJOSHADER_glProgramReady(void)
   571         const GLint location = map->location;
   751         const GLint location = map->location;
   572 
   752 
   573         if (shader_type == MOJOSHADER_TYPE_VERTEX)
   753         if (shader_type == MOJOSHADER_TYPE_VERTEX)
   574         {
   754         {
   575             if (type == MOJOSHADER_UNIFORM_FLOAT)
   755             if (type == MOJOSHADER_UNIFORM_FLOAT)
   576                 pglUniform4fvARB(location, 1, &vs_register_file_f[index * 4]);
   756                 pglUniform4fv(location, 1, &vs_register_file_f[index * 4]);
   577             else if (type == MOJOSHADER_UNIFORM_INT)
   757             else if (type == MOJOSHADER_UNIFORM_INT)
   578                 pglUniform4ivARB(location, 1, &vs_register_file_i[index * 4]);
   758                 pglUniform4iv(location, 1, &vs_register_file_i[index * 4]);
   579             else if (type == MOJOSHADER_UNIFORM_BOOL)
   759             else if (type == MOJOSHADER_UNIFORM_BOOL)
   580                 pglUniform1iARB(location, vs_register_file_b[index]);
   760                 pglUniform1i(location, vs_register_file_b[index]);
   581         } // if
   761         } // if
   582 
   762 
   583         else if (shader_type == MOJOSHADER_TYPE_PIXEL)
   763         else if (shader_type == MOJOSHADER_TYPE_PIXEL)
   584         {
   764         {
   585             if (type == MOJOSHADER_UNIFORM_FLOAT)
   765             if (type == MOJOSHADER_UNIFORM_FLOAT)
   586                 pglUniform4fvARB(location, 1, &ps_register_file_f[index * 4]);
   766                 pglUniform4fv(location, 1, &ps_register_file_f[index * 4]);
   587             else if (type == MOJOSHADER_UNIFORM_INT)
   767             else if (type == MOJOSHADER_UNIFORM_INT)
   588                 pglUniform4ivARB(location, 1, &ps_register_file_i[index * 4]);
   768                 pglUniform4iv(location, 1, &ps_register_file_i[index * 4]);
   589             else if (type == MOJOSHADER_UNIFORM_BOOL)
   769             else if (type == MOJOSHADER_UNIFORM_BOOL)
   590                 pglUniform1iARB(location, ps_register_file_b[index]);
   770                 pglUniform1i(location, ps_register_file_b[index]);
   591         } // else if
   771         } // else if
   592     } // for
   772     } // for
   593 } // MOJOSHADER_glProgramReady
   773 } // MOJOSHADER_glProgramReady
   594 
   774 
   595 
   775 
   606 
   786 
   607 
   787 
   608 void MOJOSHADER_glDeinit(void)
   788 void MOJOSHADER_glDeinit(void)
   609 {
   789 {
   610     MOJOSHADER_glBindProgram(NULL);
   790     MOJOSHADER_glBindProgram(NULL);
   611 
   791     lookup_entry_points(NULL);
   612     profile = NULL;
   792     profile = NULL;
   613     malloc_fn = NULL;
   793     malloc_fn = NULL;
   614     free_fn = NULL;
   794     free_fn = NULL;
   615     malloc_data = NULL;
   795     malloc_data = NULL;
   616     error_buffer[0] = '\0';
   796     error_buffer[0] = '\0';
   617 
   797     opengl_major = 0;
   618     // !!! FIXME: NULL entry points.
   798     opengl_minor = 0;
   619 } // MOJOSHADER_glDeinit
   799 } // MOJOSHADER_glDeinit
   620 
   800 
   621 // end of mojoshader_opengl.c ...
   801 // end of mojoshader_opengl.c ...
   622 
   802