From 0fbe828c1d2a7e7d9155a3ef64e91da4ec2b79ee Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Dec 2009 14:47:06 -0700 Subject: mesa: _mesa_Begin/EndConditionalRender() functions For GL_NV_conditional_render and GL3. The drawing functions don't check the query object yet. No API dispatch yet. --- src/mesa/main/condrender.c | 143 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/mesa/main/condrender.c (limited to 'src/mesa/main/condrender.c') diff --git a/src/mesa/main/condrender.c b/src/mesa/main/condrender.c new file mode 100644 index 0000000000..52762133a0 --- /dev/null +++ b/src/mesa/main/condrender.c @@ -0,0 +1,143 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009 VMware, Inc. 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 (including the next + * paragraph) 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 + * THE AUTHORS OR COPYRIGHT HOLDERS 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 condrender.c + * Conditional rendering functions + * + * \author Brian Paul + */ + +#include "glheader.h" +#include "condrender.h" +#include "enums.h" +#include "queryobj.h" + + +GLAPI void GLAPIENTRY +_mesa_BeginConditionalRender(GLuint queryId, GLenum mode) +{ + struct gl_query_object *q; + GET_CURRENT_CONTEXT(ctx); + + if (ctx->Query.CondRenderQuery) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginConditionalRender()"); + return; + } + + ASSERT(ctx->Query.CondRenderMode == GL_NONE); + + switch (mode) { + case GL_QUERY_WAIT: + case GL_QUERY_NO_WAIT: + case GL_QUERY_BY_REGION_WAIT: + case GL_QUERY_BY_REGION_NO_WAIT: + /* OK */ + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glBeginConditionalRender(mode=%s)", + _mesa_lookup_enum_by_nr(mode)); + return; + } + + q = _mesa_lookup_query_object(ctx, queryId); + if (!q) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glBeginConditionalRender(bad queryId=%u)", queryId); + return; + } + ASSERT(q->Id == queryId); + + if (q->Target != GL_SAMPLES_PASSED) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginConditionalRender()"); + return; + } + + ctx->Query.CondRenderQuery = q; + ctx->Query.CondRenderMode = mode; + + if (ctx->Driver.BeginConditionalRender) + ctx->Driver.BeginConditionalRender(ctx, q, mode); +} + + +GLAPI void APIENTRY +_mesa_EndConditionalRender(void) +{ + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->Query.CondRenderQuery) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glEndConditionalRender()"); + return; + } + + if (ctx->Driver.EndConditionalRender) + ctx->Driver.EndConditionalRender(ctx, ctx->Query.CondRenderQuery); + + ctx->Query.CondRenderQuery = NULL; + ctx->Query.CondRenderMode = GL_NONE; +} + + +/** + * This function is called by software rendering commands to determine if + * subsequent drawing commands should be executed or discarded depending + * on the current conditional rendering state. + * Ideally, this check would be implemented by the GPU when doing hardware + * rendering. + * XXX should this function be called via a new driver hook? + * + * \return GL_TRUE if we should render, GL_FALSE if we should discard + */ +GLboolean +_mesa_check_conditional_render(GLcontext *ctx) +{ + struct gl_query_object *q = ctx->Query.CondRenderQuery; + + if (!q) { + /* no query in progress - draw normally */ + return GL_TRUE; + } + + switch (ctx->Query.CondRenderMode) { + case GL_QUERY_BY_REGION_WAIT: + /* fall-through */ + case GL_QUERY_WAIT: + if (!q->Ready) { + ctx->Driver.WaitQuery(ctx, q); + } + return q->Result > 0; + case GL_QUERY_BY_REGION_NO_WAIT: + /* fall-through */ + case GL_QUERY_NO_WAIT: + return q->Ready ? (q->Result > 0) : GL_TRUE; + default: + _mesa_problem(ctx, "Bad cond render mode %s in " + " _mesa_check_conditional_render()", + _mesa_lookup_enum_by_nr(ctx->Query.CondRenderMode)); + return GL_TRUE; + } +} -- cgit v1.2.3 From 2be0d77a97cbe92f09dd97fb85a3d5372e52ad4c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Dec 2009 14:49:49 -0700 Subject: mesa: add flag for GL_NV_conditional_render extension --- src/mesa/main/condrender.c | 4 ++-- src/mesa/main/extensions.c | 1 + src/mesa/main/mtypes.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/mesa/main/condrender.c') diff --git a/src/mesa/main/condrender.c b/src/mesa/main/condrender.c index 52762133a0..4e1989c869 100644 --- a/src/mesa/main/condrender.c +++ b/src/mesa/main/condrender.c @@ -43,7 +43,7 @@ _mesa_BeginConditionalRender(GLuint queryId, GLenum mode) struct gl_query_object *q; GET_CURRENT_CONTEXT(ctx); - if (ctx->Query.CondRenderQuery) { + if (!ctx->Extensions.NV_conditional_render || ctx->Query.CondRenderQuery) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginConditionalRender()"); return; } @@ -89,7 +89,7 @@ _mesa_EndConditionalRender(void) { GET_CURRENT_CONTEXT(ctx); - if (!ctx->Query.CondRenderQuery) { + if (!ctx->Extensions.NV_conditional_render || !ctx->Query.CondRenderQuery) { _mesa_error(ctx, GL_INVALID_OPERATION, "glEndConditionalRender()"); return; } diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 7aec95f048..1ccbe13d65 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -167,6 +167,7 @@ static const struct { { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) }, { ON, "GL_MESA_window_pos", F(ARB_window_pos) }, { OFF, "GL_NV_blend_square", F(NV_blend_square) }, + { OFF, "GL_NV_conditional_render", F(NV_conditional_render) }, { OFF, "GL_NV_depth_clamp", F(ARB_depth_clamp) }, { OFF, "GL_NV_fragment_program", F(NV_fragment_program) }, { OFF, "GL_NV_fragment_program_option", F(NV_fragment_program_option) }, diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 1a7f87897a..a7f70a1875 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2496,6 +2496,7 @@ struct gl_extensions GLboolean MESA_texture_array; GLboolean MESA_texture_signed_rgba; GLboolean NV_blend_square; + GLboolean NV_conditional_render; GLboolean NV_fragment_program; GLboolean NV_fragment_program_option; GLboolean NV_light_max_exponent; -- cgit v1.2.3 From 5a0eb89da56aeaded17fee213bb4f00607b13a5c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Dec 2009 21:37:54 -0700 Subject: mesa: added FLUSH_VERTICES(), more comments --- src/mesa/main/condrender.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/mesa/main/condrender.c') diff --git a/src/mesa/main/condrender.c b/src/mesa/main/condrender.c index 4e1989c869..c292b8a04c 100644 --- a/src/mesa/main/condrender.c +++ b/src/mesa/main/condrender.c @@ -89,6 +89,8 @@ _mesa_EndConditionalRender(void) { GET_CURRENT_CONTEXT(ctx); + FLUSH_VERTICES(ctx, 0x0); + if (!ctx->Extensions.NV_conditional_render || !ctx->Query.CondRenderQuery) { _mesa_error(ctx, GL_INVALID_OPERATION, "glEndConditionalRender()"); return; @@ -103,12 +105,14 @@ _mesa_EndConditionalRender(void) /** - * This function is called by software rendering commands to determine if - * subsequent drawing commands should be executed or discarded depending - * on the current conditional rendering state. - * Ideally, this check would be implemented by the GPU when doing hardware - * rendering. - * XXX should this function be called via a new driver hook? + * This function is called by software rendering commands (all point, + * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and + * glBitmap, glBlitFramebuffer) to determine if subsequent drawing + * commands should be + * executed or discarded depending on the current conditional + * rendering state. Ideally, this check would be implemented by the + * GPU when doing hardware rendering. XXX should this function be + * called via a new driver hook? * * \return GL_TRUE if we should render, GL_FALSE if we should discard */ -- cgit v1.2.3 From 04c7f483b438deffe7cfa1883d0c30616257e2d0 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 1 Jan 2010 11:20:38 +0000 Subject: mesa: Make condrender.[ch] prototypes match. GLAPI on windows is more than "extern" -- it includes the --, so the mismatch between condrender.[ch] prototypes causes "different linkage" errors on windows. --- src/mesa/main/condrender.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/main/condrender.c') diff --git a/src/mesa/main/condrender.c b/src/mesa/main/condrender.c index c292b8a04c..8d9a91d547 100644 --- a/src/mesa/main/condrender.c +++ b/src/mesa/main/condrender.c @@ -37,7 +37,7 @@ #include "queryobj.h" -GLAPI void GLAPIENTRY +void GLAPIENTRY _mesa_BeginConditionalRender(GLuint queryId, GLenum mode) { struct gl_query_object *q; @@ -84,7 +84,7 @@ _mesa_BeginConditionalRender(GLuint queryId, GLenum mode) } -GLAPI void APIENTRY +void APIENTRY _mesa_EndConditionalRender(void) { GET_CURRENT_CONTEXT(ctx); -- cgit v1.2.3