Browse Source

Better Camera clearing.

Now it is exposed as protected function, so it can be called from
subclasses. It now clears() only set features, so when stencil or depth
test is not enables, it doesn't clear their buffers.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
9d39808a84
  1. 18
      src/Camera.cpp
  2. 20
      src/Camera.h

18
src/Camera.cpp

@ -20,6 +20,21 @@ using namespace std;
namespace Magnum {
GLbitfield Camera::clearMask = GL_COLOR_BUFFER_BIT;
void Camera::setFeature(Feature feature, bool enabled) {
/* Enable or disable the feature */
enabled ? glEnable(static_cast<GLenum>(feature)) : glDisable(static_cast<GLenum>(feature));
/* Update clear mask, if needed */
GLbitfield clearMaskChange;
if(feature == Feature::DepthTest) clearMaskChange = GL_DEPTH_BUFFER_BIT;
else if(feature == Feature::StencilTest) clearMaskChange = GL_STENCIL_BUFFER_BIT;
else return;
enabled ? clearMask |= clearMaskChange : clearMask &= ~clearMaskChange;
}
Camera::Camera(Object* parent): Object(parent), _aspectRatioPolicy(AspectRatioPolicy::Extend) {}
void Camera::setOrthographic(GLfloat size, GLfloat near, GLfloat far) {
@ -109,8 +124,7 @@ void Camera::draw() {
Scene* s = scene();
CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", )
/** @todo Clear only set features */
glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
clear();
/* Recursively draw child objects */
drawChildren(s, cameraMatrix());

20
src/Camera.h

@ -67,9 +67,7 @@ class MAGNUM_EXPORT Camera: public Object {
};
/** @brief Set feature */
inline static void setFeature(Feature feature, bool enabled) {
enabled ? glEnable(static_cast<GLenum>(feature)) : glDisable(static_cast<GLenum>(feature));
}
static void setFeature(Feature feature, bool enabled);
/**
* @brief Constructor
@ -151,14 +149,24 @@ class MAGNUM_EXPORT Camera: public Object {
/**
* @brief Draw the scene
*
* Clears the color, depth and stencil buffer and draws the scene
* using drawChildren().
* Calls clear() and draws the scene using drawChildren().
*/
virtual void draw();
using Object::draw; /* Don't hide Object's draw() */
protected:
/**
* @brief Clear framebuffer
*
* Clears color buffer, depth and stencil buffer in currently active
* framebuffer. If depth or stencil test is not enabled, it doesn't
* clear these buffers.
*
* @see setFeature()
*/
inline static void clear() { glClear(clearMask); }
/**
* Recalculates camera matrix.
*/
@ -172,6 +180,8 @@ class MAGNUM_EXPORT Camera: public Object {
void drawChildren(Object* object, const Matrix4& transformationMatrix);
private:
static GLbitfield clearMask;
Matrix4 rawProjectionMatrix;
Matrix4 _projectionMatrix;
Matrix4 _cameraMatrix;

Loading…
Cancel
Save