Browse Source

Revamped Scene/Camera features.

* Moved the enum and setter function to Camera, made it static, because
   it doesn't depend on any particular scene and is camera (rendering)
   related.
 * Function features() didn't actually work, because setFeature() didn't
   update private variable at all. Removed it altogether, because the
   values are not stored anywhere, the enum now holds right values
   (GL_*), which makes setFeature() function so much simpler.
 * Scene class now doesn't have any non-inline functions, removed *.cpp.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
0600764790
  1. 1
      src/CMakeLists.txt
  2. 13
      src/Camera.h
  3. 32
      src/Scene.cpp
  4. 18
      src/Scene.h

1
src/CMakeLists.txt

@ -21,7 +21,6 @@ set(Magnum_SRCS
Mesh.cpp
Query.cpp
Renderbuffer.cpp
Scene.cpp
Shader.cpp
SizeTraits.cpp
TypeTraits.cpp

13
src/Camera.h

@ -33,6 +33,13 @@ namespace Magnum {
*/
class MAGNUM_EXPORT Camera: public Object {
public:
/** @brief Features */
enum class Feature: GLenum {
AlphaBlending = GL_BLEND, /**< Alpha blending */
DepthTest = GL_DEPTH_TEST, /**< Depth test */
FaceCulling = GL_CULL_FACE /**< Face culling */
};
/** @brief Aspect ratio policy */
enum AspectRatioPolicy {
NotPreserved, /**< @brief Don't preserve aspect ratio */
@ -40,6 +47,12 @@ class MAGNUM_EXPORT Camera: public Object {
Clip /**< @brief Clip on smaller side of view */
};
/** @brief Set feature */
/** @todo Depth clamping (OpenGL 3.2, ARB_depth_clamp) */
inline static void setFeature(Feature feature, bool enabled) {
enabled ? glEnable(static_cast<GLenum>(feature)) : glDisable(static_cast<GLenum>(feature));
}
/**
* @brief Constructor
* @param parent Parent object

32
src/Scene.cpp

@ -1,32 +0,0 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include "Scene.h"
namespace Magnum {
void Scene::setFeature(Scene::Feature feature, bool enabled) {
GLenum _feature;
switch(feature) {
case AlphaBlending: _feature = GL_BLEND; break;
case DepthTest: _feature = GL_DEPTH_TEST; break;
case FaceCulling: _feature = GL_CULL_FACE; break;
default: return;
}
enabled ? glEnable(_feature) : glDisable(_feature);
}
}

18
src/Scene.h

@ -26,15 +26,8 @@ namespace Magnum {
/** @brief %Scene */
class MAGNUM_EXPORT Scene: public Object {
public:
/** @brief Features */
enum Feature {
AlphaBlending = 0x01, /**< @brief Alpha blending */
DepthTest = 0x02, /**< @brief Depth test */
FaceCulling = 0x04 /**< @brief Face culling */
};
/** @brief Constructor */
inline Scene(): _features(0) { _parent = this; }
inline Scene() { _parent = this; }
void setParent(Object* parent) = delete;
void setTransformation(const Matrix4& transformation) = delete;
@ -43,16 +36,7 @@ class MAGNUM_EXPORT Scene: public Object {
void scale(Vector3 vec, Transformation type = Transformation::Global) = delete;
void rotate(GLfloat angle, Vector3 vec, Transformation type = Transformation::Global) = delete;
/** @brief Which features are set */
inline unsigned int features() const { return _features; }
/** @brief Set feature */
/** @todo Depth clamping (OpenGL 3.2, ARB_depth_clamp) */
void setFeature(Feature feature, bool enabled);
private:
unsigned int _features;
inline virtual void draw(const Magnum::Matrix4& transformationMatrix, Camera* camera) {}
};

Loading…
Cancel
Save