Cleanups for building as C++ code. trunk
authorRyan C. Gordon <icculus@icculus.org>
Tue, 29 Apr 2008 05:44:40 -0400
branchtrunk
changeset 249 7f928921766c
parent 248 568c8f9d7cb9
child 250 b75c08291021
Cleanups for building as C++ code.
mojoshader.c
mojoshader_opengl.c
--- a/mojoshader.c	Tue Apr 29 04:47:32 2008 -0400
+++ b/mojoshader.c	Tue Apr 29 05:44:40 2008 -0400
@@ -1476,7 +1476,7 @@
 {
     // just copy the whole token stream and make all other emitters no-ops.
     ctx->output_len = (ctx->tokencount * sizeof (uint32));
-    ctx->output_bytes = Malloc(ctx, ctx->output_len);
+    ctx->output_bytes = (uint8 *) Malloc(ctx, ctx->output_len);
     if (ctx->output_bytes != NULL)
         memcpy(ctx->output_bytes, ctx->tokens, ctx->output_len);
 } // emit_PASSTHROUGH_start
@@ -2337,7 +2337,7 @@
     if (ctx->flags & CTX_FLAGS_GLSL_LIT_OPCODE)
         return;
 
-    ctx->flags |= CTX_FLAGS_GLSL_LIT_OPCODE;
+    ctx->flags = (ContextFlags) (ctx->flags | CTX_FLAGS_GLSL_LIT_OPCODE);
 
     push_output(ctx, &ctx->helpers);
     output_line(ctx, "const vec4 LIT(const vec4 src)");
@@ -4347,7 +4347,7 @@
     if (m == NULL) m = internal_malloc;
     if (f == NULL) f = internal_free;
 
-    Context *ctx = m(sizeof (Context), d);
+    Context *ctx = (Context *) m(sizeof (Context), d);
     if (ctx == NULL)
         return NULL;
 
@@ -4654,10 +4654,11 @@
     MOJOSHADER_uniform *uniforms = NULL;
     MOJOSHADER_attribute *attributes = NULL;
     MOJOSHADER_sampler *samplers = NULL;
-    MOJOSHADER_parseData *retval;
+    MOJOSHADER_parseData *retval = NULL;
     int attribute_count = 0;
 
-    if ((retval = Malloc(ctx, sizeof (MOJOSHADER_parseData))) == NULL)
+    retval = (MOJOSHADER_parseData*) Malloc(ctx, sizeof(MOJOSHADER_parseData));
+    if (retval == NULL)
         return &out_of_mem_data;
 
     memset(retval, '\0', sizeof (MOJOSHADER_parseData));
@@ -4754,7 +4755,7 @@
                     // Apparently this is an attribute that wasn't DCL'd.
                     //  Add it to the attribute list; deal with it later.
                     add_attribute_register(ctx, item->regtype, item->regnum,
-                                           0, 0, 0xF);
+                                           MOJOSHADER_USAGE_UNKNOWN, 0, 0xF);
                     break;
 
                 case REG_TYPE_ADDRESS:
--- a/mojoshader_opengl.c	Tue Apr 29 04:47:32 2008 -0400
+++ b/mojoshader_opengl.c	Tue Apr 29 05:44:40 2008 -0400
@@ -61,7 +61,7 @@
 };
 
 // Entry points in base OpenGL that lack function pointer prototypes...
-typedef WINGDIAPI const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
+typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
 
 struct MOJOSHADER_glContext
 {
@@ -72,12 +72,12 @@
 
     // The constant register files...
     // Man, it kills me how much memory this takes...
-    float vs_reg_file_f[8192 * 4];
-    int vs_reg_file_i[2047 * 4];
-    uint8 vs_reg_file_b[2047];
-    float ps_reg_file_f[8192 * 4];
-    int ps_reg_file_i[2047 * 4];
-    uint8 ps_reg_file_b[2047];
+    GLfloat vs_reg_file_f[8192 * 4];
+    GLint vs_reg_file_i[2047 * 4];
+    GLint vs_reg_file_b[2047];
+    GLfloat ps_reg_file_f[8192 * 4];
+    GLint ps_reg_file_i[2047 * 4];
+    GLint ps_reg_file_b[2047];
 
     // GL stuff...
     int opengl_major;
@@ -302,6 +302,7 @@
                                         MOJOSHADER_malloc m, MOJOSHADER_free f,
                                         void *d)
 {
+    MOJOSHADER_glContext *retval = NULL;
     MOJOSHADER_glContext *current_ctx = ctx;
     ctx = NULL;
 
@@ -315,8 +316,6 @@
         goto init_fail;
     } // if
 
-    MOJOSHADER_glContext *retval = ctx;
-
     memset(ctx, '\0', sizeof (MOJOSHADER_glContext));
     ctx->malloc_fn = m;
     ctx->free_fn = f;
@@ -335,6 +334,7 @@
 
     MOJOSHADER_glBindProgram(NULL);
 
+    retval = ctx;
     ctx = current_ctx;
     return retval;
 
@@ -361,6 +361,10 @@
                                                       bufsize, ctx->malloc_fn,
                                                       ctx->free_fn,
                                                       ctx->malloc_data);
+    GLint ok = 0;
+    const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
+    GLint shaderlen = (GLint) pd->output_len;
+
     if (pd->error != NULL)
     {
         set_error(pd->error);
@@ -371,9 +375,6 @@
     if (retval == NULL)
         goto compile_shader_fail;
 
-    GLint ok = 0;
-    const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
-    GLint shaderlen = (GLint) pd->output_len;
     shader = ctx->glCreateShaderObject(shader_type);
 
     ctx->glShaderSource(shader, 1, (const GLchar **) &pd->output, &shaderlen);
@@ -496,6 +497,7 @@
 
     MOJOSHADER_glProgram *retval = NULL;
     const GLhandleARB program = ctx->glCreateProgramObject();
+    int numregs = 0;
 
     if (vshader != NULL) ctx->glAttachObject(program, vshader->handle);
     if (pshader != NULL) ctx->glAttachObject(program, pshader->handle);
@@ -516,7 +518,6 @@
         goto link_program_fail;
     memset(retval, '\0', sizeof (MOJOSHADER_glProgram));
 
-    int numregs = 0;
     if (vshader != NULL) numregs += vshader->parseData->uniform_count;
     if (pshader != NULL) numregs += pshader->parseData->uniform_count;
     retval->uniforms = (UniformMap *) Malloc(sizeof (UniformMap) * numregs);
@@ -607,6 +608,7 @@
     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4;
     if (idx < maxregs)
     {
+        assert(sizeof (GLfloat) == sizeof (float));
         const uint cpy = (maxuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
         memcpy(ctx->vs_reg_file_f + (idx * 4), data, cpy);
     } // if
@@ -619,6 +621,7 @@
     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_i) / 4;
     if (idx < maxregs)
     {
+        assert(sizeof (GLint) == sizeof (int));
         const uint cpy = (maxuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
         memcpy(ctx->vs_reg_file_i + (idx * 4), data, cpy);
     } // if
@@ -631,8 +634,8 @@
     const uint maxregs = STATICARRAYLEN(ctx->vs_reg_file_f) / 4;
     if (idx < maxregs)
     {
-        uint8 *wptr = ctx->vs_reg_file_b + idx;
-        uint8 *endptr = wptr + maxuint(maxregs - idx, bcount);
+        GLint *wptr = ctx->vs_reg_file_b + idx;
+        GLint *endptr = wptr + maxuint(maxregs - idx, bcount);
         while (wptr != endptr)
             *(wptr++) = *(data++) ? 1 : 0;
     } // if
@@ -645,6 +648,7 @@
     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4;
     if (idx < maxregs)
     {
+        assert(sizeof (GLfloat) == sizeof (float));
         const uint cpy = (maxuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
         memcpy(ctx->ps_reg_file_f + (idx * 4), data, cpy);
     } // if
@@ -657,6 +661,7 @@
     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_i) / 4;
     if (idx < maxregs)
     {
+        assert(sizeof (GLint) == sizeof (int));
         const uint cpy = (maxuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
         memcpy(ctx->ps_reg_file_i + (idx * 4), data, cpy);
     } // if
@@ -669,8 +674,8 @@
     const uint maxregs = STATICARRAYLEN(ctx->ps_reg_file_f) / 4;
     if (idx < maxregs)
     {
-        uint8 *wptr = ctx->ps_reg_file_b + idx;
-        uint8 *endptr = wptr + maxuint(maxregs - idx, bcount);
+        GLint *wptr = ctx->ps_reg_file_b + idx;
+        GLint *endptr = wptr + maxuint(maxregs - idx, bcount);
         while (wptr != endptr)
             *(wptr++) = *(data++) ? 1 : 0;
     } // if