Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3223

Merged
merged 4 commits into from
Sep 12, 2024
Merged

Devel #3223

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 27 additions & 48 deletions OgreMain/include/OgreHardwareOcclusionQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,85 +42,64 @@ namespace Ogre {
* @{
*/
/**
* This is a abstract class that that provides the interface for the query class for
* hardware occlusion.
* Query how many pixels have passed the per-fragment tests.
*
* @author Lee Sandberg
* Updated on 13/8/2005 by Tuan Kuranes email: [email protected]
* Create one OcclusionQuery per outstanding query or one per tested object
*
* Then, in the rendering loop:
* 1. Draw all occluders
* 2. @ref begin()
* 3. Draw the polygons to be tested
* 4. @ref end()
*
* Results must be pulled using @ref waitForResult()
*/
class _OgreExport HardwareOcclusionQuery : public RenderSysAlloc
class _OgreExport HardwareOcclusionQuery : public RenderSysAlloc
{
//----------------------------------------------------------------------
// Public methods
//--
public:
/**
* Object public member functions
*/

/**
* Default object constructor
*
*/
HardwareOcclusionQuery();

/**
* Object destructor
*/
virtual ~HardwareOcclusionQuery();

/**
* Starts the hardware occlusion query
* @remarks Simple usage: Create one or more OcclusionQuery object one per outstanding query or one per tested object
* OcclusionQuery* mOcclusionQuery;
* createOcclusionQuery( &mOcclusionQuery );
* In the rendering loop:
* Draw all occluders
* mOcclusionQuery->startOcclusionQuery();
* Draw the polygons to be tested
* mOcclusionQuery->endOcclusionQuery();
*
* Results must be pulled using:
* UINT mNumberOfPixelsVisable;
* pullOcclusionQuery( &mNumberOfPixelsVisable );
*
*/
void begin() { beginOcclusionQuery(); }
virtual void beginOcclusionQuery() = 0;

/**
* Ends the hardware occlusion test
*/
void end() { endOcclusionQuery(); }
virtual void endOcclusionQuery() = 0;

/**
* Pulls the hardware occlusion query.
* @note Waits until the query result is available; use isStillOutstanding
* if just want to test if the result is available.
* @retval NumOfFragments will get the resulting number of fragments.
* Waits until the query result is available.
* use @ref resultReady() if just want to test if the result is available.
* @retval result will get the resulting number of fragments.
* @return True if success or false if not.
*/
virtual bool pullOcclusionQuery(unsigned int* NumOfFragments) = 0;
bool waitForResult(unsigned int* result) { return pullOcclusionQuery(result); }
virtual bool pullOcclusionQuery(unsigned int* result) = 0;

/**
* Let's you get the last pixel count with out doing the hardware occlusion test
* Let's you get the last pixel count with out doing the hardware occlusion test.
* This function won't give you new values, just the old value.
* @return The last fragment count from the last test.
* Remarks This function won't give you new values, just the old value.
*/
unsigned int getLastQuerysPixelcount() const { return mPixelCount; }
uint32 getLastResult() const { return mPixelCount; }
OGRE_DEPRECATED uint32 getLastQuerysPixelcount() const { return getLastResult(); }

/**
* Lets you know when query is done, or still be processed by the Hardware
* @return true if query isn't finished.
* @return true if query is finished.
*/
virtual bool isStillOutstanding(void) = 0;

bool resultReady() { return !isStillOutstanding(); }
virtual bool isStillOutstanding(void) = 0;

//----------------------------------------------------------------------
// protected members
//--
protected :
protected:
/// Number of visible pixels determined by last query
unsigned int mPixelCount;
uint32 mPixelCount;
/// Has the query returned a result yet?
bool mIsQueryResultStillOutstanding;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ namespace Ogre {
void beginOcclusionQuery();
void endOcclusionQuery();
bool pullOcclusionQuery( unsigned int* NumOfFragments);
unsigned int getLastQuerysPixelcount() { return mPixelCount; }
bool isStillOutstanding(void);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace Ogre {
{
mDevice.GetImmediateContext()->Begin(mQuery.Get());//Issue(D3DISSUE_BEGIN);
mIsQueryResultStillOutstanding = true;
mPixelCount = 0;
}

void D3D11HardwareOcclusionQuery::endOcclusionQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ namespace Ogre {
void beginOcclusionQuery();
void endOcclusionQuery();
bool pullOcclusionQuery( unsigned int* NumOfFragments);
unsigned int getLastQuerysPixelcount();
bool isStillOutstanding(void);

// Called immediately after the Direct3D device has been created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ namespace Ogre {
{
pOccQuery->Issue(D3DISSUE_BEGIN);
mIsQueryResultStillOutstanding = true;
mPixelCount = 0;
}
}

Expand Down Expand Up @@ -141,7 +140,6 @@ namespace Ogre {
if (hr == D3DERR_DEVICELOST)
{
*NumOfFragments = 0;
mPixelCount = 0;
SAFE_RELEASE(it->second);
break;
}
Expand All @@ -156,12 +154,6 @@ namespace Ogre {
return true;
}

//------------------------------------------------------------------
unsigned int D3D9HardwareOcclusionQuery::getLastQuerysPixelcount()
{
return mPixelCount;
}

//------------------------------------------------------------------
bool D3D9HardwareOcclusionQuery::isStillOutstanding(void)
{
Expand Down
16 changes: 16 additions & 0 deletions RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery()
void GLHardwareOcclusionQuery::beginOcclusionQuery()
{
glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryID);
mIsQueryResultStillOutstanding = true;
}
//------------------------------------------------------------------
void GLHardwareOcclusionQuery::endOcclusionQuery()
Expand All @@ -71,17 +72,32 @@ void GLHardwareOcclusionQuery::endOcclusionQuery()
//------------------------------------------------------------------
bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments )
{
if (!mIsQueryResultStillOutstanding)
{
*NumOfFragments = mPixelCount;
return true;
}

glGetQueryObjectuivARB(mQueryID, GL_QUERY_RESULT_ARB, (GLuint*)NumOfFragments);
mPixelCount = *NumOfFragments;

mIsQueryResultStillOutstanding = false;

return true;
}
//------------------------------------------------------------------
bool GLHardwareOcclusionQuery::isStillOutstanding(void)
{
if (!mIsQueryResultStillOutstanding)
return false;

GLuint available = GL_FALSE;

glGetQueryObjectuivARB(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &available);

if(available == GL_TRUE)
pullOcclusionQuery(&mPixelCount);

// GL_TRUE means a wait would occur
return !(available == GL_TRUE);
}
Expand Down
16 changes: 16 additions & 0 deletions RenderSystems/GL3Plus/src/OgreGL3PlusHardwareOcclusionQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace Ogre {
void GL3PlusHardwareOcclusionQuery::beginOcclusionQuery()
{
OGRE_CHECK_GL_ERROR(glBeginQuery(GL_SAMPLES_PASSED, mQueryID));
mIsQueryResultStillOutstanding = true;
}

void GL3PlusHardwareOcclusionQuery::endOcclusionQuery()
Expand All @@ -73,17 +74,32 @@ namespace Ogre {

bool GL3PlusHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments )
{
if (!mIsQueryResultStillOutstanding)
{
*NumOfFragments = mPixelCount;
return true;
}

OGRE_CHECK_GL_ERROR(glGetQueryObjectuiv(mQueryID, GL_QUERY_RESULT, (GLuint*)NumOfFragments));
mPixelCount = *NumOfFragments;

mIsQueryResultStillOutstanding = false;

return true;
}

bool GL3PlusHardwareOcclusionQuery::isStillOutstanding(void)
{
if (!mIsQueryResultStillOutstanding)
return false;

GLuint available = GL_FALSE;

OGRE_CHECK_GL_ERROR(glGetQueryObjectuiv(mQueryID, GL_QUERY_RESULT_AVAILABLE, &available));

if(available == GL_TRUE)
pullOcclusionQuery(&mPixelCount);

// GL_TRUE means a wait would occur
return !(available == GL_TRUE);
}
Expand Down
16 changes: 16 additions & 0 deletions RenderSystems/GLES2/src/OgreGLES2HardwareOcclusionQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void GLES2HardwareOcclusionQuery::notifyOnContextReset()
void GLES2HardwareOcclusionQuery::beginOcclusionQuery()
{
OGRE_CHECK_GL_ERROR(glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, mQueryID));
mIsQueryResultStillOutstanding = true;
}
//------------------------------------------------------------------
void GLES2HardwareOcclusionQuery::endOcclusionQuery()
Expand All @@ -87,17 +88,32 @@ void GLES2HardwareOcclusionQuery::endOcclusionQuery()
//------------------------------------------------------------------
bool GLES2HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments )
{
if (!mIsQueryResultStillOutstanding)
{
*NumOfFragments = mPixelCount;
return true;
}

OGRE_CHECK_GL_ERROR(glGetQueryObjectuivEXT(mQueryID, GL_QUERY_RESULT_EXT, (GLuint*)NumOfFragments));
mPixelCount = *NumOfFragments;

mIsQueryResultStillOutstanding = false;

return true;
}
//------------------------------------------------------------------
bool GLES2HardwareOcclusionQuery::isStillOutstanding(void)
{
if (!mIsQueryResultStillOutstanding)
return false;

GLuint available = GL_FALSE;

OGRE_CHECK_GL_ERROR(glGetQueryObjectuivEXT(mQueryID, GL_QUERY_RESULT_AVAILABLE_EXT, &available));

if(available == GL_TRUE)
pullOcclusionQuery(&mPixelCount);

// GL_TRUE means a wait would occur
return !(available == GL_TRUE);
}
Expand Down
Loading