@@ -27,6 +27,7 @@ | |||
#include "imports.h" | |||
#include "buffers.h" | |||
#include "context.h" | |||
#include "program.h" | |||
#include "texformat.h" | |||
#include "teximage.h" | |||
#include "texobj.h" | |||
@@ -106,6 +107,11 @@ _mesa_init_driver_functions(struct dd_function_table *driver) | |||
driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; | |||
driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; | |||
/* Vertex/fragment programs */ | |||
driver->BindProgram = NULL; | |||
driver->NewProgram = _mesa_new_program; | |||
driver->DeleteProgram = _mesa_delete_program; | |||
/* simple state commands */ | |||
driver->AlphaFunc = NULL; | |||
driver->BlendColor = NULL; |
@@ -6,9 +6,9 @@ | |||
/* | |||
* 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 | |||
* copy of this software and associated documentation files (the "Software"), | |||
@@ -827,12 +827,12 @@ alloc_shared_state( GLcontext *ctx ) | |||
#endif | |||
#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) | |||
goto cleanup; | |||
#endif | |||
#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) | |||
goto cleanup; | |||
#endif | |||
@@ -880,11 +880,11 @@ alloc_shared_state( GLcontext *ctx ) | |||
#endif | |||
#if FEATURE_ARB_vertex_program | |||
if (ss->DefaultVertexProgram) | |||
_mesa_delete_program(ctx, ss->DefaultVertexProgram); | |||
ctx->Driver.DeleteProgram(ctx, ss->DefaultVertexProgram); | |||
#endif | |||
#if FEATURE_ARB_fragment_program | |||
if (ss->DefaultFragmentProgram) | |||
_mesa_delete_program(ctx, ss->DefaultFragmentProgram); | |||
ctx->Driver.DeleteProgram(ctx, ss->DefaultFragmentProgram); | |||
#endif | |||
if (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, | |||
prog); | |||
ASSERT(p); | |||
_mesa_delete_program(ctx, p); | |||
ctx->Driver.DeleteProgram(ctx, p); | |||
_mesa_HashRemove(ss->Programs, prog); | |||
} | |||
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; | |||
@@ -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 | |||
_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)); | |||
} | |||
/** | |||
* Initialize the attribute groups in a GL context. | |||
* | |||
@@ -1510,14 +1520,14 @@ _mesa_free_context_data( GLcontext *ctx ) | |||
if (ctx->VertexProgram.Current) { | |||
ctx->VertexProgram.Current->Base.RefCount--; | |||
if (ctx->VertexProgram.Current->Base.RefCount <= 0) | |||
_mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base)); | |||
ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base)); | |||
} | |||
#endif | |||
#if FEATURE_NV_fragment_program | |||
if (ctx->FragmentProgram.Current) { | |||
ctx->FragmentProgram.Current->Base.RefCount--; | |||
if (ctx->FragmentProgram.Current->Base.RefCount <= 0) | |||
_mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base)); | |||
ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base)); | |||
} | |||
#endif | |||
@@ -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. | |||
* |
@@ -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 id program id/number | |||
* \param target program target/type | |||
* \return pointer to new program object | |||
*/ | |||
struct program * | |||
_mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id) | |||
_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) | |||
{ | |||
struct program *prog; | |||
@@ -168,7 +171,7 @@ _mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id) | |||
prog = &(fprog->Base); | |||
} | |||
else { | |||
_mesa_problem(ctx, "bad target in _mesa_alloc_program"); | |||
_mesa_problem(ctx, "bad target in _mesa_new_program"); | |||
return NULL; | |||
} | |||
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 | |||
* reference count. | |||
* Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation) | |||
* by a device driver function. | |||
*/ | |||
void | |||
_mesa_delete_program(GLcontext *ctx, struct program *prog) | |||
@@ -812,7 +817,7 @@ _mesa_BindProgram(GLenum target, GLuint id) | |||
ctx->VertexProgram.Current->Base.RefCount--; | |||
/* and delete if refcount goes below one */ | |||
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); | |||
} | |||
} | |||
@@ -829,7 +834,7 @@ _mesa_BindProgram(GLenum target, GLuint id) | |||
ctx->FragmentProgram.Current->Base.RefCount--; | |||
/* and delete if refcount goes below one */ | |||
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); | |||
} | |||
} | |||
@@ -865,7 +870,7 @@ _mesa_BindProgram(GLenum target, GLuint id) | |||
} | |||
else { | |||
/* allocate a new program now */ | |||
prog = _mesa_alloc_program(ctx, target, id); | |||
prog = ctx->Driver.NewProgram(ctx, target, id); | |||
if (!prog) { | |||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB"); | |||
return; | |||
@@ -888,6 +893,9 @@ _mesa_BindProgram(GLenum target, GLuint id) | |||
if (prog) | |||
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--; | |||
if (prog->RefCount <= 0) { | |||
_mesa_delete_program(ctx, prog); | |||
ctx->Driver.DeleteProgram(ctx, prog); | |||
} | |||
} | |||
} |
@@ -59,7 +59,7 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, | |||
GLint *line, GLint *col); | |||
extern struct program * | |||
_mesa_alloc_program(GLcontext *ctx, GLenum target, GLuint id); | |||
_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id); | |||
extern void | |||
_mesa_delete_program(GLcontext *ctx, struct program *prog); |