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 {
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>()) {
extensions.push_back(Extensions::GL::KHR::debug::string());
getLabelImplementation = &AbstractObject::getLabelImplementationKhr;
labelImplementation = &AbstractObject::labelImplementationKhr;
messageInsertImplementation = &DebugMessage::insertImplementationKhr;
@ -40,6 +42,8 @@ DebugState::DebugState(Context& context): maxLabelLength(0), maxLoggedMessages(0
} else {
if(context.isExtensionSupported<Extensions::GL::EXT::debug_label>()) {
extensions.push_back(Extensions::GL::EXT::debug_label::string());
getLabelImplementation = &AbstractObject::getLabelImplementationExt;
labelImplementation = &AbstractObject::labelImplementationExt;
} else {
@ -47,14 +51,17 @@ DebugState::DebugState(Context& context): maxLabelLength(0), maxLoggedMessages(0
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;
#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;
#endif
else
messageInsertImplementation = &DebugMessage::insertImplementationNoOp;
} else messageInsertImplementation = &DebugMessage::insertImplementationNoOp;
messageCallbackImplementation = &DebugMessage::callbackImplementationNoOp;
}

3
src/Magnum/Implementation/DebugState.h

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

47
src/Magnum/Implementation/State.cpp

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

16
src/Magnum/Implementation/State.h

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

Loading…
Cancel
Save