Occlusion query support of IGLDevice

This commit is contained in:
yvt 2013-09-06 20:05:19 +09:00
parent 29374bf680
commit 76c68ba1b1
3 changed files with 146 additions and 0 deletions

View File

@ -102,6 +102,13 @@ namespace spades {
Back,
FrontAndBack,
// Query Object
SamplesPassed,
AnySamplesPassed,
QueryResult,
QueryResultAvailable,
// Buffer target
ArrayBuffer,
ElementArrayBuffer,
@ -284,6 +291,13 @@ namespace spades {
Sizei size,
const void *data) = 0;
virtual UInteger GenQuery() = 0;
virtual void DeleteQuery(UInteger) = 0;
virtual void BeginQuery(Enum target, UInteger query) = 0;
virtual void EndQuery(Enum target) = 0;
virtual UInteger GetQueryObjectUInteger(UInteger query,
Enum pname) = 0;
virtual void *MapBuffer(Enum target, Enum access) = 0;
virtual void UnmapBuffer(Enum target) = 0;

View File

@ -550,6 +550,131 @@ ReportError(err, __LINE__, __PRETTY_FUNCTION__); \
CheckError();
}
IGLDevice::UInteger SDLGLDevice::GenQuery() {
SPADES_MARK_FUNCTION_DEBUG();
GLuint val;
#if GLEW
if(glGenQueries)
glGenQueries(1, &val);
else if(glGenQueriesARB)
glGenQueriesARB(1, &val);
else
ReportMissingFunc("glGenQueries");
#else
CheckExistence(glGenQueries);
glGenQueries(1, &val);
#endif
CheckError();
return val;
}
void SDLGLDevice::DeleteQuery(UInteger query) {
SPADES_MARK_FUNCTION_DEBUG();
#if GLEW
if(glDeleteQueries)
glDeleteQueries(1, &query);
else if(glDeleteQueriesARB)
glDeleteQueriesARB(1, &query);
else
ReportMissingFunc("glDeleteQueries");
#else
CheckExistence(glDeleteQueries);
glDeleteQueries(1, &query);
#endif
CheckError();
}
static GLenum parseQueryTarget(IGLDevice::Enum target){
SPADES_MARK_FUNCTION_DEBUG();
switch(target){
case IGLDevice::SamplesPassed:
return GL_SAMPLES_PASSED;
case IGLDevice::AnySamplesPassed:
return GL_ANY_SAMPLES_PASSED;
default:
SPInvalidEnum("target", target);
}
}
void SDLGLDevice::BeginQuery(Enum target, UInteger query){
SPADES_MARK_FUNCTION_DEBUG();
#if GLEW
if(glBeginQuery)
glBeginQuery(parseQueryTarget(target), query);
else if(glBeginQueryARB)
glBeginQueryARB(parseQueryTarget(target), query);
else
ReportMissingFunc("glBeginQuery");
#else
CheckExistence(glBeginQuery);
glBeginQuery(parseQueryTarget(target), query);
#endif
CheckError();
}
void SDLGLDevice::EndQuery(Enum target) {
SPADES_MARK_FUNCTION_DEBUG();
#if GLEW
if(glEndQuery)
glEndQuery(parseQueryTarget(target));
else if(glEndQueryARb)
glEndQueryARb(parseQueryTarget(target));
else
ReportMissingFunc("glBeginQuery");
#else
CheckExistence(glEndQuery);
glEndQuery(parseQueryTarget(target));
#endif
CheckError();
}
IGLDevice::UInteger SDLGLDevice::GetQueryObjectUInteger(UInteger query, Enum pname) {
GLuint val;
SPADES_MARK_FUNCTION_DEBUG();
#if GLEW
if(glGetQueryObjectuiv){
switch(pname) {
case draw::IGLDevice::QueryResult:
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &val);
break;
case draw::IGLDevice::QueryResultAvailable:
glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &val);
break;
default:
SPInvalidEnum("pname", pname);
}
}else if(glGetQueryObjectuivARB){
switch(pname) {
case draw::IGLDevice::QueryResult:
glGetQueryObjectuivARB(query, GL_QUERY_RESULT, &val);
break;
case draw::IGLDevice::QueryResultAvailable:
glGetQueryObjectuivARB(query, GL_QUERY_RESULT_AVAILABLE, &val);
break;
default:
SPInvalidEnum("pname", pname);
}
}else{
ReportMissingFunc("glGetQueryObjectuiv");
}
#else
CheckExistence(glGetQueryObjectuiv);
switch(pname) {
case draw::IGLDevice::QueryResult:
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &val);
break;
case draw::IGLDevice::QueryResultAvailable:
glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &val);
break;
default:
SPInvalidEnum("pname", pname);
}
#endif
CheckError();
return val;
}
IGLDevice::UInteger SDLGLDevice::GenTexture() {
GLuint i;
CheckExistence(glGenTextures);

View File

@ -78,6 +78,13 @@ namespace spades {
Sizei size,
const void *data);
virtual UInteger GenQuery();
virtual void DeleteQuery(UInteger);
virtual void BeginQuery(Enum target, UInteger query);
virtual void EndQuery(Enum target);
virtual UInteger GetQueryObjectUInteger(UInteger query,
Enum pname);
virtual UInteger GenTexture();
virtual void DeleteTexture(UInteger);