Refactored opengl parts
This commit is contained in:
parent
7d4989b670
commit
9cece93ec1
9 changed files with 65 additions and 45 deletions
|
@ -4,7 +4,7 @@
|
|||
#include "OpenGLShaderProgram.h"
|
||||
#include "OpenGLVertexArray.h"
|
||||
|
||||
OpenGLPart::OpenGLPart(OpenGLRenderer *renderer) : renderer(renderer) {
|
||||
OpenGLPart::OpenGLPart(OpenGLRenderer *renderer, const string &name) : renderer(renderer), name(name) {
|
||||
}
|
||||
|
||||
OpenGLPart::~OpenGLPart() {
|
||||
|
@ -30,6 +30,12 @@ void OpenGLPart::destroy() {
|
|||
void OpenGLPart::interrupt() {
|
||||
}
|
||||
|
||||
void OpenGLPart::pause() {
|
||||
}
|
||||
|
||||
void OpenGLPart::resume() {
|
||||
}
|
||||
|
||||
OpenGLShaderProgram *OpenGLPart::createShader(const string &name) {
|
||||
OpenGLShaderProgram *program = new OpenGLShaderProgram(name, renderer);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace opengl {
|
|||
*/
|
||||
class OPENGLSHARED_EXPORT OpenGLPart {
|
||||
public:
|
||||
OpenGLPart(OpenGLRenderer *renderer);
|
||||
OpenGLPart(OpenGLRenderer *renderer, const string &name);
|
||||
virtual ~OpenGLPart();
|
||||
|
||||
// Initialize the part rendering (create shaders, prepare static textures...)
|
||||
|
@ -32,8 +32,18 @@ class OPENGLSHARED_EXPORT OpenGLPart {
|
|||
// Interrupt the rendering
|
||||
virtual void interrupt();
|
||||
|
||||
// Temporarily pause the background working
|
||||
virtual void pause();
|
||||
|
||||
// Resume the background working
|
||||
virtual void resume();
|
||||
|
||||
void updateScenery(bool onlyCommon = false);
|
||||
|
||||
inline const string &getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Create a shader program.
|
||||
|
@ -55,6 +65,7 @@ class OPENGLSHARED_EXPORT OpenGLPart {
|
|||
OpenGLRenderer *renderer;
|
||||
|
||||
private:
|
||||
string name;
|
||||
map<string, OpenGLShaderProgram *> shaders;
|
||||
vector<OpenGLVertexArray *> arrays;
|
||||
};
|
||||
|
|
|
@ -38,23 +38,22 @@ OpenGLRenderer::OpenGLRenderer(Scenery *scenery) : SoftwareRenderer(scenery) {
|
|||
shared_state->set("viewDistance", 300.0);
|
||||
shared_state->set("exposure", 1.2);
|
||||
|
||||
skybox = new OpenGLSkybox(this);
|
||||
water = new OpenGLWater(this);
|
||||
terrain = new OpenGLTerrain(this);
|
||||
parts.push_back(skybox = new OpenGLSkybox(this));
|
||||
parts.push_back(water = new OpenGLWater(this));
|
||||
parts.push_back(terrain = new OpenGLTerrain(this));
|
||||
}
|
||||
|
||||
OpenGLRenderer::~OpenGLRenderer() {
|
||||
terrain->interrupt();
|
||||
water->interrupt();
|
||||
skybox->interrupt();
|
||||
for (auto part : parts) {
|
||||
part->interrupt();
|
||||
}
|
||||
|
||||
delete mouse_projected;
|
||||
|
||||
delete view_matrix;
|
||||
|
||||
delete skybox;
|
||||
delete water;
|
||||
delete terrain;
|
||||
for (auto part : parts) {
|
||||
delete part;
|
||||
}
|
||||
|
||||
delete functions;
|
||||
delete shared_state;
|
||||
|
@ -70,11 +69,11 @@ void OpenGLRenderer::checkForErrors(const string &domain) {
|
|||
void OpenGLRenderer::destroy() {
|
||||
shared_state->destroy(functions);
|
||||
|
||||
skybox->destroy();
|
||||
terrain->destroy();
|
||||
water->destroy();
|
||||
for (auto part : parts) {
|
||||
part->destroy();
|
||||
}
|
||||
|
||||
checkForErrors("stopping");
|
||||
checkForErrors("destroy");
|
||||
}
|
||||
|
||||
void OpenGLRenderer::initialize() {
|
||||
|
@ -92,14 +91,10 @@ void OpenGLRenderer::initialize() {
|
|||
getLightingManager()->setSpecularity(false);
|
||||
getGodRaysSampler()->setEnabled(false);
|
||||
|
||||
skybox->initialize();
|
||||
skybox->updateScenery();
|
||||
|
||||
water->initialize();
|
||||
water->updateScenery();
|
||||
|
||||
terrain->initialize();
|
||||
terrain->updateScenery();
|
||||
for (auto part : parts) {
|
||||
part->initialize();
|
||||
part->updateScenery();
|
||||
}
|
||||
|
||||
cameraChangeEvent(render_camera);
|
||||
|
||||
|
@ -168,14 +163,10 @@ void OpenGLRenderer::paint(bool clear) {
|
|||
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
skybox->render();
|
||||
checkForErrors("skybox");
|
||||
|
||||
terrain->render();
|
||||
checkForErrors("terrain");
|
||||
|
||||
water->render();
|
||||
checkForErrors("water");
|
||||
for (auto part : parts) {
|
||||
part->render();
|
||||
checkForErrors(part->getName());
|
||||
}
|
||||
|
||||
if (mouse_tracking) {
|
||||
updateMouseProjection();
|
||||
|
@ -193,22 +184,30 @@ bool OpenGLRenderer::stop() {
|
|||
|
||||
void OpenGLRenderer::reset() {
|
||||
if (ready) {
|
||||
skybox->updateScenery();
|
||||
water->updateScenery();
|
||||
terrain->updateScenery();
|
||||
for (auto part : parts) {
|
||||
part->updateScenery();
|
||||
}
|
||||
|
||||
cameraChangeEvent(render_camera);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLRenderer::pause() {
|
||||
if (not paused) {
|
||||
paused = true;
|
||||
terrain->pause();
|
||||
for (auto part : parts) {
|
||||
part->pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLRenderer::resume() {
|
||||
if (paused) {
|
||||
for (auto part : parts) {
|
||||
part->resume();
|
||||
}
|
||||
paused = false;
|
||||
terrain->resume();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLRenderer::setMouseLocation(int x, int y) {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "SoftwareRenderer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class QMatrix4x4;
|
||||
|
||||
namespace paysages {
|
||||
|
@ -135,6 +137,8 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer {
|
|||
OpenGLSkybox *skybox;
|
||||
OpenGLWater *water;
|
||||
OpenGLTerrain *terrain;
|
||||
|
||||
vector<OpenGLPart *> parts;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "AtmosphereModelBruneton.h"
|
||||
#include "FloatNode.h"
|
||||
|
||||
OpenGLSkybox::OpenGLSkybox(OpenGLRenderer *renderer) : OpenGLPart(renderer) {
|
||||
OpenGLSkybox::OpenGLSkybox(OpenGLRenderer *renderer) : OpenGLPart(renderer, "skybox") {
|
||||
program = createShader("skybox");
|
||||
program->addVertexSource("skybox");
|
||||
program->addFragmentSource("atmosphere");
|
||||
|
|
|
@ -32,7 +32,7 @@ class ChunkMaintenanceThreads : public ParallelPool {
|
|||
OpenGLTerrain *terrain;
|
||||
};
|
||||
|
||||
OpenGLTerrain::OpenGLTerrain(OpenGLRenderer *renderer) : OpenGLPart(renderer) {
|
||||
OpenGLTerrain::OpenGLTerrain(OpenGLRenderer *renderer) : OpenGLPart(renderer, "terrain") {
|
||||
work = new ChunkMaintenanceThreads(this);
|
||||
paused = false;
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ class OPENGLSHARED_EXPORT OpenGLTerrain : public OpenGLPart, public DefinitionWa
|
|||
virtual void interrupt() override;
|
||||
virtual void destroy() override;
|
||||
|
||||
void pause();
|
||||
void resume();
|
||||
virtual void pause() override;
|
||||
virtual void resume() override;
|
||||
inline bool isPaused() const {
|
||||
return paused;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "FloatDiff.h"
|
||||
#include "IntNode.h"
|
||||
|
||||
OpenGLWater::OpenGLWater(OpenGLRenderer *renderer) : OpenGLPart(renderer) {
|
||||
OpenGLWater::OpenGLWater(OpenGLRenderer *renderer) : OpenGLPart(renderer, "water") {
|
||||
enabled = true;
|
||||
|
||||
program = createShader("water");
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace paysages {
|
||||
namespace opengl {
|
||||
class WidgetExplorer;
|
||||
class OpenGLRenderer;
|
||||
class OpenGLPart;
|
||||
class OpenGLShaderProgram;
|
||||
class OpenGLSharedState;
|
||||
class OpenGLVariable;
|
||||
|
|
Loading…
Reference in a new issue