diff options
author | Brian Paul <[email protected]> | 2003-06-13 02:37:27 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2003-06-13 02:37:27 +0000 |
commit | b17a722ca3989e8563ee04cb2939f4835f8a171e (patch) | |
tree | 817c548199ee8e4a1ba2a0266f491b2b80b942d3 /src/mesa/main | |
parent | 0c0e583c01116c9e26ac99735e581ea2b842a88d (diff) |
Implemented GL_ARB_occlusion_query (not 100% finalized).
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/config.h | 1 | ||||
-rw-r--r-- | src/mesa/main/context.c | 4 | ||||
-rw-r--r-- | src/mesa/main/extensions.c | 4 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 15 | ||||
-rw-r--r-- | src/mesa/main/occlude.c | 314 | ||||
-rw-r--r-- | src/mesa/main/occlude.h | 55 | ||||
-rw-r--r-- | src/mesa/main/state.c | 14 |
7 files changed, 407 insertions, 0 deletions
diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h index f35f100205d..4b4b3ef10ae 100644 --- a/src/mesa/main/config.h +++ b/src/mesa/main/config.h @@ -243,5 +243,6 @@ #define FEATURE_ARB_fragment_program 1 +#define FEATURE_ARB_occlusion_query 1 #endif /* CONFIG_H */ diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index ae030bce849..666e3403a27 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1562,6 +1562,10 @@ init_attrib_groups( GLcontext *ctx ) ctx->FragmentProgram.Current->Base.RefCount++; #endif +#if FEATURE_ARB_occlusion_query + ctx->Occlusion.QueryObjects = _mesa_NewHashTable(); +#endif + /* Miscellaneous */ ctx->NewState = _NEW_ALL; ctx->RenderMode = GL_RENDER; diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 50769fed31e..3b7c21a1622 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -54,6 +54,7 @@ static const struct { { OFF, "GL_ARB_imaging", F(ARB_imaging) }, { OFF, "GL_ARB_multisample", F(ARB_multisample) }, { OFF, "GL_ARB_multitexture", F(ARB_multitexture) }, + { OFF, "GL_ARB_occlusion_query", F(ARB_occlusion_query) }, { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) }, { OFF, "GL_ARB_shadow", F(ARB_shadow) }, { OFF, "GL_ARB_shadow_ambient", F(SGIX_shadow_ambient) }, @@ -163,6 +164,9 @@ _mesa_enable_sw_extensions(GLcontext *ctx) #endif "GL_ARB_imaging", "GL_ARB_multitexture", +#if FEATURE_ARB_occlusion_query + "GL_ARB_occlusion_query", +#endif "GL_ARB_point_parameters", "GL_ARB_shadow", "GL_ARB_shadow_ambient", diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index dd660fa3abd..59a75da8c88 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1315,6 +1315,18 @@ struct fragment_program_state /* + * State for GL_ARB_occlusion_query + */ +struct occlusion_state +{ + GLboolean Active; + GLuint CurrentQueryObject; + GLuint PassedCounter; + struct _mesa_HashTable *QueryObjects; +}; + + +/* * State which can be shared by multiple contexts: */ struct gl_shared_state { @@ -1449,6 +1461,7 @@ struct gl_extensions { GLboolean ARB_imaging; GLboolean ARB_multisample; GLboolean ARB_multitexture; + GLboolean ARB_occlusion_query; GLboolean ARB_shadow; GLboolean ARB_texture_border_clamp; GLboolean ARB_texture_compression; @@ -1827,6 +1840,8 @@ struct __GLcontextRec { struct vertex_program_state VertexProgram; /* GL_NV_vertex_program */ struct fragment_program_state FragmentProgram; /* GL_NV_fragment_program */ + struct occlusion_state Occlusion; /* GL_ARB_occlusion_query */ + GLenum ErrorValue; /* Last error code */ GLenum RenderMode; /* either GL_RENDER, GL_SELECT, GL_FEEDBACK */ GLuint NewState; /* bitwise-or of _NEW_* flags */ diff --git a/src/mesa/main/occlude.c b/src/mesa/main/occlude.c new file mode 100644 index 00000000000..029e5d08946 --- /dev/null +++ b/src/mesa/main/occlude.c @@ -0,0 +1,314 @@ +/* + * Mesa 3-D graphics library + * Version: 5.1 + * + * Copyright (C) 1999-2003 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. + */ + + +/* + * \brief Functions to implement the GL_ARB_occlusion_query extension. + */ + + +#include "glheader.h" +#include "context.h" +#include "hash.h" +#include "imports.h" +#include "occlude.h" +#include "mtypes.h" + +#ifndef GL_SAMPLES_PASSED_ARB +#define GL_SAMPLES_PASSED_ARB 0x8914 +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#endif + + +struct occlusion_query +{ + GLenum Target; + GLuint Id; + GLuint PassedCounter; + GLboolean Active; +}; + + +/** + * Allocate a new occlusion query object. + * \param target - must be GL_SAMPLES_PASSED_ARB at this time + * \param id - the object's ID + * \return pointer to new occlusion_query object or NULL if out of memory. + */ +static struct occlusion_query * +new_query_object(GLenum target, GLuint id) +{ + struct occlusion_query *q = MALLOC_STRUCT(occlusion_query); + if (q) { + q->Target = target; + q->Id = id; + q->PassedCounter = 0; + q->Active = GL_FALSE; + } + return q; +} + + +/** + * Delete an occlusion query object. + */ +static void +delete_query_object(struct occlusion_query *q) +{ + FREE(q); +} + + +void +_mesa_GenQueriesARB(GLsizei n, GLuint *ids) +{ + GET_CURRENT_CONTEXT(ctx); + GLuint first; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (n < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glGenQueriesARB(n < 0)"); + return; + } + + if (ctx->Occlusion.Active) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glGenQueriesARB"); + return; + } + + first = _mesa_HashFindFreeKeyBlock(ctx->Occlusion.QueryObjects, n); + if (first) { + GLuint i; + for (i = 0; i < n; i++) { + struct occlusion_query *q = new_query_object(GL_SAMPLES_PASSED_ARB, + first + i); + if (!q) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenQueriesARB"); + return; + } + ids[i] = first + i; + _mesa_HashInsert(ctx->Occlusion.QueryObjects, first + i, q); + } + } +} + + +void +_mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (n < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteQueriesARB(n < 0)"); + return; + } + + if (ctx->Occlusion.Active) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteQueriesARB"); + return; + } + + for (i = 0; i < n; i++) { + if (ids[i] > 0) { + struct occlusion_query *q = (struct occlusion_query *) + _mesa_HashLookup(ctx->Occlusion.QueryObjects, ids[i]); + if (q) { + _mesa_HashRemove(ctx->Occlusion.QueryObjects, ids[i]); + delete_query_object(q); + } + } + } +} + + +GLboolean +_mesa_IsQueryARB(GLuint id) +{ + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); + + if (id && _mesa_HashLookup(ctx->Occlusion.QueryObjects, id)) + return GL_TRUE; + else + return GL_FALSE; +} + + +void +_mesa_BeginQueryARB(GLenum target, GLuint id) +{ + GET_CURRENT_CONTEXT(ctx); + struct occlusion_query *q; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + FLUSH_VERTICES(ctx, _NEW_DEPTH); + + if (target != GL_SAMPLES_PASSED_ARB) { + _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)"); + return; + } + + if (ctx->Occlusion.CurrentQueryObject) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB(target)"); + return; + } + + q = (struct occlusion_query *) + _mesa_HashLookup(ctx->Occlusion.QueryObjects, id); + if (q && q->Active) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB"); + return; + } + else if (!q) { + q = new_query_object(target, id); + if (!q) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQueryARB"); + return; + } + _mesa_HashInsert(ctx->Occlusion.QueryObjects, id, q); + } + + q->Active = GL_TRUE; + q->PassedCounter = 0; + ctx->Occlusion.Active = GL_TRUE; + ctx->Occlusion.CurrentQueryObject = id; + ctx->Occlusion.PassedCounter = 0; +} + + +void +_mesa_EndQueryARB(GLenum target) +{ + GET_CURRENT_CONTEXT(ctx); + struct occlusion_query *q; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + FLUSH_VERTICES(ctx, _NEW_DEPTH); + + if (target != GL_SAMPLES_PASSED_ARB) { + _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)"); + return; + } + + q = (struct occlusion_query *) + _mesa_HashLookup(ctx->Occlusion.QueryObjects, + ctx->Occlusion.CurrentQueryObject); + if (!q || !q->Active) { + _mesa_problem(ctx, "bad query object in glEndQueryARB"); + return; + } + + q->PassedCounter = ctx->Occlusion.PassedCounter; + q->Active = GL_FALSE; + ctx->Occlusion.Active = GL_FALSE; + ctx->Occlusion.CurrentQueryObject = 0; +} + + +void +_mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params) +{ + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (target != GL_SAMPLES_PASSED_ARB) { + _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivARB(target)"); + return; + } + + switch (pname) { + case GL_QUERY_COUNTER_BITS_ARB: + *params = 8 * sizeof(GLuint); + break; + case GL_CURRENT_QUERY_ARB: + *params = ctx->Occlusion.CurrentQueryObject; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivARB(pname)"); + return; + } +} + + +void +_mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params) +{ + GET_CURRENT_CONTEXT(ctx); + struct occlusion_query *q; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + q = (struct occlusion_query *) + _mesa_HashLookup(ctx->Occlusion.QueryObjects, id); + if (!q || q->Active) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glGetQueryObjectivARB"); + return; + } + + switch (pname) { + case GL_QUERY_RESULT_ARB: + *params = q->PassedCounter; + break; + case GL_QUERY_RESULT_AVAILABLE_ARB: + /* XXX revisit when we have a hardware implementation! */ + *params = GL_TRUE; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectivARB(pname)"); + return; + } +} + + +void +_mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params) +{ + GET_CURRENT_CONTEXT(ctx); + struct occlusion_query *q; + ASSERT_OUTSIDE_BEGIN_END(ctx); + + q = (struct occlusion_query *) + _mesa_HashLookup(ctx->Occlusion.QueryObjects, id); + if (!q || q->Active) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glGetQueryObjectuivARB"); + return; + } + + switch (pname) { + case GL_QUERY_RESULT_ARB: + *params = q->PassedCounter; + break; + case GL_QUERY_RESULT_AVAILABLE_ARB: + /* XXX revisit when we have a hardware implementation! */ + *params = GL_TRUE; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectuivARB(pname)"); + return; + } +} diff --git a/src/mesa/main/occlude.h b/src/mesa/main/occlude.h new file mode 100644 index 00000000000..cc3786772bc --- /dev/null +++ b/src/mesa/main/occlude.h @@ -0,0 +1,55 @@ +/* + * Mesa 3-D graphics library + * Version: 5.1 + * + * Copyright (C) 1999-2003 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. + */ + + +#ifndef OCCLUDE_H +#define OCCLUDE_H + + +extern void +_mesa_GenQueriesARB(GLsizei n, GLuint *ids); + +extern void +_mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids); + +extern GLboolean +_mesa_IsQueryARB(GLuint id); + +extern void +_mesa_BeginQueryARB(GLenum target, GLuint id); + +extern void +_mesa_EndQueryARB(GLenum target); + +extern void +_mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params); + +extern void +_mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params); + +extern void +_mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params); + + +#endif /* OCCLUDE_H */ diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 63c8bc4abda..2851b8e083b 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -59,6 +59,9 @@ #include "light.h" #include "lines.h" #include "matrix.h" +#if FEATURE_ARB_occlusion_query +#include "occlude.h" +#endif #include "pixel.h" #include "points.h" #include "polygon.h" @@ -644,6 +647,17 @@ _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize) exec->MapBufferARB = _mesa_MapBufferARB; exec->UnmapBufferARB = _mesa_UnmapBufferARB; #endif + +#if FEATURE_ARB_occlusion_query + exec->GenQueriesARB = _mesa_GenQueriesARB; + exec->DeleteQueriesARB = _mesa_DeleteQueriesARB; + exec->IsQueryARB = _mesa_IsQueryARB; + exec->BeginQueryARB = _mesa_BeginQueryARB; + exec->EndQueryARB = _mesa_EndQueryARB; + exec->GetQueryivARB = _mesa_GetQueryivARB; + exec->GetQueryObjectivARB = _mesa_GetQueryObjectivARB; + exec->GetQueryObjectuivARB = _mesa_GetQueryObjectuivARB; +#endif } |