Retrograded to OpenGL 3.0 functions

This commit is contained in:
Michaël Lemaire 2013-12-23 10:26:29 +01:00 committed by Michael Lemaire
parent 39789aea3f
commit 8098482d50
6 changed files with 52 additions and 38 deletions

View file

@ -1,6 +1,6 @@
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include <QOpenGLFunctions_3_2_Core> #include OPENGL_FUNCTIONS_INCLUDE
#include "CameraDefinition.h" #include "CameraDefinition.h"
#include "OpenGLSharedState.h" #include "OpenGLSharedState.h"
#include "OpenGLSkybox.h" #include "OpenGLSkybox.h"
@ -9,7 +9,9 @@
OpenGLRenderer::OpenGLRenderer(Scenery* scenery): OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
SoftwareRenderer(scenery) SoftwareRenderer(scenery)
{ {
functions = new QOpenGLFunctions_3_2_Core(); ready = false;
functions = new OpenGLFunctions();
shared_state = new OpenGLSharedState(); shared_state = new OpenGLSharedState();
skybox = new OpenGLSkybox(this); skybox = new OpenGLSkybox(this);
@ -27,9 +29,10 @@ OpenGLRenderer::~OpenGLRenderer()
void OpenGLRenderer::initialize() void OpenGLRenderer::initialize()
{ {
// TODO Check return value ready = functions->initializeOpenGLFunctions();
functions->initializeOpenGLFunctions();
if (ready)
{
functions->glClearColor(0.0, 0.0, 0.0, 0.0); functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glDisable(GL_LIGHTING); functions->glDisable(GL_LIGHTING);
@ -57,20 +60,27 @@ void OpenGLRenderer::initialize()
water->initialize(); water->initialize();
water->updateScenery(); water->updateScenery();
}
} }
void OpenGLRenderer::resize(int width, int height) void OpenGLRenderer::resize(int width, int height)
{ {
if (ready)
{
functions->glViewport(0, 0, width, height); functions->glViewport(0, 0, width, height);
}
} }
void OpenGLRenderer::paint() void OpenGLRenderer::paint()
{ {
if (ready)
{
functions->glClearColor(0.0, 0.0, 0.0, 0.0); functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
skybox->render(); skybox->render();
water->render(); water->render();
}
} }
void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera) void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera)

View file

@ -5,8 +5,6 @@
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
class QOpenGLFunctions_3_2_Core;
namespace paysages { namespace paysages {
namespace opengl { namespace opengl {
@ -25,14 +23,16 @@ public:
void cameraChangeEvent(CameraDefinition* camera); 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;} inline OpenGLSharedState* getSharedState() const {return shared_state;}
virtual double getPrecision(const Vector3 &location) override; virtual double getPrecision(const Vector3 &location) override;
virtual Color applyMediumTraversal(Vector3 location, Color color) override; virtual Color applyMediumTraversal(Vector3 location, Color color) override;
private: private:
QOpenGLFunctions_3_2_Core* functions; bool ready;
OpenGLFunctions* functions;
OpenGLSharedState* shared_state; OpenGLSharedState* shared_state;
OpenGLSkybox* skybox; OpenGLSkybox* skybox;

View file

@ -1,7 +1,7 @@
#include "OpenGLShaderProgram.h" #include "OpenGLShaderProgram.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QOpenGLFunctions_3_2_Core>
#include <QDir> #include <QDir>
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include "OpenGLSharedState.h" #include "OpenGLSharedState.h"

View file

@ -6,7 +6,6 @@
#include <QString> #include <QString>
class QOpenGLShaderProgram; class QOpenGLShaderProgram;
class QOpenGLFunctions_3_2_Core;
namespace paysages { namespace paysages {
namespace opengl { namespace opengl {
@ -39,7 +38,7 @@ private:
QString name; QString name;
QOpenGLShaderProgram* program; QOpenGLShaderProgram* program;
QOpenGLFunctions_3_2_Core* functions; OpenGLFunctions* functions;
std::string source_vertex; std::string source_vertex;
std::string source_fragment; std::string source_fragment;

View file

@ -1,8 +1,8 @@
#include "OpenGLVariable.h" #include "OpenGLVariable.h"
#include <cassert> #include OPENGL_FUNCTIONS_INCLUDE
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QOpenGLFunctions_3_2_Core> #include <cassert>
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include "OpenGLShaderProgram.h" #include "OpenGLShaderProgram.h"
#include "Vector3.h" #include "Vector3.h"
@ -22,7 +22,7 @@ OpenGLVariable::OpenGLVariable(const std::string &name):
void OpenGLVariable::apply(OpenGLShaderProgram *program, int &texture_unit) void OpenGLVariable::apply(OpenGLShaderProgram *program, int &texture_unit)
{ {
QOpenGLShaderProgram* pr = program->getProgram(); QOpenGLShaderProgram* pr = program->getProgram();
QOpenGLFunctions_3_2_Core* functions = program->getRenderer()->getOpenGlFunctions(); OpenGLFunctions* functions = program->getRenderer()->getOpenGlFunctions();
if (texture_toupload) if (texture_toupload)
{ {
@ -133,7 +133,7 @@ void OpenGLVariable::set(const Color &color)
void OpenGLVariable::uploadTexture(OpenGLRenderer* renderer) 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); assert(type == TYPE_TEXTURE_2D or type == TYPE_TEXTURE_3D or type == TYPE_TEXTURE_4D);

View file

@ -25,4 +25,9 @@ namespace opengl {
} }
using namespace paysages::opengl; using namespace paysages::opengl;
//#define OpenGLFunctions QOpenGLFunctions_3_2_Core
#define OpenGLFunctions QOpenGLFunctions_3_0
#define OPENGL_FUNCTIONS_INCLUDE <OpenGLFunctions>
class OpenGLFunctions;
#endif // OPENGL_GLOBAL_H #endif // OPENGL_GLOBAL_H