From 4f31fe77d28748e1ff8960578d0725e114159382 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 29 Mar 2006 21:02:04 +0000 Subject: [PATCH] new files --- .../src/glstuff/glOcclusionQueryContext_src.I | 29 ++++++ .../glstuff/glOcclusionQueryContext_src.cxx | 92 +++++++++++++++++++ .../src/glstuff/glOcclusionQueryContext_src.h | 59 ++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 panda/src/glstuff/glOcclusionQueryContext_src.I create mode 100644 panda/src/glstuff/glOcclusionQueryContext_src.cxx create mode 100644 panda/src/glstuff/glOcclusionQueryContext_src.h diff --git a/panda/src/glstuff/glOcclusionQueryContext_src.I b/panda/src/glstuff/glOcclusionQueryContext_src.I new file mode 100644 index 0000000000..e0734e989e --- /dev/null +++ b/panda/src/glstuff/glOcclusionQueryContext_src.I @@ -0,0 +1,29 @@ +// Filename: glOcclusionQueryContext_src.I +// Created by: drose (27Mar06) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: CLP(OcclusionQueryContext)::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CLP(OcclusionQueryContext):: +CLP(OcclusionQueryContext)(GraphicsStateGuardian *gsg) { + _index = 0; + _gsg = gsg; +} diff --git a/panda/src/glstuff/glOcclusionQueryContext_src.cxx b/panda/src/glstuff/glOcclusionQueryContext_src.cxx new file mode 100644 index 0000000000..55ee4c5efe --- /dev/null +++ b/panda/src/glstuff/glOcclusionQueryContext_src.cxx @@ -0,0 +1,92 @@ +// Filename: glOcclusionQueryContext_src.cxx +// Created by: drose (27Mar06) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "pnotify.h" +#include "dcast.h" +#include "mutexHolder.h" + +TypeHandle CLP(OcclusionQueryContext)::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: GLOcclusionQueryContext::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +CLP(OcclusionQueryContext):: +~CLP(OcclusionQueryContext)() { + if (_index != 0) { + // Tell the GSG to recycle this index when it gets around to it. + CLP(GraphicsStateGuardian) *glgsg; + DCAST_INTO_V(glgsg, _gsg); + MutexHolder holder(glgsg->_lock); + glgsg->_deleted_queries.push_back(_index); + + _index = 0; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: GLOcclusionQueryContext::is_answer_ready +// Access: Public, Virtual +// Description: Returns true if the query's answer is ready, false +// otherwise. If this returns false, the application +// must continue to poll until it returns true. +// +// It is only valid to call this from the draw thread. +//////////////////////////////////////////////////////////////////// +bool CLP(OcclusionQueryContext):: +is_answer_ready() const { + CLP(GraphicsStateGuardian) *glgsg; + DCAST_INTO_R(glgsg, _gsg, false); + GLuint result; + glgsg->_glGetQueryObjectuiv(_index, GL_QUERY_RESULT_AVAILABLE, &result); + return (result != 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: GLOcclusionQueryContext::waiting_for_answer +// Access: Public, Virtual +// Description: Requests the graphics engine to expedite the pending +// answer--the application is now waiting until the +// answer is ready. +// +// It is only valid to call this from the draw thread. +//////////////////////////////////////////////////////////////////// +void CLP(OcclusionQueryContext):: +waiting_for_answer() { + GLP(Flush)(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GLOcclusionQueryContext::get_num_fragments +// Access: Public, Virtual +// Description: Returns the number of fragments (pixels) of the +// specified geometry that passed the depth test. +// If is_answer_ready() did not return true, this +// function may block before it returns. +// +// It is only valid to call this from the draw thread. +//////////////////////////////////////////////////////////////////// +int CLP(OcclusionQueryContext):: +get_num_fragments() const { + CLP(GraphicsStateGuardian) *glgsg; + DCAST_INTO_R(glgsg, _gsg, 0); + GLuint result; + glgsg->_glGetQueryObjectuiv(_index, GL_QUERY_RESULT, &result); + return result; +} diff --git a/panda/src/glstuff/glOcclusionQueryContext_src.h b/panda/src/glstuff/glOcclusionQueryContext_src.h new file mode 100644 index 0000000000..3ae331fee7 --- /dev/null +++ b/panda/src/glstuff/glOcclusionQueryContext_src.h @@ -0,0 +1,59 @@ +// Filename: glOcclusionQueryContext_src.h +// Created by: drose (27Mar06) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "pandabase.h" +#include "occlusionQueryContext.h" + +class GraphicsStateGuardian; + +//////////////////////////////////////////////////////////////////// +// Class : GLOcclusionQueryContext +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_GL CLP(OcclusionQueryContext) : public OcclusionQueryContext { +public: + INLINE CLP(OcclusionQueryContext)(GraphicsStateGuardian *gsg); + virtual ~CLP(OcclusionQueryContext)(); + + virtual bool is_answer_ready() const; + virtual void waiting_for_answer(); + virtual int get_num_fragments() const; + + GLuint _index; + GraphicsStateGuardian *_gsg; + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + OcclusionQueryContext::init_type(); + register_type(_type_handle, CLASSPREFIX_QUOTED "OcclusionQueryContext", + OcclusionQueryContext::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; +}; + +#include "glOcclusionQueryContext_src.I" +