Browse Source

Decide about used extensions on only one place.

Having the same branch cascade twice for debug output and for actual
feature selection is not good for maintenance. Put the extensions into
some list and then make it unique instead.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
28939078e2
  1. 17
      src/Magnum/Implementation/DebugState.cpp
  2. 3
      src/Magnum/Implementation/DebugState.h
  3. 47
      src/Magnum/Implementation/State.cpp
  4. 16
      src/Magnum/Implementation/State.h

17
src/Magnum/Implementation/DebugState.cpp

@ -31,8 +31,10 @@
namespace Magnum { namespace Implementation { namespace Magnum { namespace Implementation {
DebugState::DebugState(Context& context): maxLabelLength(0), maxLoggedMessages(0), maxMessageLength(0), messageCallback(nullptr) { DebugState::DebugState(Context& context, std::vector<std::string>& extensions): maxLabelLength(0), maxLoggedMessages(0), maxMessageLength(0), messageCallback(nullptr) {
if(context.isExtensionSupported<Extensions::GL::KHR::debug>()) { if(context.isExtensionSupported<Extensions::GL::KHR::debug>()) {
extensions.push_back(Extensions::GL::KHR::debug::string());
getLabelImplementation = &AbstractObject::getLabelImplementationKhr; getLabelImplementation = &AbstractObject::getLabelImplementationKhr;
labelImplementation = &AbstractObject::labelImplementationKhr; labelImplementation = &AbstractObject::labelImplementationKhr;
messageInsertImplementation = &DebugMessage::insertImplementationKhr; messageInsertImplementation = &DebugMessage::insertImplementationKhr;
@ -40,6 +42,8 @@ DebugState::DebugState(Context& context): maxLabelLength(0), maxLoggedMessages(0
} else { } else {
if(context.isExtensionSupported<Extensions::GL::EXT::debug_label>()) { if(context.isExtensionSupported<Extensions::GL::EXT::debug_label>()) {
extensions.push_back(Extensions::GL::EXT::debug_label::string());
getLabelImplementation = &AbstractObject::getLabelImplementationExt; getLabelImplementation = &AbstractObject::getLabelImplementationExt;
labelImplementation = &AbstractObject::labelImplementationExt; labelImplementation = &AbstractObject::labelImplementationExt;
} else { } else {
@ -47,14 +51,17 @@ DebugState::DebugState(Context& context): maxLabelLength(0), maxLoggedMessages(0
labelImplementation = &AbstractObject::labelImplementationNoOp; labelImplementation = &AbstractObject::labelImplementationNoOp;
} }
if(context.isExtensionSupported<Extensions::GL::EXT::debug_marker>()) if(context.isExtensionSupported<Extensions::GL::EXT::debug_marker>()) {
extensions.push_back(Extensions::GL::EXT::debug_marker::string());
messageInsertImplementation = &DebugMessage::insertImplementationExt; messageInsertImplementation = &DebugMessage::insertImplementationExt;
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
else if(context.isExtensionSupported<Extensions::GL::GREMEDY::string_marker>()) } else if(context.isExtensionSupported<Extensions::GL::GREMEDY::string_marker>()) {
extensions.push_back(Extensions::GL::GREMEDY::string_marker::string());
messageInsertImplementation = &DebugMessage::insertImplementationGremedy; messageInsertImplementation = &DebugMessage::insertImplementationGremedy;
#endif #endif
else } else messageInsertImplementation = &DebugMessage::insertImplementationNoOp;
messageInsertImplementation = &DebugMessage::insertImplementationNoOp;
messageCallbackImplementation = &DebugMessage::callbackImplementationNoOp; messageCallbackImplementation = &DebugMessage::callbackImplementationNoOp;
} }

3
src/Magnum/Implementation/DebugState.h

@ -26,13 +26,14 @@
*/ */
#include <string> #include <string>
#include <vector>
#include "Magnum/DebugMessage.h" #include "Magnum/DebugMessage.h"
namespace Magnum { namespace Implementation { namespace Magnum { namespace Implementation {
struct DebugState { struct DebugState {
DebugState(Context& context); explicit DebugState(Context& context, std::vector<std::string>& extensions);
std::string(*getLabelImplementation)(GLenum, GLuint); std::string(*getLabelImplementation)(GLenum, GLuint);
void(*labelImplementation)(GLenum, GLuint, const std::string&); void(*labelImplementation)(GLenum, GLuint, const std::string&);

47
src/Magnum/Implementation/State.cpp

@ -25,6 +25,8 @@
#include "State.h" #include "State.h"
#include <algorithm>
#include "Magnum/Context.h" #include "Magnum/Context.h"
#include "Magnum/Extensions.h" #include "Magnum/Extensions.h"
@ -39,32 +41,31 @@
namespace Magnum { namespace Implementation { namespace Magnum { namespace Implementation {
State::State(Context& context): State::State(Context& context) {
buffer(new BufferState), /* List of extensions used in current context. Guesstimate count to avoid
debug(new DebugState(context)), unnecessary reallocations. */
framebuffer(new FramebufferState), std::vector<std::string> extensions;
mesh(new MeshState), #ifndef MAGNUM_TARGET_GLES
renderer(new RendererState), extensions.reserve(32);
shader(new ShaderState), #else
shaderProgram(new ShaderProgramState), extensions.reserve(8);
texture(new TextureState) #endif
{
Debug() << "Using optional features:"; buffer = new BufferState;
debug = new DebugState(context, extensions);
framebuffer = new FramebufferState;
mesh = new MeshState;
renderer = new RendererState;
shader = new ShaderState;
shaderProgram = new ShaderProgramState;
texture = new TextureState;
if(context.isExtensionSupported<Extensions::GL::KHR::debug>()) /* Sort the features and remove duplicates */
Debug() << " " << Extensions::GL::KHR::debug::string(); std::sort(extensions.begin(), extensions.end());
else { extensions.erase(std::unique(extensions.begin(), extensions.end()), extensions.end());
if(context.isExtensionSupported<Extensions::GL::EXT::debug_label>())
Debug() << " " << Extensions::GL::EXT::debug_label::string();
if(context.isExtensionSupported<Extensions::GL::EXT::debug_marker>()) Debug() << "Using optional features:";
Debug() << " " << Extensions::GL::EXT::debug_marker::string(); for(const auto& ext: extensions) Debug() << " " << ext;
#ifndef MAGNUM_TARGET_GLES
else if(context.isExtensionSupported<Extensions::GL::GREMEDY::string_marker>())
Debug() << " " << Extensions::GL::GREMEDY::string_marker::string();
#endif
}
} }
State::~State() { State::~State() {

16
src/Magnum/Implementation/State.h

@ -44,14 +44,14 @@ struct State {
~State(); ~State();
BufferState* const buffer; BufferState* buffer;
DebugState* const debug; DebugState* debug;
FramebufferState* const framebuffer; FramebufferState* framebuffer;
MeshState* const mesh; MeshState* mesh;
RendererState* const renderer; RendererState* renderer;
ShaderState* const shader; ShaderState* shader;
ShaderProgramState* const shaderProgram; ShaderProgramState* shaderProgram;
TextureState* const texture; TextureState* texture;
}; };
}} }}

Loading…
Cancel
Save