Support for half-float attribute arrays. trunk
authorRyan C. Gordon <icculus@icculus.org>
Mon, 28 Apr 2008 04:49:02 -0400
branchtrunk
changeset 236 8e2fc535b210
parent 235 a9ec326856d5
child 237 09f35dfc1d7e
Support for half-float attribute arrays.
mojoshader.h
mojoshader_opengl.c
--- a/mojoshader.h	Mon Apr 28 02:28:34 2008 -0400
+++ b/mojoshader.h	Mon Apr 28 04:49:02 2008 -0400
@@ -61,7 +61,8 @@
     MOJOSHADER_ATTRIBUTE_INT,
     MOJOSHADER_ATTRIBUTE_UINT,
     MOJOSHADER_ATTRIBUTE_FLOAT,
-    MOJOSHADER_ATTRIBUTE_DOUBLE
+    MOJOSHADER_ATTRIBUTE_DOUBLE,
+    MOJOSHADER_ATTRIBUTE_HALF_FLOAT,  /* MAYBE available in your OpenGL! */
 } MOJOSHADER_attributeType;
 
 /*
--- a/mojoshader_opengl.c	Mon Apr 28 02:28:34 2008 -0400
+++ b/mojoshader_opengl.c	Mon Apr 28 04:49:02 2008 -0400
@@ -71,17 +71,20 @@
 static MOJOSHADER_glProgram *bound_program = NULL;
 static const char *profile = NULL;
 
+// Extensions...
+static int have_base_opengl = 0;
+static int have_GL_ARB_shader_objects = 0;
+static int have_GL_ARB_vertex_shader = 0;
+static int have_GL_ARB_fragment_shader = 0;
+static int have_GL_ARB_shading_language_100 = 0;
+static int have_GL_NV_half_float = 0;
+
 // Entry points...
 typedef WINGDIAPI const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
 typedef WINGDIAPI void (APIENTRYP PFNGLDISABLECLIENTSTATEPROC) (GLenum array);
 typedef WINGDIAPI void (APIENTRYP PFNGLENABLECLIENTSTATEPROC) (GLenum array);
 typedef WINGDIAPI void (APIENTRYP PFNGLVERTEXPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
 
-static int have_base_opengl = 0;
-static int have_GL_ARB_shader_objects = 0;
-static int have_GL_ARB_vertex_shader = 0;
-static int have_GL_ARB_fragment_shader = 0;
-static int have_GL_ARB_shading_language_100 = 0;
 static PFNGLGETSTRINGPROC pglGetString = NULL;
 static PFNGLDELETEOBJECTARBPROC pglDeleteObject = NULL;
 static PFNGLATTACHOBJECTARBPROC pglAttachObject = NULL;
@@ -202,9 +205,12 @@
         return 0;  // don't bother checking, we're missing an entry point.
 
     // See if it's in the spec for this GL implementation's version.
-    if ( ((opengl_major << 16) | (opengl_minor & 0xFFFF)) >=
-         ((major << 16) | (minor & 0xFFFF)) )
-        return 1;
+    if (major >= 0)
+    {
+        if ( ((opengl_major << 16) | (opengl_minor & 0xFFFF)) >=
+             ((major << 16) | (minor & 0xFFFF)) )
+            return 1;
+    } // if
 
     // Not available in the GL version, check the extension list.
     const char *ptr = strstr(extlist, ext);
@@ -235,6 +241,7 @@
     have_GL_ARB_vertex_shader = 1;
     have_GL_ARB_fragment_shader = 1;
     have_GL_ARB_shading_language_100 = 1;
+    have_GL_NV_half_float = 1;
 
     lookup_entry_points(lookup);
 
@@ -257,6 +264,7 @@
     VERIFY_EXT(GL_ARB_vertex_shader, 2, 0);
     VERIFY_EXT(GL_ARB_fragment_shader, 2, 0);
     VERIFY_EXT(GL_ARB_shading_language_100, 2, 0);
+    VERIFY_EXT(GL_NV_half_float, -1, -1);
 
     #undef VERIFY_EXT
 
@@ -658,6 +666,7 @@
         case MOJOSHADER_ATTRIBUTE_UINT: return GL_INT;
         case MOJOSHADER_ATTRIBUTE_FLOAT: return GL_FLOAT;
         case MOJOSHADER_ATTRIBUTE_DOUBLE: return GL_DOUBLE;
+        case MOJOSHADER_ATTRIBUTE_HALF_FLOAT: return GL_SHORT;
     } // switch
 
     return GL_NONE;  // oh well. Raises a GL error later.
@@ -676,6 +685,11 @@
         case MOJOSHADER_ATTRIBUTE_UINT: return GL_UNSIGNED_INT;
         case MOJOSHADER_ATTRIBUTE_FLOAT: return GL_FLOAT;
         case MOJOSHADER_ATTRIBUTE_DOUBLE: return GL_DOUBLE;
+
+        case MOJOSHADER_ATTRIBUTE_HALF_FLOAT:
+            if (have_GL_NV_half_float)
+                return GL_HALF_FLOAT_NV;
+            break;
     } // switch
 
     return GL_NONE;  // oh well. Raises a GL error later.