#include "context.h"\r
#include "macros.h"\r
#include "hash.h"\r
-\r
+#include "slang_mesa.h"\r
+#include "Public/ShaderLang.h"\r
\r
struct gl2_unknown_obj\r
{\r
impl->_obj._destructor = _unknown_destructor;\r
}\r
\r
+struct gl2_unkinner_obj\r
+{\r
+ struct gl2_unknown_intf **unkouter;\r
+};\r
+\r
+struct gl2_unkinner_impl\r
+{\r
+ struct gl2_unknown_intf *_vftbl;\r
+ struct gl2_unkinner_obj _obj;\r
+};\r
+\r
+static void\r
+_unkinner_destructor (struct gl2_unknown_intf **intf)\r
+{\r
+}\r
+\r
+static void\r
+_unkinner_AddRef (struct gl2_unknown_intf **intf)\r
+{\r
+ struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;\r
+\r
+ (**impl->_obj.unkouter).AddRef (impl->_obj.unkouter);\r
+}\r
+\r
+static void\r
+_unkinner_Release (struct gl2_unknown_intf **intf)\r
+{\r
+ struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;\r
+\r
+ (**impl->_obj.unkouter).Release (impl->_obj.unkouter);\r
+}\r
+\r
+static struct gl2_unknown_intf **\r
+_unkinner_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)\r
+{\r
+ struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;\r
+\r
+ return (**impl->_obj.unkouter).QueryInterface (impl->_obj.unkouter, uiid);\r
+}\r
+\r
+static struct gl2_unknown_intf _unkinner_vftbl = {\r
+ _unkinner_AddRef,\r
+ _unkinner_Release,\r
+ _unkinner_QueryInterface\r
+};\r
+\r
+static void\r
+_unkinner_constructor (struct gl2_unkinner_impl *impl, struct gl2_unknown_intf **outer)\r
+{\r
+ impl->_vftbl = &_unkinner_vftbl;\r
+ impl->_obj.unkouter = outer;\r
+}\r
+\r
struct gl2_generic_obj\r
{\r
struct gl2_unknown_obj _unknown;\r
_generic_QueryInterface\r
},\r
_generic_Delete,\r
- NULL,\r
+ NULL, /* abstract GetType */\r
_generic_GetName,\r
_generic_GetDeleteStatus,\r
_generic_GetInfoLog\r
}\r
\r
static struct gl2_container_intf _container_vftbl = {\r
- {\r
- {\r
- _unknown_AddRef,\r
- _unknown_Release,\r
- _container_QueryInterface,\r
- },\r
- _generic_Delete,\r
- NULL,\r
- _generic_GetName,\r
- _generic_GetDeleteStatus,\r
- _generic_GetInfoLog,\r
- },\r
+ {\r
+ {\r
+ _unknown_AddRef,\r
+ _unknown_Release,\r
+ _container_QueryInterface\r
+ },\r
+ _generic_Delete,\r
+ NULL, /* abstract GetType */\r
+ _generic_GetName,\r
+ _generic_GetDeleteStatus,\r
+ _generic_GetInfoLog\r
+ },\r
_container_Attach,\r
_container_Detach,\r
_container_GetAttachedCount,\r
impl->_obj.attached_count = 0;\r
}\r
\r
+struct gl2_3dlabs_shhandle_obj\r
+{\r
+ struct gl2_unkinner_obj _unknown;\r
+ ShHandle handle;\r
+};\r
+\r
+struct gl2_3dlabs_shhandle_impl\r
+{\r
+ struct gl2_3dlabs_shhandle_intf *_vftbl;\r
+ struct gl2_3dlabs_shhandle_obj _obj;\r
+};\r
+\r
+static void\r
+_3dlabs_shhandle_destructor (struct gl2_unknown_intf **intf)\r
+{\r
+ struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;\r
+\r
+ ShDestruct (impl->_obj.handle);\r
+ _unkinner_destructor (intf);\r
+}\r
+\r
+static GLvoid *\r
+_3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf **intf)\r
+{\r
+ struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;\r
+\r
+ return impl->_obj.handle;\r
+}\r
+\r
+static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl = {\r
+ {\r
+ _unkinner_AddRef,\r
+ _unkinner_Release,\r
+ _unkinner_QueryInterface\r
+ },\r
+ _3dlabs_shhandle_GetShHandle\r
+};\r
+\r
+static void\r
+_3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl *impl, struct gl2_unknown_intf **outer)\r
+{\r
+ _unkinner_constructor ((struct gl2_unkinner_impl *) impl, outer);\r
+ impl->_vftbl = &_3dlabs_shhandle_vftbl;\r
+ impl->_obj.handle = NULL;\r
+}\r
+\r
struct gl2_shader_obj\r
{\r
struct gl2_generic_obj _generic;\r
+ struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle;\r
GLboolean compile_status;\r
GLcharARB *source;\r
GLint *offsets;\r
\r
_mesa_free ((void *) impl->_obj.source);\r
_mesa_free ((void *) impl->_obj.offsets);\r
+ _3dlabs_shhandle_destructor ((struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl);\r
_generic_destructor (intf);\r
}\r
\r
static struct gl2_unknown_intf **\r
_shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)\r
{\r
+ struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;\r
+\r
if (uiid == UIID_SHADER)\r
{\r
(**intf).AddRef (intf);\r
return intf;\r
}\r
+ if (uiid == UIID_3DLABS_SHHANDLE)\r
+ {\r
+ (**intf).AddRef (intf);\r
+ return (struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl;\r
+ }\r
return _generic_QueryInterface (intf, uiid);\r
}\r
\r
_shader_Compile (struct gl2_shader_intf **intf)\r
{\r
struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;\r
+ char **strings;\r
+ TBuiltInResource res;\r
\r
impl->_obj.compile_status = GL_FALSE;\r
_mesa_free ((void *) impl->_obj._generic.info_log);\r
impl->_obj._generic.info_log = NULL;\r
\r
- /* TODO compile */\r
+ /* 3dlabs compiler expects us to feed it with null-terminated string array,\r
+ we've got only one big string with offsets, so we must split it; but when\r
+ there's only one string to deal with, we pass its address directly */\r
+\r
+ if (impl->_obj.offset_count <= 1)\r
+ strings = &impl->_obj.source;\r
+ else\r
+ {\r
+ GLsizei i, offset = 0;\r
+\r
+ strings = (char **) _mesa_malloc (impl->_obj.offset_count * sizeof (char *));\r
+ if (strings == NULL)\r
+ return;\r
+\r
+ for (i = 0; i < impl->_obj.offset_count; i++)\r
+ {\r
+ GLsizei size = impl->_obj.offsets[i] - offset;\r
+\r
+ strings[i] = (char *) _mesa_malloc ((size + 1) * sizeof (char));\r
+ if (strings[i] == NULL)\r
+ {\r
+ GLsizei j;\r
+\r
+ for (j = 0; j < i; j++)\r
+ _mesa_free (strings[j]);\r
+ _mesa_free (strings);\r
+ return;\r
+ }\r
+\r
+ _mesa_memcpy (strings[i], impl->_obj.source + offset, size * sizeof (char));\r
+ strings[i][size] = '\0';\r
+ offset = impl->_obj.offsets[i];\r
+ }\r
+ }\r
+\r
+ /* TODO set these fields to some REAL numbers */\r
+ res.maxLights = 8;\r
+ res.maxClipPlanes = 6;\r
+ res.maxTextureUnits = 2;\r
+ res.maxTextureCoords = 2;\r
+ res.maxVertexAttribs = 8;\r
+ res.maxVertexUniformComponents = 64;\r
+ res.maxVaryingFloats = 8;\r
+ res.maxVertexTextureImageUnits = 2;\r
+ res.maxCombinedTextureImageUnits = 2;\r
+ res.maxTextureImageUnits = 2;\r
+ res.maxFragmentUniformComponents = 64;\r
+ res.maxDrawBuffers = 1;\r
+\r
+ if (ShCompile (impl->_obj._3dlabs_shhandle._obj.handle, strings, impl->_obj.offset_count,\r
+ EShOptFull, &res, 0))\r
+ impl->_obj.compile_status = GL_TRUE;\r
+\r
+ if (impl->_obj.offset_count > 1)\r
+ {\r
+ GLsizei i;\r
+\r
+ for (i = 0; i < impl->_obj.offset_count; i++)\r
+ _mesa_free (strings[i]);\r
+ _mesa_free (strings);\r
+ }\r
+\r
+ impl->_obj._generic.info_log = _mesa_strdup (ShGetInfoLog (\r
+ impl->_obj._3dlabs_shhandle._obj.handle));\r
}\r
\r
static struct gl2_shader_intf _shader_vftbl = {\r
- {\r
- {\r
- _unknown_AddRef,\r
- _unknown_Release,\r
- _shader_QueryInterface,\r
- },\r
- _generic_Delete,\r
- _shader_GetType,\r
- _generic_GetName,\r
- _generic_GetDeleteStatus,\r
- _generic_GetInfoLog,\r
- },\r
- NULL,\r
+ {\r
+ {\r
+ _unknown_AddRef,\r
+ _unknown_Release,\r
+ _shader_QueryInterface\r
+ },\r
+ _generic_Delete,\r
+ _shader_GetType,\r
+ _generic_GetName,\r
+ _generic_GetDeleteStatus,\r
+ _generic_GetInfoLog\r
+ },\r
+ NULL, /* abstract GetSubType */\r
_shader_GetCompileStatus,\r
_shader_SetSource,\r
_shader_GetSource,\r
_shader_constructor (struct gl2_shader_impl *impl)\r
{\r
_generic_constructor ((struct gl2_generic_impl *) impl);\r
+ _3dlabs_shhandle_constructor (&impl->_obj._3dlabs_shhandle, (struct gl2_unknown_intf **)\r
+ &impl->_vftbl);\r
impl->_vftbl = &_shader_vftbl;\r
impl->_obj._generic._unknown._destructor = _shader_destructor;\r
impl->_obj.compile_status = GL_FALSE;\r
struct gl2_container_obj _container;\r
GLboolean link_status;\r
GLboolean validate_status;\r
+ ShHandle linker;\r
+ ShHandle uniforms;\r
};\r
\r
struct gl2_program_impl\r
_program_destructor (struct gl2_unknown_intf **intf)\r
{\r
struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;\r
- (void) impl;\r
+\r
+ ShDestruct (impl->_obj.linker);\r
+ ShDestruct (impl->_obj.uniforms);\r
_container_destructor (intf);\r
}\r
\r
_program_Link (struct gl2_program_intf **intf)\r
{\r
struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;\r
+ ShHandle *handles;\r
+ GLuint i;\r
\r
impl->_obj.link_status = GL_FALSE;\r
_mesa_free ((void *) impl->_obj._container._generic.info_log);\r
impl->_obj._container._generic.info_log = NULL;\r
\r
- /* TODO link */\r
+ handles = (ShHandle *) _mesa_malloc (impl->_obj._container.attached_count * sizeof (ShHandle));\r
+ if (handles == NULL)\r
+ return;\r
+\r
+ for (i = 0; i < impl->_obj._container.attached_count; i++)\r
+ {\r
+ struct gl2_generic_intf **gen = impl->_obj._container.attached[i];\r
+ struct gl2_3dlabs_shhandle_intf **sh;\r
+\r
+ sh = (struct gl2_3dlabs_shhandle_intf **) (**gen)._unknown.QueryInterface (\r
+ (struct gl2_unknown_intf **) gen, UIID_3DLABS_SHHANDLE);\r
+ if (sh != NULL)\r
+ {\r
+ handles[i] = (**sh).GetShHandle (sh);\r
+ (**sh)._unknown.Release ((struct gl2_unknown_intf **) sh);\r
+ }\r
+ else\r
+ {\r
+ _mesa_free (handles);\r
+ return;\r
+ }\r
+ }\r
+\r
+ if (ShLink (impl->_obj.linker, handles, impl->_obj._container.attached_count,\r
+ impl->_obj.uniforms, NULL, NULL))\r
+ impl->_obj.link_status = GL_TRUE;\r
+\r
+ impl->_obj._container._generic.info_log = _mesa_strdup (ShGetInfoLog (impl->_obj.linker));\r
}\r
\r
static GLvoid\r
struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;\r
\r
impl->_obj.validate_status = GL_FALSE;\r
+ _mesa_free ((void *) impl->_obj._container._generic.info_log);\r
+ impl->_obj._container._generic.info_log = NULL;\r
\r
/* TODO validate */\r
}\r
{\r
_unknown_AddRef,\r
_unknown_Release,\r
- _program_QueryInterface,\r
+ _program_QueryInterface\r
},\r
_generic_Delete,\r
_program_GetType,\r
_generic_GetName,\r
_generic_GetDeleteStatus,\r
- _generic_GetInfoLog,\r
+ _generic_GetInfoLog\r
},\r
_program_Attach,\r
_container_Detach,\r
_container_GetAttachedCount,\r
- _container_GetAttached,\r
+ _container_GetAttached\r
},\r
_program_GetLinkStatus,\r
_program_GetValidateStatus,\r
impl->_obj._container._generic._unknown._destructor = _program_destructor;\r
impl->_obj.link_status = GL_FALSE;\r
impl->_obj.validate_status = GL_FALSE;\r
+ impl->_obj.linker = ShConstructLinker (EShExVertexFragment, 0);\r
+ impl->_obj.uniforms = ShConstructUniformMap ();\r
}\r
\r
struct gl2_fragment_shader_obj\r
_fragment_shader_destructor (struct gl2_unknown_intf **intf)\r
{\r
struct gl2_fragment_shader_impl *impl = (struct gl2_fragment_shader_impl *) intf;\r
+\r
(void) impl;\r
/* TODO free fragment shader data */\r
\r
{\r
_unknown_AddRef,\r
_unknown_Release,\r
- _fragment_shader_QueryInterface,\r
+ _fragment_shader_QueryInterface\r
},\r
_generic_Delete,\r
_shader_GetType,\r
_generic_GetName,\r
_generic_GetDeleteStatus,\r
- _generic_GetInfoLog,\r
+ _generic_GetInfoLog\r
},\r
_fragment_shader_GetSubType,\r
_shader_GetCompileStatus,\r
_shader_constructor ((struct gl2_shader_impl *) impl);\r
impl->_vftbl = &_fragment_shader_vftbl;\r
impl->_obj._shader._generic._unknown._destructor = _fragment_shader_destructor;\r
+ impl->_obj._shader._3dlabs_shhandle._obj.handle = ShConstructCompiler (EShLangFragment, 0);\r
}\r
\r
struct gl2_vertex_shader_obj\r
_vertex_shader_destructor (struct gl2_unknown_intf **intf)\r
{\r
struct gl2_vertex_shader_impl *impl = (struct gl2_vertex_shader_impl *) intf;\r
+\r
(void) impl;\r
/* TODO free vertex shader data */\r
\r
{\r
_unknown_AddRef,\r
_unknown_Release,\r
- _vertex_shader_QueryInterface,\r
+ _vertex_shader_QueryInterface\r
},\r
_generic_Delete,\r
_shader_GetType,\r
_generic_GetName,\r
_generic_GetDeleteStatus,\r
- _generic_GetInfoLog,\r
+ _generic_GetInfoLog\r
},\r
_vertex_shader_GetSubType,\r
_shader_GetCompileStatus,\r
_shader_constructor ((struct gl2_shader_impl *) impl);\r
impl->_vftbl = &_vertex_shader_vftbl;\r
impl->_obj._shader._generic._unknown._destructor = _vertex_shader_destructor;\r
+ impl->_obj._shader._3dlabs_shhandle._obj.handle = ShConstructCompiler (EShLangVertex, 0);\r
}\r
\r
GLhandleARB\r
_mesa_3dlabs_create_shader_object (GLenum shaderType)\r
{\r
- GET_CURRENT_CONTEXT(ctx);\r
- (void) ctx;\r
switch (shaderType)\r
{\r
case GL_FRAGMENT_SHADER_ARB:\r
{\r
- struct gl2_fragment_shader_impl *x = (struct gl2_fragment_shader_impl *) _mesa_malloc (\r
- sizeof (struct gl2_fragment_shader_impl));\r
+ struct gl2_fragment_shader_impl *x = (struct gl2_fragment_shader_impl *)\r
+ _mesa_malloc (sizeof (struct gl2_fragment_shader_impl));\r
\r
if (x != NULL)\r
{\r
break;\r
case GL_VERTEX_SHADER_ARB:\r
{\r
- struct gl2_vertex_shader_impl *x = (struct gl2_vertex_shader_impl *) _mesa_malloc (\r
- sizeof (struct gl2_vertex_shader_impl));\r
+ struct gl2_vertex_shader_impl *x = (struct gl2_vertex_shader_impl *)\r
+ _mesa_malloc (sizeof (struct gl2_vertex_shader_impl));\r
\r
if (x != NULL)\r
{\r
GLhandleARB\r
_mesa_3dlabs_create_program_object (void)\r
{\r
- GET_CURRENT_CONTEXT(ctx);\r
- struct gl2_program_impl *x = (struct gl2_program_impl *)\r
+ struct gl2_program_impl *x = (struct gl2_program_impl *) \r
_mesa_malloc (sizeof (struct gl2_program_impl));\r
\r
- (void) ctx;\r
if (x != NULL)\r
{\r
_program_constructor (x);\r
return 0;\r
}\r
\r
+void\r
+_mesa_init_shaderobjects_3dlabs (GLcontext *ctx)\r
+{\r
+ _glslang_3dlabs_InitProcess ();\r
+ _glslang_3dlabs_ShInitialize ();\r
+}\r
+\r