Commit 4d12a05e authored by Brian Paul's avatar Brian Paul

Added _mesa_lookup_program() and _mesa_lookup_bufferobj() functions to avoid

a lot of casting elsewhere.
Use _mesa_lookup_texture() in tdfx driver, use _mesa_lookup_bufferobj() in r300
driver.
parent 261a806f
......@@ -749,13 +749,13 @@ void r300_evict_vbos(GLcontext *ctx, int amount)
r300ContextPtr rmesa = R300_CONTEXT(ctx);
struct _mesa_HashTable *hash = ctx->Shared->BufferObjects;
GLuint k = _mesa_HashFirstEntry(hash);
struct gl_buffer_object *obj;
struct r300_buffer_object *r300_obj;
GLvoid *data;
while (amount > 0 && k) {
obj = (struct gl_buffer_object *) _mesa_HashLookup(hash, k);
r300_obj = (struct r300_buffer_object *) obj;
struct gl_buffer_object *obj = _mesa_lookup_bufferobj(ctx, k);
struct r300_buffer_object *r300_obj
= (struct r300_buffer_object *) obj;
if (obj->OnCard && obj->Size) {
obj->Data = _mesa_malloc(obj->Size);
......
......@@ -602,7 +602,7 @@ tdfxDestroyContext( __DRIcontextPrivate *driContextPriv )
id;
id = _mesa_HashNextEntry(textures, id)) {
struct gl_texture_object *tObj
= (struct gl_texture_object *) _mesa_HashLookup(textures, id);
= _mesa_lookup_texture(fxMesa->glCtx, id);
tdfxTMFreeTexture(fxMesa, tObj);
}
}
......
......@@ -38,6 +38,7 @@
#include "tdfx_context.h"
#include "tdfx_tex.h"
#include "tdfx_texman.h"
#include "texobj.h"
#include "hash.h"
......@@ -82,8 +83,8 @@ VerifyFreeList(tdfxContextPtr fxMesa, FxU32 tmu)
for (id = _mesa_HashFirstEntry(textures);
id;
id = _mesa_HashNextEntry(textures, id)) {
struct gl_texture_object *tObj;
tObj = (struct gl_texture_object *) _mesa_HashLookup(textures, id);
struct gl_texture_object *tObj
= _mesa_lookup_texture(fxMesa->glCtx, id);
tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj);
if (ti) {
if (ti->isInTM) {
......@@ -122,7 +123,7 @@ dump_texmem(tdfxContextPtr fxMesa)
id;
id = _mesa_HashNextEntry(textures, id)) {
struct gl_texture_object *obj
= (struct gl_texture_object *) _mesa_HashLookup(textures, id);
= _mesa_lookup_texture(fxMesa->glCtx, id);
tdfxTexInfo *info = TDFX_TEXTURE_DATA(obj);
if (info && info->isInTM) {
......@@ -404,7 +405,7 @@ FindOldestObject(tdfxContextPtr fxMesa, FxU32 tmu)
id;
id = _mesa_HashNextEntry(textures, id)) {
struct gl_texture_object *obj
= (struct gl_texture_object *) _mesa_HashLookup(textures, id);
= _mesa_lookup_texture(fxMesa->glCtx, id);
tdfxTexInfo *info = TDFX_TEXTURE_DATA(obj);
if (info && info->isInTM &&
......@@ -460,7 +461,7 @@ FlushTexMemory(tdfxContextPtr fxMesa)
id;
id = _mesa_HashNextEntry(textures, id)) {
struct gl_texture_object *obj
= (struct gl_texture_object *) _mesa_HashLookup(textures, id);
= _mesa_lookup_texture(fxMesa->glCtx, id);
if (obj->RefCount < 2) {
/* don't flush currently bound textures */
tdfxTMMoveOutTM_NoLock(fxMesa, obj);
......@@ -972,7 +973,7 @@ void tdfxTMRestoreTextures_NoLock( tdfxContextPtr fxMesa )
id;
id = _mesa_HashNextEntry(textures, id)) {
struct gl_texture_object *tObj
= (struct gl_texture_object *) _mesa_HashLookup(textures, id);
= _mesa_lookup_texture(fxMesa->glCtx, id);
tdfxTexInfo *ti = TDFX_TEXTURE_DATA( tObj );
if ( ti && ti->isInTM ) {
int i;
......
......@@ -469,8 +469,8 @@ _mesa_validate_pbo_access(GLuint dimensions,
* Return the gl_buffer_object for the given ID.
* Always return NULL for ID 0.
*/
static INLINE struct gl_buffer_object *
lookup_bufferobj(GLcontext *ctx, GLuint buffer)
struct gl_buffer_object *
_mesa_lookup_bufferobj(GLcontext *ctx, GLuint buffer)
{
if (buffer == 0)
return NULL;
......@@ -508,7 +508,7 @@ _mesa_BindBufferARB(GLenum target, GLuint buffer)
}
else {
/* non-default buffer object */
newBufObj = lookup_bufferobj(ctx, buffer);
newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
if (!newBufObj) {
/* if this is a new buffer object id, allocate a buffer object now */
ASSERT(ctx->Driver.NewBufferObject);
......@@ -577,7 +577,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids)
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
for (i = 0; i < n; i++) {
struct gl_buffer_object *bufObj = lookup_bufferobj(ctx, ids[i]);
struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
if (bufObj) {
/* unbind any vertex pointers bound to this buffer */
GLuint j;
......@@ -722,7 +722,7 @@ _mesa_IsBufferARB(GLuint id)
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
bufObj = lookup_bufferobj(ctx, id);
bufObj = _mesa_lookup_bufferobj(ctx, id);
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
return bufObj ? GL_TRUE : GL_FALSE;
......
......@@ -44,6 +44,9 @@ _mesa_new_buffer_object( GLcontext *ctx, GLuint name, GLenum target );
extern void
_mesa_delete_buffer_object( GLcontext *ctx, struct gl_buffer_object *bufObj );
extern struct gl_buffer_object *
_mesa_lookup_bufferobj(GLcontext *ctx, GLuint buffer);
extern void
_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
GLuint name, GLenum target );
......
......@@ -70,8 +70,7 @@ _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
vprog = (struct gl_vertex_program *)
_mesa_HashLookup(ctx->Shared->Programs, id);
vprog = (struct gl_vertex_program *) _mesa_lookup_program(ctx, id);
if (!vprog || vprog->Base.Target != GL_VERTEX_STATE_PROGRAM_NV) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glExecuteProgramNV");
......@@ -109,8 +108,7 @@ GLboolean GLAPIENTRY _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
_mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV");
return GL_FALSE;
}
prog = (const struct gl_program *)
_mesa_HashLookup(ctx->Shared->Programs, ids[i]);
prog = _mesa_lookup_program(ctx, ids[i]);
if (!prog) {
_mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV");
return GL_FALSE;
......@@ -158,7 +156,7 @@ _mesa_RequestResidentProgramsNV(GLsizei n, const GLuint *ids)
return;
}
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
prog = _mesa_lookup_program(ctx, ids[i]);
if (!prog) {
_mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
return;
......@@ -254,7 +252,7 @@ _mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
if (!ctx->_CurrentProgram)
ASSERT_OUTSIDE_BEGIN_END(ctx);
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
prog = _mesa_lookup_program(ctx, id);
if (!prog) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramivNV");
return;
......@@ -296,7 +294,7 @@ _mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
return;
}
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
prog = _mesa_lookup_program(ctx, id);
if (!prog) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramStringNV");
return;
......@@ -522,7 +520,7 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
prog = _mesa_lookup_program(ctx, id);
if (prog && prog->Target != 0 && prog->Target != target) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glLoadProgramNV(target)");
......@@ -773,7 +771,7 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
prog = _mesa_lookup_program(ctx, id);
if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glProgramNamedParameterNV");
return;
......@@ -839,7 +837,7 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
if (!ctx->_CurrentProgram)
ASSERT_OUTSIDE_BEGIN_END(ctx);
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
prog = _mesa_lookup_program(ctx, id);
if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramNamedParameterNV");
return;
......
/*
* Mesa 3-D graphics library
* Version: 6.5
* Version: 6.5.1
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
......@@ -304,6 +304,20 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog)
}
/**
* Return the gl_program object for a given ID.
* Basically just a wrapper for _mesa_HashLookup() to avoid a lot of
* casts elsewhere.
*/
struct gl_program *
_mesa_lookup_program(GLcontext *ctx, GLuint id)
{
if (id)
return (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
else
return NULL;
}
/**********************************************************************/
/* Program parameter functions */
......@@ -1753,7 +1767,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
}
else {
/* Bind user program */
prog = (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
prog = _mesa_lookup_program(ctx, id);
if (!prog || prog == &_mesa_DummyProgram) {
/* allocate a new program now */
prog = ctx->Driver.NewProgram(ctx, target, id);
......@@ -1809,8 +1823,7 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
for (i = 0; i < n; i++) {
if (ids[i] != 0) {
struct gl_program *prog = (struct gl_program *)
_mesa_HashLookup(ctx->Shared->Programs, ids[i]);
struct gl_program *prog = _mesa_lookup_program(ctx, ids[i]);
if (prog == &_mesa_DummyProgram) {
_mesa_HashRemove(ctx->Shared->Programs, ids[i]);
}
......@@ -1899,7 +1912,7 @@ _mesa_IsProgram(GLuint id)
if (id == 0)
return GL_FALSE;
if (_mesa_HashLookup(ctx->Shared->Programs, id))
if (_mesa_lookup_program(ctx, id))
return GL_TRUE;
else
return GL_FALSE;
......
/*
* Mesa 3-D graphics library
* Version: 6.5
* Version: 6.5.1
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
......@@ -111,6 +111,8 @@ _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id);
extern void
_mesa_delete_program(GLcontext *ctx, struct gl_program *prog);
extern struct gl_program *
_mesa_lookup_program(GLcontext *ctx, GLuint id);
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment