📄 shaderobjects_3dlabs.c
字号:
/*
* Mesa 3-D graphics library
* Version: 6.3
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* \file shaderobjects_3dlabs.c
* shader objects definitions for 3dlabs compiler
* \author Michal Krol
*/
/* Set this to 1 when we are ready to use 3dlabs' front-end */
#define USE_3DLABS_FRONTEND 0
#include "glheader.h"
#include "shaderobjects.h"
#include "shaderobjects_3dlabs.h"
#include "context.h"
#include "macros.h"
#include "hash.h"
#if USE_3DLABS_FRONTEND
#include "slang_mesa.h"
#include "Public/ShaderLang.h"
#else
#include "slang_compile.h"
#endif
struct gl2_unknown_obj
{
GLuint reference_count;
void (* _destructor) (struct gl2_unknown_intf **);
};
struct gl2_unknown_impl
{
struct gl2_unknown_intf *_vftbl;
struct gl2_unknown_obj _obj;
};
static void
_unknown_destructor (struct gl2_unknown_intf **intf)
{
}
static void
_unknown_AddRef (struct gl2_unknown_intf **intf)
{
struct gl2_unknown_impl *impl = (struct gl2_unknown_impl *) intf;
impl->_obj.reference_count++;
}
static void
_unknown_Release (struct gl2_unknown_intf **intf)
{
struct gl2_unknown_impl *impl = (struct gl2_unknown_impl *) intf;
impl->_obj.reference_count--;
if (impl->_obj.reference_count == 0)
{
impl->_obj._destructor (intf);
_mesa_free ((void *) intf);
}
}
static struct gl2_unknown_intf **
_unknown_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
{
if (uiid == UIID_UNKNOWN)
{
(**intf).AddRef (intf);
return intf;
}
return NULL;
}
static struct gl2_unknown_intf _unknown_vftbl = {
_unknown_AddRef,
_unknown_Release,
_unknown_QueryInterface
};
static void
_unknown_constructor (struct gl2_unknown_impl *impl)
{
impl->_vftbl = &_unknown_vftbl;
impl->_obj.reference_count = 1;
impl->_obj._destructor = _unknown_destructor;
}
struct gl2_unkinner_obj
{
struct gl2_unknown_intf **unkouter;
};
struct gl2_unkinner_impl
{
struct gl2_unknown_intf *_vftbl;
struct gl2_unkinner_obj _obj;
};
static void
_unkinner_destructor (struct gl2_unknown_intf **intf)
{
}
static void
_unkinner_AddRef (struct gl2_unknown_intf **intf)
{
struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
(**impl->_obj.unkouter).AddRef (impl->_obj.unkouter);
}
static void
_unkinner_Release (struct gl2_unknown_intf **intf)
{
struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
(**impl->_obj.unkouter).Release (impl->_obj.unkouter);
}
static struct gl2_unknown_intf **
_unkinner_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
{
struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
return (**impl->_obj.unkouter).QueryInterface (impl->_obj.unkouter, uiid);
}
static struct gl2_unknown_intf _unkinner_vftbl = {
_unkinner_AddRef,
_unkinner_Release,
_unkinner_QueryInterface
};
static void
_unkinner_constructor (struct gl2_unkinner_impl *impl, struct gl2_unknown_intf **outer)
{
impl->_vftbl = &_unkinner_vftbl;
impl->_obj.unkouter = outer;
}
struct gl2_generic_obj
{
struct gl2_unknown_obj _unknown;
GLhandleARB name;
GLboolean delete_status;
GLcharARB *info_log;
};
struct gl2_generic_impl
{
struct gl2_generic_intf *_vftbl;
struct gl2_generic_obj _obj;
};
static void
_generic_destructor (struct gl2_unknown_intf **intf)
{
GET_CURRENT_CONTEXT(ctx);
struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
_mesa_free ((void *) impl->_obj.info_log);
_glthread_LOCK_MUTEX (ctx->Shared->Mutex);
_mesa_HashRemove (ctx->Shared->GL2Objects, impl->_obj.name);
_glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
_unknown_destructor (intf);
}
static struct gl2_unknown_intf **
_generic_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
{
if (uiid == UIID_GENERIC)
{
(**intf).AddRef (intf);
return intf;
}
return _unknown_QueryInterface (intf, uiid);
}
static void
_generic_Delete (struct gl2_generic_intf **intf)
{
struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
if (impl->_obj.delete_status == GL_FALSE)
{
impl->_obj.delete_status = GL_TRUE;
(**intf)._unknown.Release ((struct gl2_unknown_intf **) intf);
}
}
static GLhandleARB
_generic_GetName (struct gl2_generic_intf **intf)
{
struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
return impl->_obj.name;
}
static GLboolean
_generic_GetDeleteStatus (struct gl2_generic_intf **intf)
{
struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
return impl->_obj.delete_status;
}
static const GLcharARB *
_generic_GetInfoLog (struct gl2_generic_intf **intf)
{
struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
return impl->_obj.info_log;
}
static struct gl2_generic_intf _generic_vftbl = {
{
_unknown_AddRef,
_unknown_Release,
_generic_QueryInterface
},
_generic_Delete,
NULL, /* abstract GetType */
_generic_GetName,
_generic_GetDeleteStatus,
_generic_GetInfoLog
};
static void
_generic_constructor (struct gl2_generic_impl *impl)
{
GET_CURRENT_CONTEXT(ctx);
_unknown_constructor ((struct gl2_unknown_impl *) impl);
impl->_vftbl = &_generic_vftbl;
impl->_obj._unknown._destructor = _generic_destructor;
impl->_obj.delete_status = GL_FALSE;
impl->_obj.info_log = NULL;
_glthread_LOCK_MUTEX (ctx->Shared->Mutex);
impl->_obj.name = _mesa_HashFindFreeKeyBlock (ctx->Shared->GL2Objects, 1);
_mesa_HashInsert (ctx->Shared->GL2Objects, impl->_obj.name, (void *) impl);
_glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
}
struct gl2_container_obj
{
struct gl2_generic_obj _generic;
struct gl2_generic_intf ***attached;
GLuint attached_count;
};
struct gl2_container_impl
{
struct gl2_container_intf *_vftbl;
struct gl2_container_obj _obj;
};
static void
_container_destructor (struct gl2_unknown_intf **intf)
{
struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
GLuint i;
for (i = 0; i < impl->_obj.attached_count; i++)
{
struct gl2_generic_intf **x = impl->_obj.attached[i];
(**x)._unknown.Release ((struct gl2_unknown_intf **) x);
}
_generic_destructor (intf);
}
static struct gl2_unknown_intf **
_container_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
{
if (uiid == UIID_CONTAINER)
{
(**intf).AddRef (intf);
return intf;
}
return _generic_QueryInterface (intf, uiid);
}
static GLboolean
_container_Attach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
{
GET_CURRENT_CONTEXT(ctx);
struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
GLuint i;
for (i = 0; i < impl->_obj.attached_count; i++)
if (impl->_obj.attached[i] == att)
{
_mesa_error (ctx, GL_INVALID_OPERATION, "_container_Attach");
return GL_FALSE;
}
impl->_obj.attached = (struct gl2_generic_intf ***) _mesa_realloc (impl->_obj.attached,
impl->_obj.attached_count * sizeof (*impl->_obj.attached), (impl->_obj.attached_count + 1) *
sizeof (*impl->_obj.attached));
if (impl->_obj.attached == NULL)
return GL_FALSE;
impl->_obj.attached[impl->_obj.attached_count] = att;
impl->_obj.attached_count++;
(**att)._unknown.AddRef ((struct gl2_unknown_intf **) att);
return GL_TRUE;
}
static GLboolean
_container_Detach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
{
GET_CURRENT_CONTEXT(ctx);
struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
GLuint i, j;
for (i = 0; i < impl->_obj.attached_count; i++)
if (impl->_obj.attached[i] == att)
{
for (j = i; j < impl->_obj.attached_count - 1; j++)
impl->_obj.attached[j] = impl->_obj.attached[j + 1];
impl->_obj.attached = (struct gl2_generic_intf ***) _mesa_realloc (impl->_obj.attached,
impl->_obj.attached_count * sizeof (*impl->_obj.attached),
(impl->_obj.attached_count - 1) * sizeof (*impl->_obj.attached));
impl->_obj.attached_count--;
(**att)._unknown.Release ((struct gl2_unknown_intf **) att);
return GL_TRUE;
}
_mesa_error (ctx, GL_INVALID_OPERATION, "_container_Detach");
return GL_FALSE;
}
static GLsizei
_container_GetAttachedCount (struct gl2_container_intf **intf)
{
struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
return impl->_obj.attached_count;
}
static struct gl2_generic_intf **
_container_GetAttached (struct gl2_container_intf **intf, GLuint index)
{
struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
(**impl->_obj.attached[index])._unknown.AddRef (
(struct gl2_unknown_intf **)impl->_obj.attached[index]);
return impl->_obj.attached[index];
}
static struct gl2_container_intf _container_vftbl = {
{
{
_unknown_AddRef,
_unknown_Release,
_container_QueryInterface
},
_generic_Delete,
NULL, /* abstract GetType */
_generic_GetName,
_generic_GetDeleteStatus,
_generic_GetInfoLog
},
_container_Attach,
_container_Detach,
_container_GetAttachedCount,
_container_GetAttached
};
static void
_container_constructor (struct gl2_container_impl *impl)
{
_generic_constructor ((struct gl2_generic_impl *) impl);
impl->_vftbl = &_container_vftbl;
impl->_obj._generic._unknown._destructor = _container_destructor;
impl->_obj.attached = NULL;
impl->_obj.attached_count = 0;
}
struct gl2_3dlabs_shhandle_obj
{
struct gl2_unkinner_obj _unknown;
#if USE_3DLABS_FRONTEND
ShHandle handle;
#endif
};
struct gl2_3dlabs_shhandle_impl
{
struct gl2_3dlabs_shhandle_intf *_vftbl;
struct gl2_3dlabs_shhandle_obj _obj;
};
static void
_3dlabs_shhandle_destructor (struct gl2_unknown_intf **intf)
{
#if USE_3DLABS_FRONTEND
struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;
ShDestruct (impl->_obj.handle);
#endif
_unkinner_destructor (intf);
}
static GLvoid *
_3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf **intf)
{
#if USE_3DLABS_FRONTEND
struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;
return impl->_obj.handle;
#else
return NULL;
#endif
}
static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl = {
{
_unkinner_AddRef,
_unkinner_Release,
_unkinner_QueryInterface
},
_3dlabs_shhandle_GetShHandle
};
static void
_3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl *impl, struct gl2_unknown_intf **outer)
{
_unkinner_constructor ((struct gl2_unkinner_impl *) impl, outer);
impl->_vftbl = &_3dlabs_shhandle_vftbl;
#if USE_3DLABS_FRONTEND
impl->_obj.handle = NULL;
#endif
}
struct gl2_shader_obj
{
struct gl2_generic_obj _generic;
struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle;
GLboolean compile_status;
GLcharARB *source;
GLint *offsets;
GLsizei offset_count;
};
struct gl2_shader_impl
{
struct gl2_shader_intf *_vftbl;
struct gl2_shader_obj _obj;
};
static void
_shader_destructor (struct gl2_unknown_intf **intf)
{
struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
_mesa_free ((void *) impl->_obj.source);
_mesa_free ((void *) impl->_obj.offsets);
_3dlabs_shhandle_destructor ((struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl);
_generic_destructor (intf);
}
static struct gl2_unknown_intf **
_shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
{
#if USE_3DLABS_FRONTEND
struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
#endif
if (uiid == UIID_SHADER)
{
(**intf).AddRef (intf);
return intf;
}
#if USE_3DLABS_FRONTEND
if (uiid == UIID_3DLABS_SHHANDLE)
{
(**intf).AddRef (intf);
return (struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl;
}
#endif
return _generic_QueryInterface (intf, uiid);
}
static GLenum
_shader_GetType (struct gl2_generic_intf **intf)
{
return GL_SHADER_OBJECT_ARB;
}
static GLboolean
_shader_GetCompileStatus (struct gl2_shader_intf **intf)
{
struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
return impl->_obj.compile_status;
}
static GLvoid
_shader_SetSource (struct gl2_shader_intf **intf, GLcharARB *src, GLint *off, GLsizei cnt)
{
struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -