mojoshader_opengl.c
changeset 1056 73c697a7e950
parent 1043 6227066350b4
child 1060 4cdf5a3ceb03
equal deleted inserted replaced
1055:3295380ce6fc 1056:73c697a7e950
    43 
    43 
    44 #ifndef GL_HALF_FLOAT_OES
    44 #ifndef GL_HALF_FLOAT_OES
    45 #define GL_HALF_FLOAT_OES 0x8D61
    45 #define GL_HALF_FLOAT_OES 0x8D61
    46 #endif
    46 #endif
    47 
    47 
       
    48 // this happens to be the same value for ARB1 and GLSL.
       
    49 #ifndef GL_PROGRAM_POINT_SIZE
       
    50 #define GL_PROGRAM_POINT_SIZE 0x8642
       
    51 #endif
    48 
    52 
    49 struct MOJOSHADER_glShader
    53 struct MOJOSHADER_glShader
    50 {
    54 {
    51     const MOJOSHADER_parseData *parseData;
    55     const MOJOSHADER_parseData *parseData;
    52     GLuint handle;
    56     GLuint handle;
    93     GLfloat *vs_preshader_regs;
    97     GLfloat *vs_preshader_regs;
    94     size_t ps_preshader_reg_count;
    98     size_t ps_preshader_reg_count;
    95     GLfloat *ps_preshader_regs;
    99     GLfloat *ps_preshader_regs;
    96 
   100 
    97     uint32 refcount;
   101     uint32 refcount;
       
   102 
       
   103     int uses_pointsize;
       
   104 
    98     // GLSL uses these...location of uniform arrays.
   105     // GLSL uses these...location of uniform arrays.
    99     GLint vs_float4_loc;
   106     GLint vs_float4_loc;
   100     GLint vs_int4_loc;
   107     GLint vs_int4_loc;
   101     GLint vs_bool_loc;
   108     GLint vs_bool_loc;
   102     GLint ps_float4_loc;
   109     GLint ps_float4_loc;
   143 
   150 
   144     // This tells us which vertex attribute arrays we have enabled.
   151     // This tells us which vertex attribute arrays we have enabled.
   145     GLint max_attrs;
   152     GLint max_attrs;
   146     uint8 want_attr[32];
   153     uint8 want_attr[32];
   147     uint8 have_attr[32];
   154     uint8 have_attr[32];
       
   155 
       
   156     // rarely used, so we don't touch when we don't have to.
       
   157     int pointsize_enabled;
   148 
   158 
   149     // GL stuff...
   159     // GL stuff...
   150     int opengl_major;
   160     int opengl_major;
   151     int opengl_minor;
   161     int opengl_minor;
   152     MOJOSHADER_glProgram *bound_program;
   162     MOJOSHADER_glProgram *bound_program;
  1468             ctx->profilePushSampler(loc, s[i].index);
  1478             ctx->profilePushSampler(loc, s[i].index);
  1469     } // for
  1479     } // for
  1470 } // lookup_samplers
  1480 } // lookup_samplers
  1471 
  1481 
  1472 
  1482 
       
  1483 // Right now, this just decides if we have to toggle pointsize support later.
       
  1484 static void lookup_outputs(MOJOSHADER_glProgram *program,
       
  1485                            MOJOSHADER_glShader *shader)
       
  1486 {
       
  1487     const MOJOSHADER_parseData *pd = shader->parseData;
       
  1488     int i;
       
  1489 
       
  1490     for (i = 0; i < pd->output_count; i++)
       
  1491     {
       
  1492         if (pd->outputs[i].usage == MOJOSHADER_USAGE_POINTSIZE)
       
  1493         {
       
  1494             program->uses_pointsize = 1;
       
  1495             break;
       
  1496         } // if
       
  1497     } // for
       
  1498 } // lookup_outputs
       
  1499 
       
  1500 
  1473 static int lookup_attributes(MOJOSHADER_glProgram *program)
  1501 static int lookup_attributes(MOJOSHADER_glProgram *program)
  1474 {
  1502 {
  1475     int i;
  1503     int i;
  1476     const MOJOSHADER_parseData *pd = program->vertex->parseData;
  1504     const MOJOSHADER_parseData *pd = program->vertex->parseData;
  1477     const MOJOSHADER_attribute *a = pd->attributes;
  1505     const MOJOSHADER_attribute *a = pd->attributes;
  1579         } // if
  1607         } // if
  1580 
  1608 
  1581         if (!lookup_uniforms(retval, vshader, &bound))
  1609         if (!lookup_uniforms(retval, vshader, &bound))
  1582             goto link_program_fail;
  1610             goto link_program_fail;
  1583         lookup_samplers(retval, vshader, &bound);
  1611         lookup_samplers(retval, vshader, &bound);
       
  1612         lookup_outputs(retval, pshader);
  1584         vshader->refcount++;
  1613         vshader->refcount++;
  1585     } // if
  1614     } // if
  1586 
  1615 
  1587     if (pshader != NULL)
  1616     if (pshader != NULL)
  1588     {
  1617     {
  1589         if (!lookup_uniforms(retval, pshader, &bound))
  1618         if (!lookup_uniforms(retval, pshader, &bound))
  1590             goto link_program_fail;
  1619             goto link_program_fail;
  1591         lookup_samplers(retval, pshader, &bound);
  1620         lookup_samplers(retval, pshader, &bound);
       
  1621         lookup_outputs(retval, pshader);
  1592         pshader->refcount++;
  1622         pshader->refcount++;
  1593     } // if
  1623     } // if
  1594 
  1624 
  1595     if (!build_constants_lists(retval))
  1625     if (!build_constants_lists(retval))
  1596         goto link_program_fail;
  1626         goto link_program_fail;
  2006     if (program == NULL)
  2036     if (program == NULL)
  2007         return;  // nothing to do.
  2037         return;  // nothing to do.
  2008 
  2038 
  2009     // Toggle vertex attribute arrays on/off, based on our needs.
  2039     // Toggle vertex attribute arrays on/off, based on our needs.
  2010     update_enabled_arrays();
  2040     update_enabled_arrays();
       
  2041 
       
  2042     if (program->uses_pointsize != ctx->pointsize_enabled)
       
  2043     {
       
  2044         if (program->uses_pointsize)
       
  2045             ctx->glEnable(GL_PROGRAM_POINT_SIZE);
       
  2046         else
       
  2047             ctx->glDisable(GL_PROGRAM_POINT_SIZE);
       
  2048         ctx->pointsize_enabled = program->uses_pointsize;
       
  2049     } // if
  2011 
  2050 
  2012     // push Uniforms to the program from our register files...
  2051     // push Uniforms to the program from our register files...
  2013     if ((program->uniform_count) && (program->generation != ctx->generation))
  2052     if ((program->uniform_count) && (program->generation != ctx->generation))
  2014     {
  2053     {
  2015         // vertex shader uniforms come first in program->uniforms array.
  2054         // vertex shader uniforms come first in program->uniforms array.