mojoshader_opengl.c
changeset 760 6dc8d2cafc58
parent 759 3b891dbe951a
child 761 3ccbd05350d6
equal deleted inserted replaced
759:3b891dbe951a 760:6dc8d2cafc58
   176     void (*profileUseProgramObject)(MOJOSHADER_glProgram *program);
   176     void (*profileUseProgramObject)(MOJOSHADER_glProgram *program);
   177     void (*profileUniform4fv)(const MOJOSHADER_parseData *, GLint, GLsizei, GLfloat *);
   177     void (*profileUniform4fv)(const MOJOSHADER_parseData *, GLint, GLsizei, GLfloat *);
   178     void (*profileUniform4iv)(const MOJOSHADER_parseData *, GLint, GLsizei, GLint *);
   178     void (*profileUniform4iv)(const MOJOSHADER_parseData *, GLint, GLsizei, GLint *);
   179     void (*profileUniform1i)(const MOJOSHADER_parseData *, GLint, GLint);
   179     void (*profileUniform1i)(const MOJOSHADER_parseData *, GLint, GLint);
   180     void (*profileSetSampler)(GLint loc, GLuint sampler);
   180     void (*profileSetSampler)(GLint loc, GLuint sampler);
   181     int (*profileMustLoadConstantArrays)(void);
   181     int (*profileMustPushConstantArrays)(void);
   182     int (*profileMustLoadSamplers)(void);
   182     int (*profileMustPushSamplers)(void);
   183 };
   183 };
   184 
   184 
   185 
   185 
   186 static MOJOSHADER_glContext *ctx = NULL;
   186 static MOJOSHADER_glContext *ctx = NULL;
   187 
   187 
   275     // !!! FIXME: geometry shaders?
   275     // !!! FIXME: geometry shaders?
   276     return GL_NONE;
   276     return GL_NONE;
   277 } // glsl_shader_type
   277 } // glsl_shader_type
   278 
   278 
   279 
   279 
   280 static int impl_GLSL_MustLoadConstantArrays(void) { return 1; }
   280 static int impl_GLSL_MustPushConstantArrays(void) { return 1; }
   281 static int impl_GLSL_MustLoadSamplers(void) { return 1; }
   281 static int impl_GLSL_MustPushSamplers(void) { return 1; }
   282 
   282 
   283 static int impl_GLSL_MaxUniforms(MOJOSHADER_shaderType shader_type)
   283 static int impl_GLSL_MaxUniforms(MOJOSHADER_shaderType shader_type)
   284 {
   284 {
   285     GLenum pname = GL_NONE;
   285     GLenum pname = GL_NONE;
   286     GLint val = 0;
   286     GLint val = 0;
   426 
   426 
   427     // !!! FIXME: geometry shaders?
   427     // !!! FIXME: geometry shaders?
   428     return GL_NONE;
   428     return GL_NONE;
   429 } // arb1_shader_type
   429 } // arb1_shader_type
   430 
   430 
   431 static int impl_ARB1_MustLoadConstantArrays(void) { return 0; }
   431 static int impl_ARB1_MustPushConstantArrays(void) { return 0; }
   432 static int impl_ARB1_MustLoadSamplers(void) { return 0; }
   432 static int impl_ARB1_MustPushSamplers(void) { return 0; }
   433 
   433 
   434 static int impl_ARB1_MaxUniforms(MOJOSHADER_shaderType shader_type)
   434 static int impl_ARB1_MaxUniforms(MOJOSHADER_shaderType shader_type)
   435 {
   435 {
   436     GLint retval = 0;
   436     GLint retval = 0;
   437     const GLenum program_type = arb1_shader_type(shader_type);
   437     const GLenum program_type = arb1_shader_type(shader_type);
   972         ctx->profileUseProgramObject = impl_GLSL_UseProgramObject;
   972         ctx->profileUseProgramObject = impl_GLSL_UseProgramObject;
   973         ctx->profileUniform4fv = impl_GLSL_Uniform4fv;
   973         ctx->profileUniform4fv = impl_GLSL_Uniform4fv;
   974         ctx->profileUniform4iv = impl_GLSL_Uniform4iv;
   974         ctx->profileUniform4iv = impl_GLSL_Uniform4iv;
   975         ctx->profileUniform1i = impl_GLSL_Uniform1i;
   975         ctx->profileUniform1i = impl_GLSL_Uniform1i;
   976         ctx->profileSetSampler = impl_GLSL_SetSampler;
   976         ctx->profileSetSampler = impl_GLSL_SetSampler;
   977         ctx->profileMustLoadConstantArrays = impl_GLSL_MustLoadConstantArrays;
   977         ctx->profileMustPushConstantArrays = impl_GLSL_MustPushConstantArrays;
   978         ctx->profileMustLoadSamplers = impl_GLSL_MustLoadSamplers;
   978         ctx->profileMustPushSamplers = impl_GLSL_MustPushSamplers;
   979     } // if
   979     } // if
   980 #endif
   980 #endif
   981 
   981 
   982 #if SUPPORT_PROFILE_ARB1
   982 #if SUPPORT_PROFILE_ARB1
   983     else if ( (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) ||
   983     else if ( (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) ||
   996         ctx->profileUseProgramObject = impl_ARB1_UseProgramObject;
   996         ctx->profileUseProgramObject = impl_ARB1_UseProgramObject;
   997         ctx->profileUniform4fv = impl_ARB1_Uniform4fv;
   997         ctx->profileUniform4fv = impl_ARB1_Uniform4fv;
   998         ctx->profileUniform4iv = impl_ARB1_Uniform4iv;
   998         ctx->profileUniform4iv = impl_ARB1_Uniform4iv;
   999         ctx->profileUniform1i = impl_ARB1_Uniform1i;
   999         ctx->profileUniform1i = impl_ARB1_Uniform1i;
  1000         ctx->profileSetSampler = impl_ARB1_SetSampler;
  1000         ctx->profileSetSampler = impl_ARB1_SetSampler;
  1001         ctx->profileMustLoadConstantArrays = impl_ARB1_MustLoadConstantArrays;
  1001         ctx->profileMustPushConstantArrays = impl_ARB1_MustPushConstantArrays;
  1002         ctx->profileMustLoadSamplers = impl_ARB1_MustLoadSamplers;
  1002         ctx->profileMustPushSamplers = impl_ARB1_MustPushSamplers;
  1003 
  1003 
  1004         // GL_NV_gpu_program4 has integer uniform loading support.
  1004         // GL_NV_gpu_program4 has integer uniform loading support.
  1005         if (strcmp(profile, MOJOSHADER_PROFILE_NV4) == 0)
  1005         if (strcmp(profile, MOJOSHADER_PROFILE_NV4) == 0)
  1006         {
  1006         {
  1007             ctx->profileUniform4iv = impl_NV4_Uniform4iv;
  1007             ctx->profileUniform4iv = impl_NV4_Uniform4iv;
  1022     assert(ctx->profileUseProgramObject != NULL);
  1022     assert(ctx->profileUseProgramObject != NULL);
  1023     assert(ctx->profileUniform4fv != NULL);
  1023     assert(ctx->profileUniform4fv != NULL);
  1024     assert(ctx->profileUniform4iv != NULL);
  1024     assert(ctx->profileUniform4iv != NULL);
  1025     assert(ctx->profileUniform1i != NULL);
  1025     assert(ctx->profileUniform1i != NULL);
  1026     assert(ctx->profileSetSampler != NULL);
  1026     assert(ctx->profileSetSampler != NULL);
  1027     assert(ctx->profileMustLoadConstantArrays != NULL);
  1027     assert(ctx->profileMustPushConstantArrays != NULL);
  1028     assert(ctx->profileMustLoadSamplers != NULL);
  1028     assert(ctx->profileMustPushSamplers != NULL);
  1029 
  1029 
  1030     retval = ctx;
  1030     retval = ctx;
  1031     ctx = current_ctx;
  1031     ctx = current_ctx;
  1032     return retval;
  1032     return retval;
  1033 
  1033 
  1175         if (loc != -1)  // maybe the Uniform was optimized out?
  1175         if (loc != -1)  // maybe the Uniform was optimized out?
  1176         {
  1176         {
  1177             // only do constants once, at link time. These aren't changed ever.
  1177             // only do constants once, at link time. These aren't changed ever.
  1178             if (u->constant)
  1178             if (u->constant)
  1179             {
  1179             {
  1180                 if (ctx->profileMustLoadConstantArrays())
  1180                 if (ctx->profileMustPushConstantArrays())
  1181                 {
  1181                 {
  1182                     const int base = u->index;
  1182                     const int base = u->index;
  1183                     const int size = u->array_count;
  1183                     const int size = u->array_count;
  1184                     GLfloat *f = (GLfloat *) alloca(sizeof (GLfloat)*(size*4));
  1184                     GLfloat *f = (GLfloat *) alloca(sizeof (GLfloat)*(size*4));
  1185                     fill_constant_array(f, base, size, pd);
  1185                     fill_constant_array(f, base, size, pd);
  1207 {
  1207 {
  1208     const MOJOSHADER_parseData *pd = shader->parseData;
  1208     const MOJOSHADER_parseData *pd = shader->parseData;
  1209     const MOJOSHADER_sampler *s = pd->samplers;
  1209     const MOJOSHADER_sampler *s = pd->samplers;
  1210     int i;
  1210     int i;
  1211 
  1211 
  1212     if ((pd->sampler_count == 0) || (!ctx->profileMustLoadSamplers()))
  1212     if ((pd->sampler_count == 0) || (!ctx->profileMustPushSamplers()))
  1213         return;   // nothing to do here, so don't bother binding, etc.
  1213         return;   // nothing to do here, so don't bother binding, etc.
  1214 
  1214 
  1215     // Link up the Samplers. These never change after link time, since they
  1215     // Link up the Samplers. These never change after link time, since they
  1216     //  are meant to be constant texture unit ids and not textures.
  1216     //  are meant to be constant texture unit ids and not textures.
  1217 
  1217