From 8098482d5047ca5a5e608f24c91f3eb90eb3976f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 23 Dec 2013 10:26:29 +0100 Subject: [PATCH] Retrograded to OpenGL 3.0 functions --- src/render/opengl/OpenGLRenderer.cpp | 64 +++++++++++++---------- src/render/opengl/OpenGLRenderer.h | 8 +-- src/render/opengl/OpenGLShaderProgram.cpp | 2 +- src/render/opengl/OpenGLShaderProgram.h | 3 +- src/render/opengl/OpenGLVariable.cpp | 8 +-- src/render/opengl/opengl_global.h | 5 ++ 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 0600be9..d3e943d 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -1,6 +1,6 @@ #include "OpenGLRenderer.h" -#include +#include OPENGL_FUNCTIONS_INCLUDE #include "CameraDefinition.h" #include "OpenGLSharedState.h" #include "OpenGLSkybox.h" @@ -9,7 +9,9 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery): SoftwareRenderer(scenery) { - functions = new QOpenGLFunctions_3_2_Core(); + ready = false; + + functions = new OpenGLFunctions(); shared_state = new OpenGLSharedState(); skybox = new OpenGLSkybox(this); @@ -27,50 +29,58 @@ OpenGLRenderer::~OpenGLRenderer() void OpenGLRenderer::initialize() { - // TODO Check return value - functions->initializeOpenGLFunctions(); + ready = functions->initializeOpenGLFunctions(); - functions->glClearColor(0.0, 0.0, 0.0, 0.0); + if (ready) + { + functions->glClearColor(0.0, 0.0, 0.0, 0.0); - functions->glDisable(GL_LIGHTING); + functions->glDisable(GL_LIGHTING); - functions->glFrontFace(GL_CCW); - functions->glCullFace(GL_BACK); - functions->glEnable(GL_CULL_FACE); + functions->glFrontFace(GL_CCW); + functions->glCullFace(GL_BACK); + functions->glEnable(GL_CULL_FACE); - functions->glDepthFunc(GL_LESS); - functions->glDepthMask(1); - functions->glEnable(GL_DEPTH_TEST); + functions->glDepthFunc(GL_LESS); + functions->glDepthMask(1); + functions->glEnable(GL_DEPTH_TEST); - functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - functions->glEnable(GL_LINE_SMOOTH); - functions->glLineWidth(1.0); + functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + functions->glEnable(GL_LINE_SMOOTH); + functions->glLineWidth(1.0); - functions->glDisable(GL_FOG); + functions->glDisable(GL_FOG); - functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - prepare(); + prepare(); - skybox->initialize(); - skybox->updateScenery(); + skybox->initialize(); + skybox->updateScenery(); - water->initialize(); - water->updateScenery(); + water->initialize(); + water->updateScenery(); + } } void OpenGLRenderer::resize(int width, int height) { - functions->glViewport(0, 0, width, height); + if (ready) + { + functions->glViewport(0, 0, width, height); + } } void OpenGLRenderer::paint() { - functions->glClearColor(0.0, 0.0, 0.0, 0.0); - functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (ready) + { + functions->glClearColor(0.0, 0.0, 0.0, 0.0); + functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - skybox->render(); - water->render(); + skybox->render(); + water->render(); + } } void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera) diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index 2069ed1..fc4f7de 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -5,8 +5,6 @@ #include "SoftwareRenderer.h" -class QOpenGLFunctions_3_2_Core; - namespace paysages { namespace opengl { @@ -25,14 +23,16 @@ public: void cameraChangeEvent(CameraDefinition* camera); - inline QOpenGLFunctions_3_2_Core* getOpenGlFunctions() const {return functions;} + inline OpenGLFunctions* getOpenGlFunctions() const {return functions;} inline OpenGLSharedState* getSharedState() const {return shared_state;} virtual double getPrecision(const Vector3 &location) override; virtual Color applyMediumTraversal(Vector3 location, Color color) override; private: - QOpenGLFunctions_3_2_Core* functions; + bool ready; + + OpenGLFunctions* functions; OpenGLSharedState* shared_state; OpenGLSkybox* skybox; diff --git a/src/render/opengl/OpenGLShaderProgram.cpp b/src/render/opengl/OpenGLShaderProgram.cpp index dc326a1..6df6534 100644 --- a/src/render/opengl/OpenGLShaderProgram.cpp +++ b/src/render/opengl/OpenGLShaderProgram.cpp @@ -1,7 +1,7 @@ #include "OpenGLShaderProgram.h" +#include OPENGL_FUNCTIONS_INCLUDE #include -#include #include #include "OpenGLRenderer.h" #include "OpenGLSharedState.h" diff --git a/src/render/opengl/OpenGLShaderProgram.h b/src/render/opengl/OpenGLShaderProgram.h index 2b4bfd1..9a00bef 100644 --- a/src/render/opengl/OpenGLShaderProgram.h +++ b/src/render/opengl/OpenGLShaderProgram.h @@ -6,7 +6,6 @@ #include class QOpenGLShaderProgram; -class QOpenGLFunctions_3_2_Core; namespace paysages { namespace opengl { @@ -39,7 +38,7 @@ private: QString name; QOpenGLShaderProgram* program; - QOpenGLFunctions_3_2_Core* functions; + OpenGLFunctions* functions; std::string source_vertex; std::string source_fragment; diff --git a/src/render/opengl/OpenGLVariable.cpp b/src/render/opengl/OpenGLVariable.cpp index 11e97a5..be33aff 100644 --- a/src/render/opengl/OpenGLVariable.cpp +++ b/src/render/opengl/OpenGLVariable.cpp @@ -1,8 +1,8 @@ #include "OpenGLVariable.h" -#include +#include OPENGL_FUNCTIONS_INCLUDE #include -#include +#include #include "OpenGLRenderer.h" #include "OpenGLShaderProgram.h" #include "Vector3.h" @@ -22,7 +22,7 @@ OpenGLVariable::OpenGLVariable(const std::string &name): void OpenGLVariable::apply(OpenGLShaderProgram *program, int &texture_unit) { QOpenGLShaderProgram* pr = program->getProgram(); - QOpenGLFunctions_3_2_Core* functions = program->getRenderer()->getOpenGlFunctions(); + OpenGLFunctions* functions = program->getRenderer()->getOpenGlFunctions(); if (texture_toupload) { @@ -133,7 +133,7 @@ void OpenGLVariable::set(const Color &color) void OpenGLVariable::uploadTexture(OpenGLRenderer* renderer) { - QOpenGLFunctions_3_2_Core* functions = renderer->getOpenGlFunctions(); + OpenGLFunctions* functions = renderer->getOpenGlFunctions(); assert(type == TYPE_TEXTURE_2D or type == TYPE_TEXTURE_3D or type == TYPE_TEXTURE_4D); diff --git a/src/render/opengl/opengl_global.h b/src/render/opengl/opengl_global.h index d8f0cef..d74c89d 100644 --- a/src/render/opengl/opengl_global.h +++ b/src/render/opengl/opengl_global.h @@ -25,4 +25,9 @@ namespace opengl { } using namespace paysages::opengl; +//#define OpenGLFunctions QOpenGLFunctions_3_2_Core +#define OpenGLFunctions QOpenGLFunctions_3_0 +#define OPENGL_FUNCTIONS_INCLUDE +class OpenGLFunctions; + #endif // OPENGL_GLOBAL_H