Commit 5576f538 authored by Martin Schultz's avatar Martin Schultz
Browse files

Merge branch 'fixCoreProfileIncompatibility' into 'featureCoreProfile'

Fix core profile incompatibility

See merge request !41
parents 927827c3 6826cda2
......@@ -116,9 +116,6 @@ class RenderInterface {
* // Collect missing extension
* QString missing = "";
*
* if ( !glExtensions.contains("GL_ARB_vertex_buffer_object") )
* missing += "Missing Extension GL_ARB_vertex_buffer_object\n";
*
* if ( !glExtensions.contains("GL_ARB_vertex_program") )
* missing += "Missing Extension GL_ARB_vertex_program\n";
*
......
......@@ -1957,15 +1957,9 @@ bool Core::checkOpenGLCapabilities() {
missing += tr("No OpenGL support found!\n");
}
//Get OpenGL extensions
//Get OpenGL extensions not needed, deprecated style .... get rid of it ... soon
QString glExtensions = QString((const char*)glGetString(GL_EXTENSIONS));
// Vertex buffer objects used heavily in mesh node and almost all other nodes
if ( !glExtensions.contains("GL_ARB_vertex_buffer_object") ) {
ok = false;
missing += tr("Your graphics card does not support the GL_ARB_vertex_buffer_object extension!\n");
}
#else
QOpenGLContext* context = QOpenGLContext::currentContext();
......@@ -1979,14 +1973,6 @@ bool Core::checkOpenGLCapabilities() {
ok = false;
missing += tr("OpenGL Version less then 2.0!\n");
} else {
// Check extensions
if ( !context->hasExtension("GL_ARB_vertex_buffer_object") ) {
missing += "GL_ARB_vertex_buffer_object extension missing\n";
ok = false;
}
}
} else {
......
......@@ -600,8 +600,15 @@ void loggerState( LoggerState _state) {
}
/// Current state of the logging window?
LoggerState loggerState( ) {
return static_cast<OpenFlipper::Options::LoggerState> (OpenFlipperSettings().value("Core/Gui/LogWindow/LogWindowMode",0).toInt() );
LoggerState loggerState( ) {
LoggerState state = static_cast<OpenFlipper::Options::LoggerState> (OpenFlipperSettings().value("Core/Gui/LogWindow/LogWindowMode",0).toInt() );
// workaround for windows issue with drawing logger in scene using coreProfile (thank you Qt)
#ifdef WIN32
if(coreProfile_ && state == LoggerState::InScene)
return LoggerState::Normal;
#endif
/////////////////////////////////////////////////////////////////////////////////////////////
return state;
}
/// Which mode should is currently selected?
......
......@@ -58,8 +58,8 @@
//== INCLUDES =================================================================
#include <ACG/GL/acg_glew.hh>
#include <ACG/GL/AntiAliasing.hh>
#include <ACG/GL/acg_glew.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/ScreenQuad.hh>
......@@ -82,7 +82,7 @@ namespace ACG {
//== CLASS IMPLEMENTATION =====================================================
#ifdef GL_ARB_texture_multisample
#ifdef MSFILTERWEIGHTS
MSFilterWeights::MSFilterWeights(int _numSamples) : numSamples_(_numSamples) {
......@@ -133,12 +133,12 @@ void MSFilterWeights::asTextureBuffer( TextureBuffer& out ) {
//=============================================================================
#endif //MSFILTERWEIGHTS
//=============================================================================
#ifdef MSTEXTURESAMPLER
MSTextureSampler::MSTextureSampler() : shaderNearest_(0), shaderNearestDepth_(0), shaderLinear_(0) {
}
......@@ -286,7 +286,7 @@ void MSTextureSampler::filterMSAATexture_Linear( GLuint _texture, int _samples,
#endif // GL_ARB_texture_multisample
#endif // MSTEXTURESAMPLER
} // namespace ACG
......
......@@ -63,6 +63,7 @@
//== INCLUDES =================================================================
// GL
#include <ACG/GL/acg_glew.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/GL/gl.hh>
......@@ -105,8 +106,8 @@ Recommended resources on implementing MSAA with render to texture:
http://www.humus.name/index.php?page=3D&ID=81
*/
#ifdef GL_ARB_texture_multisample
#define MSFILTERWEIGHTS
class ACGDLLEXPORT MSFilterWeights
{
......@@ -149,8 +150,8 @@ private:
// This class performs multisampling on MSAA textures and writes the result to the currently bound FBO.
#ifdef GL_ARB_texture_multisample
#define MSTEXTURESAMPLER
class ACGDLLEXPORT MSTextureSampler
{
......
......@@ -118,6 +118,10 @@ GLStateContext::GLStateContext() :
{
framebuffers_[0] = framebuffers_[1] = 0;
memset(drawBufferState_, GL_BACK, sizeof(drawBufferState_));
blendFuncState_[0] = GL_SRC_ALPHA;
blendFuncState_[1] = GL_ONE_MINUS_SRC_ALPHA;
blendFuncState_[2] = GL_SRC_ALPHA;
blendFuncState_[3] = GL_ONE_MINUS_SRC_ALPHA;
}
GLState::GLState(bool _updateGL, bool _compatibilityProfile)
......@@ -273,9 +277,10 @@ void GLState::clearBuffers ()
GLState::disable(GL_DEPTH_TEST);
GLState::disable(GL_DITHER);
glShadeModel( GL_FLAT );
if ( compatibilityProfile_ ) {
glShadeModel(GL_FLAT);
GLState::disable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
......@@ -2070,9 +2075,11 @@ void GLState::bindFramebuffer(GLenum _target, GLuint _framebuffer)
if (stateStack_.back().framebuffers_[i] != _framebuffer)
#endif
{
if (!glBindFramebufferEXT)
glewInit();
glBindFramebufferEXT(_target, _framebuffer);
#ifndef __APPLE__
if (!glBindFramebuffer)
glewInit();
#endif
glBindFramebuffer(_target, _framebuffer);
stateStack_.back().framebuffers_[i] = _framebuffer;
}
}
......
......@@ -82,8 +82,10 @@ curViewerID_(0),
prevFbo_(0),
prevDrawBuffer_(GL_BACK),
prevFboSaved_(false),
prevVAO_(0),
depthCopyShader_(0),
errorDetectionLevel_(1),
coreProfile_(false),
enableLineThicknessGL42_(false)
{
prevViewport_[0] = 0;
......@@ -537,6 +539,13 @@ void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph
void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot)
{
// save default VAO
#ifdef GL_ARB_vertex_array_object
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &prevVAO_);
#endif
coreProfile_ = !_glState->compatibilityProfile();
// grab view transform from glstate
viewMatrix_ = _glState->modelview();
camPosWS_ = Vec3f( viewMatrix_(0,3), viewMatrix_(1,3), viewMatrix_(2,3) );
......@@ -622,12 +631,14 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
// ---------------------------
// gl cleanup
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
if (_glState->compatibilityProfile())
{
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
}
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
......@@ -637,12 +648,13 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
// save active fbo and viewport
saveInputFbo();
if(_glState->compatibilityProfile())
{
// get global ambient factor
GLfloat lightModelAmbient[4];
glGetFloatv(GL_LIGHT_MODEL_AMBIENT, lightModelAmbient);
globalLightModelAmbient_ = ACG::Vec3f(lightModelAmbient[0], lightModelAmbient[1], lightModelAmbient[2]);
}
// search list of render object for objects requiring the scene depth map
bool requiresSceneDepths = false;
......@@ -663,7 +675,7 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
void IRenderer::finishRenderingPipeline(bool _drawOverlay)
{
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(0);
glBindVertexArray(prevVAO_);
#endif
// draw thick lines
......@@ -719,7 +731,7 @@ void IRenderer::finishRenderingPipeline(bool _drawOverlay)
}
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(0);
glBindVertexArray(prevVAO_);
#endif
for (int i = 0; i < maxClipDistances_; ++i)
......@@ -732,8 +744,8 @@ void IRenderer::finishRenderingPipeline(bool _drawOverlay)
glUseProgram(0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// Renderer check:
// Print a warning if the currently active fbo / viewport is not the same as the saved fbo.
......@@ -876,7 +888,8 @@ void IRenderer::bindObjectVBO(ACG::RenderObject* _obj,
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(_obj->vertexArrayObject);
if (_obj->vertexArrayObject)
glBindVertexArray(_obj->vertexArrayObject);
#endif
if (!_obj->vertexArrayObject)
......@@ -885,8 +898,8 @@ void IRenderer::bindObjectVBO(ACG::RenderObject* _obj,
// NOTE:
// always bind buffers before glVertexAttribPointer calls!!
// freeze in glDrawElements guaranteed (with no error message whatsoever)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _obj->vertexBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _obj->indexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _obj->vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _obj->indexBuffer);
// activate vertex declaration
......@@ -1017,13 +1030,16 @@ void IRenderer::bindObjectRenderStates(ACG::RenderObject* _obj)
else
glDisable(GL_BLEND);
if (_obj->alphaTest)
if (!coreProfile_)
{
glEnable(GL_ALPHA_TEST);
glAlphaFunc(_obj->alphaFunc, _obj->alphaRef);
if (_obj->alphaTest)
{
glEnable(GL_ALPHA_TEST);
glAlphaFunc(_obj->alphaFunc, _obj->alphaRef);
}
else
glDisable(GL_ALPHA_TEST);
}
else
glDisable(GL_ALPHA_TEST);
if (_obj->depthTest)
glEnable(GL_DEPTH_TEST);
......@@ -1162,7 +1178,7 @@ void IRenderer::renderObject(ACG::RenderObject* _obj,
#ifdef GL_ARB_vertex_array_object
if (_obj->vertexArrayObject)
glBindVertexArray(0);
glBindVertexArray(prevVAO_);
#endif
}
......
......@@ -480,6 +480,14 @@ public:
*/
void setViewerID(int _viewerID);
/** \brief Tell renderer to use core or compatibility profile
*
* @param _enable renderer should use opengl in core profile mode
*/
void setCoreProfileMode(bool _enable) {coreProfile_ = _enable;}
/**
* During traversal of the scene graph this method returns the range of
* render objects that has been collected in the current subtree.
......@@ -560,12 +568,20 @@ protected:
/// flag indicating a that saveCurrentFbo() has been called prior restoreFbo()
bool prevFboSaved_;
/// previously bound VAO
GLint prevVAO_;
/// shader copies depth of the first front layer to the back buffer
GLSL::Program* depthCopyShader_;
/// error-detection level for checking render objects
int errorDetectionLevel_;
/// core profile mode
bool coreProfile_;
/// max number of clip distance outputs in a vertex shader
static int maxClipDistances_;
......
......@@ -125,7 +125,8 @@ void RenderObject::initFromState( GLState* _glState )
pointSize = _glState->point_size();
}
if(_glState->compatibilityProfile())
{
// get texcoord generation params
if (glIsEnabled(GL_TEXTURE_GEN_Q))
shaderDesc.texGenDim = 4;
......@@ -135,7 +136,7 @@ void RenderObject::initFromState( GLState* _glState )
shaderDesc.texGenDim = 2;
else if (glIsEnabled(GL_TEXTURE_GEN_S))
shaderDesc.texGenDim = 1;
}
if (shaderDesc.texGenDim)
{
GLint genMode = 0;
......
......@@ -65,7 +65,7 @@
#if defined(ARCH_DARWIN)
#include <GL/glew.h>
#include <OpenGL/gl3.h>
#elif defined(WIN32)
......
......@@ -61,11 +61,16 @@ namespace {
inline const char *_getExtensionString() {
// glGetString(GL_EXTENSIONS) is deprecated and not available in core profile
if(!openGLVersion(3,0))
{
return (const char*) glGetString(GL_EXTENSIONS);
}
// enumerate extensions with glGetStringi(GL_EXTENSIONS, id) instead
#ifndef __APPLE__
if (!glGetStringi)
glewInit();
#endif
static std::string supported_str;
if (supported_str.empty()) {
......@@ -92,6 +97,11 @@ inline const char *_getExtensionString() {
}
}
std::string getExtensionString()
{
return _getExtensionString();
}
/** Check if the extension given by a std::string is supported by the current OpenGL extension
*/
bool checkExtensionSupported( const std::string& _extension ) {
......
......@@ -255,6 +255,13 @@ inline void ACG::GLState::texcoordPointer(GLint n, GLenum t, GLsizei s, const GL
{ ::ACG::GLState::texcoordPointer(n, t, s, p); }
*/
/**
* @brief getExtensionString returns a string containing all supported OpenGL extensions
* this function uses the new style to query the extensions
*
* @return std::string with all supported extensions
*/
std::string ACGDLLEXPORT getExtensionString( ) ;
/** Check if the extension given by a std::string is supported by the current OpenGL extension
*/
......
......@@ -327,7 +327,11 @@ bool Texture2D::autogenerateMipMaps()
#ifdef GL_SGIS_generate_mipmap
if (supportsGenerateMipmap())
{
parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
//parameter based mipmap generation was removed in 3.1
if( openGLVersion(3,1))
glGenerateMipmap(GL_TEXTURE_2D);
else
parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
return true;
}
#endif
......@@ -1000,6 +1004,8 @@ bool VertexArrayObject::isSupported()
if (supportStatus_ < 0)
supportStatus_ = checkExtensionSupported("GL_ARB_vertex_array_object") ? 1 : 0;
if( openGLVersion(3,2) )
return true;
#endif
return supportStatus_ > 0;
......
......@@ -1142,7 +1142,9 @@ void QtBaseViewer::initializeGL()
ACG::GLState::enable(GL_DEPTH_TEST);
ACG::GLState::enable(GL_LIGHTING);
ACG::GLState::disable(GL_DITHER);
ACG::GLState::shadeModel( GL_FLAT );
if (glstate_->compatibilityProfile())
ACG::GLState::shadeModel( GL_FLAT );
projectionMode( projectionMode_ );
......@@ -1291,7 +1293,9 @@ void QtBaseViewer::paintGL()
ACG::GLState::enable(GL_DEPTH_TEST);
ACG::GLState::enable(GL_LIGHTING);
ACG::GLState::disable(GL_DITHER);
ACG::GLState::shadeModel( GL_FLAT );
if (glstate_->compatibilityProfile())
ACG::GLState::shadeModel( GL_FLAT );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
......
......@@ -60,7 +60,7 @@
#include "CoordsysNode.hh"
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/ShaderCache.hh>
//== NAMESPACES ===============================================================
......@@ -253,45 +253,126 @@ void CoordsysNode::drawCoordsys(IRenderer* _renderer, RenderObject* _baseRO)
//============================================================================
void
CoordsysNode::drawCoordsysPick( GLState& _state) {
CoordsysNode::drawCoordsysPick( GLState& _state, GLSL::Program* _pickShader) {
const double arrowLength = 0.03;
const double bodyLength = 0.06;
const double sphereRadius = 0.01;
// Origin
_state.pick_set_name (1);
sphere_->draw(_state,sphereRadius);
if (_pickShader)
{
_pickShader->setUniform("color", _state.pick_get_name_color_norm(1));
GLMatrixf mWVP = _state.projection() * _state.modelview();
mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
_pickShader->setUniform("mWVP", mWVP);
sphere_->draw_primitive(_pickShader);
}
else
{
_state.pick_set_name (1);
sphere_->draw(_state,sphereRadius);
}
// X-Axis
_state.pick_set_name (2);
if (_pickShader)
_pickShader->setUniform("color", _state.pick_get_name_color_norm(2));
else
_state.pick_set_name(2);
_state.push_modelview_matrix ();
_state.rotate (-90, 0, 1, 0);
_state.translate ( 0, 0, -bodyLength );
cylinder_->draw(_state,bodyLength);
_state.push_modelview_matrix();
_state.scale(1.0, 1.0, bodyLength);
if (_pickShader)
{
// set transform matrix
GLMatrixf mWVP = _state.projection() * _state.modelview();
_pickShader->setUniform("mWVP", mWVP);
cylinder_->draw_primitive(_pickShader);
}
else
cylinder_->draw_primitive();
_state.pop_modelview_matrix();
_state.translate ( 0, 0, -arrowLength );
cone_->draw(_state,arrowLength);
_state.scale(1.0, 1.0, arrowLength);
if (_pickShader)
{
// set transform matrix
GLMatrixf mWVP = _state.projection() * _state.modelview();
_pickShader->setUniform("mWVP", mWVP);
cone_->draw_primitive(_pickShader);
}
else
cone_->draw_primitive();
_state.pop_modelview_matrix ();
// Y-Axis
_state.pick_set_name (3);
if (_pickShader)
_pickShader->setUniform("color", _state.pick_get_name_color_norm(3));
else
_state.pick_set_name(3);
_state.push_modelview_matrix ();
_state.rotate (90, 1, 0, 0);
_state.translate ( 0, 0, -bodyLength );
cylinder_->draw(_state,bodyLength);
_state.translate ( 0, 0, -arrowLength );
cone_->draw(_state,arrowLength);
_state.push_modelview_matrix();
_state.scale(1.0, 1.0, bodyLength);
if (_pickShader)
{
// set transform matrix
GLMatrixf mWVP = _state.projection() * _state.modelview();
_pickShader->setUniform("mWVP", mWVP);
cylinder_->draw_primitive(_pickShader);
}
else
cylinder_->draw_primitive();
_state.pop_modelview_matrix();
_state.translate(0, 0, -arrowLength);
_state.scale(1.0, 1.0, arrowLength);
if (_pickShader)
{
// set transform matrix
GLMatrixf mWVP = _state.projection() * _state.modelview();
_pickShader->setUniform("mWVP", mWVP);
cone_->draw_primitive(_pickShader);
}
else
cone_->draw_primitive();
_state.pop_modelview_matrix ();
// Z-Axis
_state.pick_set_name (4);
if (_pickShader)
_pickShader->setUniform("color", _state.pick_get_name_color_norm(4));
else
_state.pick_set_name(4);
_state.push_modelview_matrix ();
_state.rotate (180, 0, 1, 0);
_state.translate ( 0, 0, -bodyLength );
cylinder_->draw(_state,bodyLength);
_state.translate ( 0, 0, -arrowLength );
cone_->draw(_state,arrowLength);
_state.push_modelview_matrix();
_state.scale(1.0, 1.0, bodyLength);
if (_pickShader)
{
// set transform matrix
GLMatrixf mWVP = _state.projection() * _state.modelview();
_pickShader->setUniform("mWVP", mWVP);
cylinder_->draw_primitive(_pickShader);
}
else
cylinder_->draw_primitive();
_state.pop_modelview_matrix();
_state.translate(0, 0, -arrowLength);
_state.scale(1.0, 1.0, arrowLength);
if (_pickShader)
{
// set transform matrix
GLMatrixf mWVP = _state.projection() * _state.modelview();
_pickShader->setUniform("mWVP", mWVP);
cone_->draw_primitive(_pickShader);
}
else
cone_->draw_primitive();
_state.pop_modelview_matrix ();
}
......@@ -609,8 +690,22 @@ getProjectionMode() const
void
CoordsysNode::pick(GLState& _state, PickTarget _target)
{