Commit 341c6436 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'featureCoreProfile' into 'master'

Feature core profile

See merge request !65
parents b3b8d339 386eb643
......@@ -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";
*
......
......@@ -98,20 +98,6 @@
//== IMPLEMENTATION ==========================================================
namespace {
void recreateContext()
{
#ifdef WIN32
QOpenGLContext* ctx = QOpenGLContext::currentContext();
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
ctx->setFormat(format);
ctx->create();
QOffscreenSurface* surface = new QOffscreenSurface();
ctx->makeCurrent(surface);
#endif
}
}
/** \brief Constuctor for the Core Widget ( This is stage 1 , call init for stage 2)
*
* Initialization is working the following way:\n
......@@ -667,7 +653,6 @@ Core::init() {
coreWidget_->splitter_->restoreState (windowStates.value("Core/LogSplitter").toByteArray ());
coreWidget_->show();
recreateContext();
applyOptions();
......@@ -686,7 +671,6 @@ Core::init() {
} else {
coreWidget_->show();
recreateContext();
applyOptions();
......@@ -1974,15 +1958,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();
......@@ -1996,14 +1974,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 {
......
......@@ -348,6 +348,12 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *err
QCommandLineOption remotePortOption("remote-port",QCoreApplication::translate("main", "Remote port"),"portnumber");
parser.addOption(remotePortOption);
QCommandLineOption coreProfileOption("core-profile",QCoreApplication::translate("main", "OpenGL Core Profile Mode"));
parser.addOption(coreProfileOption);
QCommandLineOption profileOption("profile",QCoreApplication::translate("main","Request OpenGL context profile <profile> with profile set as compat or core"),QCoreApplication::translate("main","<compat | core >"));
profileOption.setDefaultValue("compat");
parser.addOption(profileOption);
const QCommandLineOption helpOption = parser.addHelpOption();
const QCommandLineOption versionOption = parser.addVersionOption();
......@@ -408,7 +414,21 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *err
const QString port = parser.value("remote-port");
std::cerr << "Got port option : " << port.toStdString() << std::endl;
OpenFlipper::Options::remoteControl(port.toInt());
}
if(parser.value(profileOption)=="core")
{
OpenFlipper::Options::coreProfile(true);
}
else
{
if(parser.value(profileOption)=="compat")
{
OpenFlipper::Options::coreProfile(false);
}
}
if(parser.isSet(coreProfileOption)) {
OpenFlipper::Options::coreProfile(true);
}
return CommandLineOk;
......@@ -496,11 +516,14 @@ int main(int argc, char **argv)
QSurfaceFormat format;
format.setVersion(4, 4);
if (OpenFlipper::Options::coreProfile())
{
format.setProfile(QSurfaceFormat::CoreProfile);
}
else {
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setOption(QSurfaceFormat::DeprecatedFunctions);
}
if (OpenFlipper::Options::debug())
format.setOption(format.options() | QSurfaceFormat::DebugContext);
......
// picking - all fragments have the same pick id
#version 130
#version 150
uniform vec4 color;
......@@ -9,4 +9,4 @@ out vec4 outColor;
void main()
{
outColor = color;
}
\ No newline at end of file
}
#version 330
uniform sampler2D DepthTex;
uniform float DepthSign;
in vec2 vTexCoord;
out vec4 oColor;
void main()
{
oColor = vec4(1.0, 1.0, 1.0, 1.0);
gl_FragDepth = texture(DepthTex, vTexCoord).x * DepthSign;
}
\ No newline at end of file
......@@ -7,5 +7,5 @@ out vec4 oColor;
void main()
{
oColor = texture2D(Tex, vTexCoord);
}
\ No newline at end of file
oColor = texture(Tex, vTexCoord);
}
......@@ -136,6 +136,9 @@ static bool nogui_ = false;
/// Store the stereo support
static bool stereo_ = true;
/// Use opengl core profile mode?
static bool coreProfile_ = false;
/// Store the opengl stereo support
static bool glStereo_ = true;
......@@ -374,6 +377,16 @@ bool stereo( ) {
return stereo_;
}
/// Store opengl core profile setting
void coreProfile( bool _enableCoreProfile ) {
coreProfile_ = _enableCoreProfile;
}
/// get opengl core profile setting
bool coreProfile( ) {
return coreProfile_;
}
/// Store opengl stereo mode setting
void glStereo( bool _glStereo ) {
glStereo_ = _glStereo;
......@@ -587,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?
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
......@@ -415,6 +415,14 @@ QString helpDirStr();
DLLEXPORT
bool gui( );
/// Store opengl core profile setting
DLLEXPORT
void coreProfile(bool _enableCoreProfile);
/// get opengl core profile setting
DLLEXPORT
bool coreProfile( );
/// Store stereo support setting
DLLEXPORT
void stereo( bool _stereo );
......
......@@ -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) {
......@@ -125,20 +125,18 @@ MSFilterWeights::MSFilterWeights(int _numSamples) : numSamples_(_numSamples) {
}
//=============================================================================
void MSFilterWeights::asTextureBuffer( TextureBuffer& out ) {
if (numSamples_)
out.setBufferData(numSamples_ * 4, &weights_[0], GL_R32F, GL_STATIC_DRAW);
}
//=============================================================================
#endif //MSFILTERWEIGHTS
//=============================================================================
#ifdef MSTEXTURESAMPLER
MSTextureSampler::MSTextureSampler() : shaderNearest_(0), shaderNearestDepth_(0), shaderLinear_(0) {
}
......@@ -286,7 +284,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
{
......@@ -116,13 +117,11 @@ public:
virtual ~MSFilterWeights() { }
#if defined(GL_ARB_texture_buffer_object)
// Initializes a texture buffer with filter weights in format GL_R32F.
// This can be used for reading from multisampled textures in a shader.
void asTextureBuffer(TextureBuffer& out);
#endif
// get ptr to weights as array, can be used for setUniform() for example
const float* asDataPtr() const {return &weights_[0];}
......@@ -149,8 +148,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
{
......
......@@ -60,6 +60,7 @@
#include "ColorStack.hh"
#include <ACG/GL/GLState.hh>
#include <iostream>
......@@ -89,14 +90,14 @@ ColorStack::~ColorStack ()
//----------------------------------------------------------------------------
void ColorStack::initialize ()
void ColorStack::initialize (GLState* _state)
{
if (initialized_)
{
delete root_;
}
error_ = false;
translator_.initialize ();
translator_.initialize (_state);
root_ = currentNode_ = new ColorStack::Node (0, 0, &translator_);
initialized_ = true;
}
......@@ -241,7 +242,7 @@ bool ColorStack::Node::setIndex (size_t _idx) const
{
if (colorStartIdx_ && colorStartIdx_ + _idx < colorEndIdx_)
{
glColor(translator_->index2color(colorStartIdx_ + _idx));
//glColor(translator_->index2color(colorStartIdx_ + _idx));
return true;
}
return false;
......
......@@ -73,6 +73,7 @@
namespace ACG {
class GLState;
//== CLASS DEFINITION =========================================================
......@@ -87,10 +88,9 @@ public:
ColorStack();
/// Destructor.
~ColorStack();
/// init (takes current GL context/ like glInitNames (); glPushName (0))
void initialize();
void initialize(ACG::GLState*);
/// has it been initialized?
bool initialized() const { return initialized_; }
......
......@@ -60,6 +60,7 @@
#include "ColorTranslator.hh"
#include <ACG/GL/GLState.hh>
#include <iostream>
#include <limits>
......@@ -75,13 +76,22 @@ namespace ACG {
void
ColorTranslator::
initialize()
initialize(ACG::GLState* _state)
{
glGetIntegerv( GL_RED_BITS, &red_bits_ );
glGetIntegerv( GL_GREEN_BITS, &green_bits_ );
glGetIntegerv( GL_BLUE_BITS, &blue_bits_ );
glGetIntegerv( GL_ALPHA_BITS, &alpha_bits_ );
if(_state->compatibilityProfile())
{
glGetIntegerv( GL_RED_BITS, &red_bits_ );
glGetIntegerv( GL_GREEN_BITS, &green_bits_ );
glGetIntegerv( GL_BLUE_BITS, &blue_bits_ );
glGetIntegerv( GL_ALPHA_BITS, &alpha_bits_ );
}
else
{ //only up to 8 bits are supported as of now, so hardcode them for core profiles
red_bits_ = 8;
green_bits_ = 8;
blue_bits_ = 8;
alpha_bits_ = 8;
}
// We currently only support up to 8 bits per channel (
if (red_bits_ > 8) red_bits_ = 8;
if (green_bits_ > 8) green_bits_ = 8;
......
......@@ -71,6 +71,7 @@
namespace ACG {
class GLState;
//== CLASS DEFINITION =========================================================
......@@ -97,7 +98,7 @@ public:
/// init (takes current GL context to get the component sizes)
/// Can't use constructor as we might not have a context at this point.
void initialize();
void initialize(ACG::GLState*);
/// has it been initialized?
bool initialized() const { return initialized_; }
......
......@@ -57,6 +57,7 @@ DrawMeshBase::DrawMeshBase() :
numTris_(0), numVerts_(0),
meshComp_(0),
lineIBO_(0),
heVBO_(0),
indexType_(0),
pickVertexIBO_(0) {
......@@ -70,6 +71,7 @@ DrawMeshBase::~DrawMeshBase() {
if (vbo_) glDeleteBuffersARB(1, &vbo_);
if (ibo_) glDeleteBuffersARB(1, &ibo_);
if (lineIBO_) glDeleteBuffersARB(1, &lineIBO_);
if (heVBO_) glDeleteBuffersARB(1, &heVBO_);
delete vertexDecl_;
delete vertexDeclEdgeCol_;
......@@ -106,6 +108,18 @@ void DrawMeshBase::bindLineIbo() {
ACG::GLState::bindBufferARB(GL_ELEMENT_ARRAY_BUFFER, lineIBO_);
}
void DrawMeshBase::bindHEVbo() {
glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&prevVBO_);
if (!heVBO_)
glGenBuffersARB(1, &heVBO_);
ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, heVBO_);
}
void DrawMeshBase::unbindHEVbo() {
ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, prevVBO_);
}
void DrawMeshBase::bindPickVertexIbo() {
if (!pickVertexIBO_)
glGenBuffersARB(1, &pickVertexIBO_);
......@@ -131,6 +145,13 @@ void DrawMeshBase::fillLineBuffer(size_t n_edges, void *data) {
data, GL_STATIC_DRAW_ARB);
}
void DrawMeshBase::fillHEVBO(size_t numberOfElements_, size_t sizeOfElements_, void* data_)
{
bindHEVbo();
glBufferData(GL_ARRAY_BUFFER,numberOfElements_ * sizeOfElements_, data_, GL_STATIC_DRAW);
unbindHEVbo();
}
void DrawMeshBase::fillVertexBuffer() {
if (!vertices_.empty())
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts_ * vertexDecl_->getVertexStride(), &vertices_[0], GL_STATIC_DRAW_ARB);
......
......@@ -97,10 +97,13 @@ class ACGDLLEXPORT DrawMeshBase {
void bindVbo();
void bindIbo();
void bindLineIbo();
void bindHEVbo();
void unbindHEVbo();
void bindPickVertexIbo();
void createIndexBuffer();
void fillLineBuffer(size_t n_edges, void *data);
void fillHEVBO(size_t numberOfElements_, size_t sizeOfElements_, void* data_);
void fillVertexBuffer();
void fillInvVertexMap(size_t n_vertices, void *data);
......@@ -132,6 +135,10 @@ class ACGDLLEXPORT DrawMeshBase {
/// index buffer used in Wireframe / Hiddenline mode
GLuint lineIBO_;
/// vbo for halfedge rendering, as they are offset
GLuint heVBO_;
//previously bound buffer
GLint prevVBO_;
/// support for 2 and 4 byte unsigned integers
GLenum indexType_;
......@@ -212,6 +219,11 @@ public:
*/
GLuint getIBO();
/**
* @brief getHEVBO get VBO which stores Halfedges with offset
* @return GLuint the VBO
*/
GLuint getHEVBO(){return heVBO_;}
/** \brief get vertex declaration of the current vbo layout
*/
......@@ -488,7 +500,6 @@ public:
*/
void updatePickingVertices_opt(ACG::GLState& _state);
#ifdef GL_ARB_texture_buffer_object
TextureBuffer* pickVertexMap_opt(){
if ( pickVertexMapTBO_.is_valid() )
......@@ -499,7 +510,6 @@ public:
}
}
#endif // GL_ARB_texture_buffer_object
private:
......@@ -509,10 +519,8 @@ private:
std::vector< ACG::Vec4uc > pickVertColBuf_;
#ifdef GL_ARB_texture_buffer_object
// map from vbo vertex id to openmesh vertex id
TextureBuffer pickVertexMapTBO_;
#endif // GL_ARB_texture_buffer_object
// vertex picking shader
GLSL::Program* pickVertexShader_;
......@@ -642,7 +650,6 @@ public:
*/
void updatePickingFaces_opt(ACG::GLState& _state );
#ifdef GL_ARB_texture_buffer_object
TextureBuffer* pickFaceTriangleMap_opt(){
if ( pickFaceTriToFaceMapTBO_.is_valid() )
......@@ -652,7 +659,6 @@ public:
return 0;
}
}
#endif
private:
......@@ -660,10 +666,8 @@ private:
std::vector< ACG::Vec3f > pickFaceVertexBuf_;
std::vector< ACG::Vec4uc > pickFaceColBuf_;
#ifdef GL_ARB_texture_buffer_object