added device driver hooks for BindProgram, NewProgram, DeleteProgram

This commit is contained in:
Brian Paul
2004-01-23 18:57:05 +00:00
parent f2ce4dc7da
commit 4d859f73fc
5 changed files with 55 additions and 18 deletions

View File

@@ -27,6 +27,7 @@
#include "imports.h" #include "imports.h"
#include "buffers.h" #include "buffers.h"
#include "context.h" #include "context.h"
#include "program.h"
#include "texformat.h" #include "texformat.h"
#include "teximage.h" #include "teximage.h"
#include "texobj.h" #include "texobj.h"
@@ -106,6 +107,11 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
/* Vertex/fragment programs */
driver->BindProgram = NULL;
driver->NewProgram = _mesa_new_program;
driver->DeleteProgram = _mesa_delete_program;
/* simple state commands */ /* simple state commands */
driver->AlphaFunc = NULL; driver->AlphaFunc = NULL;
driver->BlendColor = NULL; driver->BlendColor = NULL;

View File

@@ -6,9 +6,9 @@
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
* Version: 5.1 * Version: 6.1
* *
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@@ -827,12 +827,12 @@ alloc_shared_state( GLcontext *ctx )
#endif #endif
#if FEATURE_ARB_vertex_program #if FEATURE_ARB_vertex_program
ss->DefaultVertexProgram = _mesa_alloc_program(ctx, GL_VERTEX_PROGRAM_ARB, 0); ss->DefaultVertexProgram = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
if (!ss->DefaultVertexProgram) if (!ss->DefaultVertexProgram)
goto cleanup; goto cleanup;
#endif #endif
#if FEATURE_ARB_fragment_program #if FEATURE_ARB_fragment_program
ss->DefaultFragmentProgram = _mesa_alloc_program(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); ss->DefaultFragmentProgram = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
if (!ss->DefaultFragmentProgram) if (!ss->DefaultFragmentProgram)
goto cleanup; goto cleanup;
#endif #endif
@@ -880,11 +880,11 @@ alloc_shared_state( GLcontext *ctx )
#endif #endif
#if FEATURE_ARB_vertex_program #if FEATURE_ARB_vertex_program
if (ss->DefaultVertexProgram) if (ss->DefaultVertexProgram)
_mesa_delete_program(ctx, ss->DefaultVertexProgram); ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram);
#endif #endif
#if FEATURE_ARB_fragment_program #if FEATURE_ARB_fragment_program
if (ss->DefaultFragmentProgram) if (ss->DefaultFragmentProgram)
_mesa_delete_program(ctx, ss->DefaultFragmentProgram); ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram);
#endif #endif
if (ss->BufferObjects) if (ss->BufferObjects)
_mesa_DeleteHashTable(ss->BufferObjects); _mesa_DeleteHashTable(ss->BufferObjects);
@@ -956,7 +956,7 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
struct program *p = (struct program *) _mesa_HashLookup(ss->Programs, struct program *p = (struct program *) _mesa_HashLookup(ss->Programs,
prog); prog);
ASSERT(p); ASSERT(p);
_mesa_delete_program(ctx, p); ctx->Driver.DeleteProgram(ctx, p);
_mesa_HashRemove(ss->Programs, prog); _mesa_HashRemove(ss->Programs, prog);
} }
else { else {
@@ -974,7 +974,11 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
} }
static void _mesa_init_current( GLcontext *ctx ) /**
* Initialize fields of gl_current_attrib (aka ctx->Current.*)
*/
static void
_mesa_init_current( GLcontext *ctx )
{ {
int i; int i;
@@ -995,6 +999,11 @@ static void _mesa_init_current( GLcontext *ctx )
} }
/**
* Initialize fields of gl_constants (aka ctx->Const.*).
* Use defaults from config.h. The device drivers will often override
* some of these values (such as number of texture units).
*/
static void static void
_mesa_init_constants( GLcontext *ctx ) _mesa_init_constants( GLcontext *ctx )
{ {
@@ -1067,6 +1076,7 @@ _mesa_init_constants( GLcontext *ctx )
ASSERT(ctx->Const.MaxTextureUnits == MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits)); ASSERT(ctx->Const.MaxTextureUnits == MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits));
} }
/** /**
* Initialize the attribute groups in a GL context. * Initialize the attribute groups in a GL context.
* *
@@ -1510,14 +1520,14 @@ _mesa_free_context_data( GLcontext *ctx )
if (ctx->VertexProgram.Current) { if (ctx->VertexProgram.Current) {
ctx->VertexProgram.Current->Base.RefCount--; ctx->VertexProgram.Current->Base.RefCount--;
if (ctx->VertexProgram.Current->Base.RefCount <= 0) if (ctx->VertexProgram.Current->Base.RefCount <= 0)
_mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base)); ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
} }
#endif #endif
#if FEATURE_NV_fragment_program #if FEATURE_NV_fragment_program
if (ctx->FragmentProgram.Current) { if (ctx->FragmentProgram.Current) {
ctx->FragmentProgram.Current->Base.RefCount--; ctx->FragmentProgram.Current->Base.RefCount--;
if (ctx->FragmentProgram.Current->Base.RefCount <= 0) if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
_mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base)); ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
} }
#endif #endif

View File

@@ -563,6 +563,19 @@ struct dd_function_table {
/*@}*/ /*@}*/
/**
* \name Vertex/fragment program functions
*/
/*@{*/
/** Bind a vertex/fragment program */
void (*BindProgram)(GLcontext *ctx, GLenum target, struct program *prog);
/** Allocate a new program */
struct program * (*NewProgram)(GLcontext *ctx, GLenum target, GLuint id);
/** Delete a program */
void (*DeleteProgram)(GLcontext *ctx, struct program *prog);
/*@}*/
/** /**
* \name State-changing functions. * \name State-changing functions.
* *

View File

@@ -140,14 +140,17 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
/** /**
* Allocate and initialize a new fragment/vertex program object * Allocate and initialize a new fragment/vertex program object but don't
* put it into the program hash table.
* Called via ctx->Driver.NewProgram. May be wrapped (OO deriviation)
* by a device driver function.
* \param ctx context * \param ctx context
* \param id program id/number * \param id program id/number
* \param target program target/type * \param target program target/type
* \return pointer to new program object * \return pointer to new program object
*/ */
struct program * struct program *
_mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id) _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id)
{ {
struct program *prog; struct program *prog;
@@ -168,7 +171,7 @@ _mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id)
prog = &(fprog->Base); prog = &(fprog->Base);
} }
else { else {
_mesa_problem(ctx, "bad target in _mesa_alloc_program"); _mesa_problem(ctx, "bad target in _mesa_new_program");
return NULL; return NULL;
} }
prog->Id = id; prog->Id = id;
@@ -182,6 +185,8 @@ _mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id)
/** /**
* Delete a program and remove it from the hash table, ignoring the * Delete a program and remove it from the hash table, ignoring the
* reference count. * reference count.
* Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation)
* by a device driver function.
*/ */
void void
_mesa_delete_program(GLcontext *ctx, struct program *prog) _mesa_delete_program(GLcontext *ctx, struct program *prog)
@@ -812,7 +817,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
ctx->VertexProgram.Current->Base.RefCount--; ctx->VertexProgram.Current->Base.RefCount--;
/* and delete if refcount goes below one */ /* and delete if refcount goes below one */
if (ctx->VertexProgram.Current->Base.RefCount <= 0) { if (ctx->VertexProgram.Current->Base.RefCount <= 0) {
_mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base)); ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
_mesa_HashRemove(ctx->Shared->Programs, id); _mesa_HashRemove(ctx->Shared->Programs, id);
} }
} }
@@ -829,7 +834,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
ctx->FragmentProgram.Current->Base.RefCount--; ctx->FragmentProgram.Current->Base.RefCount--;
/* and delete if refcount goes below one */ /* and delete if refcount goes below one */
if (ctx->FragmentProgram.Current->Base.RefCount <= 0) { if (ctx->FragmentProgram.Current->Base.RefCount <= 0) {
_mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base)); ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
_mesa_HashRemove(ctx->Shared->Programs, id); _mesa_HashRemove(ctx->Shared->Programs, id);
} }
} }
@@ -865,7 +870,7 @@ _mesa_BindProgram(GLenum target, GLuint id)
} }
else { else {
/* allocate a new program now */ /* allocate a new program now */
prog = _mesa_alloc_program(ctx, target, id); prog = ctx->Driver.NewProgram(ctx, target, id);
if (!prog) { if (!prog) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB"); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
return; return;
@@ -888,6 +893,9 @@ _mesa_BindProgram(GLenum target, GLuint id)
if (prog) if (prog)
prog->RefCount++; prog->RefCount++;
if (ctx->Driver.BindProgram)
ctx->Driver.BindProgram(ctx, target, prog);
} }
@@ -935,7 +943,7 @@ _mesa_DeletePrograms(GLsizei n, const GLuint *ids)
} }
prog->RefCount--; prog->RefCount--;
if (prog->RefCount <= 0) { if (prog->RefCount <= 0) {
_mesa_delete_program(ctx, prog); ctx->Driver.DeleteProgram(ctx, prog);
} }
} }
} }

View File

@@ -59,7 +59,7 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
GLint *line, GLint *col); GLint *line, GLint *col);
extern struct program * extern struct program *
_mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id); _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id);
extern void extern void
_mesa_delete_program(GLcontext *ctx, struct program *prog); _mesa_delete_program(GLcontext *ctx, struct program *prog);