Browse Source

Call glClearDepth() if glClearDepthf() is not available.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
c9cb20d849
  1. 2
      src/Context.cpp
  2. 34
      src/Renderer.cpp
  3. 20
      src/Renderer.h

2
src/Context.cpp

@ -40,6 +40,7 @@
#include "Framebuffer.h" #include "Framebuffer.h"
#include "Mesh.h" #include "Mesh.h"
#include "Renderbuffer.h" #include "Renderbuffer.h"
#include "Renderer.h"
#include "Implementation/State.h" #include "Implementation/State.h"
@ -368,6 +369,7 @@ Context::Context() {
Framebuffer::initializeContextBasedFunctionality(this); Framebuffer::initializeContextBasedFunctionality(this);
Mesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this);
Renderbuffer::initializeContextBasedFunctionality(this); Renderbuffer::initializeContextBasedFunctionality(this);
Renderer::initializeContextBasedFunctionality(this);
} }
Context::~Context() { Context::~Context() {

34
src/Renderer.cpp

@ -26,9 +26,17 @@
#include "Color.h" #include "Color.h"
#include "Math/Geometry/Rectangle.h" #include "Math/Geometry/Rectangle.h"
#include "Context.h"
#include "Extensions.h"
namespace Magnum { namespace Magnum {
#ifndef MAGNUM_TARGET_GLES
Renderer::ClearDepthfImplementation Renderer::clearDepthfImplementation = &Renderer::clearDepthfImplementationDefault;
#else
Renderer::ClearDepthfImplementation Renderer::clearDepthfImplementation = &Renderer::clearDepthfImplementationES;
#endif
void Renderer::setFeature(const Feature feature, const bool enabled) { void Renderer::setFeature(const Feature feature, const bool enabled) {
enabled ? glEnable(GLenum(feature)) : glDisable(GLenum(feature)); enabled ? glEnable(GLenum(feature)) : glDisable(GLenum(feature));
} }
@ -47,10 +55,6 @@ void Renderer::setClearDepth(const Double depth) {
} }
#endif #endif
void Renderer::setClearDepth(const Float depth) {
glClearDepthf(depth);
}
void Renderer::setClearStencil(const Int stencil) { void Renderer::setClearStencil(const Int stencil) {
glClearStencil(stencil); glClearStencil(stencil);
} }
@ -149,4 +153,26 @@ void Renderer::setLogicOperation(const LogicOperation operation) {
} }
#endif #endif
void Renderer::initializeContextBasedFunctionality(Context* context) {
#ifndef MAGNUM_TARGET_GLES
if(context->isExtensionSupported<Extensions::GL::ARB::ES2_compatibility>()) {
Debug() << "Renderer: using" << Extensions::GL::ARB::ES2_compatibility::string() << "features";
clearDepthfImplementation = &Renderer::clearDepthfImplementationES;
}
#else
static_cast<void>(context);
#endif
}
#ifndef MAGNUM_TARGET_GLES
void Renderer::clearDepthfImplementationDefault(const GLfloat depth) {
glClearDepth(depth);
}
#endif
void Renderer::clearDepthfImplementationES(const GLfloat depth) {
glClearDepthf(depth);
}
} }

20
src/Renderer.h

@ -43,6 +43,8 @@ Access to global renderer configuration.
@todo @extension{ARB,viewport_array} @todo @extension{ARB,viewport_array}
*/ */
class MAGNUM_EXPORT Renderer { class MAGNUM_EXPORT Renderer {
friend class Context;
public: public:
Renderer() = delete; Renderer() = delete;
@ -226,10 +228,12 @@ class MAGNUM_EXPORT Renderer {
* @overload * @overload
* *
* @see @ref Feature "Feature::DepthTest", @fn_gl{ClearDepth} * @see @ref Feature "Feature::DepthTest", @fn_gl{ClearDepth}
* @requires_gl41 %Extension @extension{ARB,ES2_compatibility} * If OpenGL ES, OpenGL 4.1 or extension @extension{ARB,ES2_compatibility}
* @todo Call double version if the extension is not available * is not available, this function behaves exactly as setClearDepth(Double).
*/ */
static void setClearDepth(Float depth); inline static void setClearDepth(Float depth) {
clearDepthfImplementation(depth);
}
/** /**
* @brief Set clear stencil * @brief Set clear stencil
@ -835,6 +839,16 @@ class MAGNUM_EXPORT Renderer {
} }
/*@}*/ /*@}*/
private:
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);
typedef void(*ClearDepthfImplementation)(GLfloat);
#ifndef MAGNUM_TARGET_GLES
static void MAGNUM_LOCAL clearDepthfImplementationDefault(GLfloat depth);
#endif
static void MAGNUM_LOCAL clearDepthfImplementationES(GLfloat depth);
static ClearDepthfImplementation clearDepthfImplementation;
}; };
} }

Loading…
Cancel
Save