From 479dcb03ac1e4fc9538d7664caf80fb55bb697f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 10 Dec 2015 23:41:42 +0100 Subject: [PATCH 1/4] Added opengl resources deleting at exit (textures, arrays...) --- src/basics/Vector3.cpp | 4 +-- src/basics/Vector3.h | 3 +- src/definition/AtmosphereDefinition.cpp | 5 ++- src/definition/Scenery.cpp | 3 +- .../modeler/quickapp/MainModelerWindow.cpp | 28 ++++++---------- .../modeler/quickapp/MainModelerWindow.h | 3 ++ src/interface/modeler/quickapp/OpenGLView.cpp | 5 +++ src/interface/modeler/quickapp/OpenGLView.h | 3 ++ src/render/opengl/OpenGLPart.cpp | 23 ++++++++++--- src/render/opengl/OpenGLPart.h | 5 +++ src/render/opengl/OpenGLRenderer.cpp | 24 +++++++++++++- src/render/opengl/OpenGLRenderer.h | 32 ++++++++++++++++--- src/render/opengl/OpenGLShaderProgram.cpp | 4 +++ src/render/opengl/OpenGLShaderProgram.h | 7 ++++ src/render/opengl/OpenGLSharedState.cpp | 6 ++++ src/render/opengl/OpenGLSharedState.h | 19 +++++++---- src/render/opengl/OpenGLTerrain.cpp | 9 +++++- src/render/opengl/OpenGLTerrain.h | 1 + src/render/opengl/OpenGLTerrainChunk.cpp | 16 +++++++--- src/render/opengl/OpenGLTerrainChunk.h | 7 ++++ src/render/opengl/OpenGLVariable.cpp | 16 +++++++--- src/render/opengl/OpenGLVariable.h | 7 ++++ src/render/opengl/OpenGLVertexArray.cpp | 21 ++++++++---- src/render/opengl/OpenGLVertexArray.h | 2 +- src/system/RandomGenerator.cpp | 10 +++--- src/system/system_global.h | 2 +- src/tests/OpenGLTerrainChunk_Test.cpp | 3 +- 27 files changed, 203 insertions(+), 65 deletions(-) diff --git a/src/basics/Vector3.cpp b/src/basics/Vector3.cpp index 41e84ee..de11720 100644 --- a/src/basics/Vector3.cpp +++ b/src/basics/Vector3.cpp @@ -117,7 +117,7 @@ Vector3 Vector3::midPointTo(const Vector3 &other) const { Vector3 Vector3::randomInSphere(double radius, bool only_surface, RandomGenerator &random) { // TODO More uniform spatial repartition // The current randomization clusters result near the center and at the poles - VectorSpherical vec = {only_surface ? radius : random.genDouble() * radius, - (random.genDouble() - 0.5) * M_PI, random.genDouble() * M_2PI}; + VectorSpherical vec = {only_surface ? radius : random.genDouble() * radius, (random.genDouble() - 0.5) * M_PI, + random.genDouble() * M_2PI}; return Vector3(vec); } diff --git a/src/basics/Vector3.h b/src/basics/Vector3.h index c04b9d0..0776581 100644 --- a/src/basics/Vector3.h +++ b/src/basics/Vector3.h @@ -71,7 +71,8 @@ class BASICSSHARED_EXPORT Vector3 { * * If *only_surface* is true, produce a vector with *radius* as length. */ - static Vector3 randomInSphere(double radius = 1.0, bool only_surface = false, RandomGenerator &random = RandomGeneratorDefault); + static Vector3 randomInSphere(double radius = 1.0, bool only_surface = false, + RandomGenerator &random = RandomGeneratorDefault); public: // TODO Make private diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index 9d4e691..8cbf3cc 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -153,9 +153,8 @@ void AtmosphereDefinition::generateStars(int count, RandomGenerator &random) { for (int i = 0; i < count; ++i) { Star star; - star.location = - Vector3((random.genDouble() - 0.5) * 100000.0, (random.genDouble() * 0.5) * 100000.0, - (random.genDouble() - 0.5) * 100000.0); + star.location = Vector3((random.genDouble() - 0.5) * 100000.0, (random.genDouble() * 0.5) * 100000.0, + (random.genDouble() - 0.5) * 100000.0); if (star.location.getNorm() < 30000.0) { i--; continue; diff --git a/src/definition/Scenery.cpp b/src/definition/Scenery.cpp index 4bb4bc2..77ee158 100644 --- a/src/definition/Scenery.cpp +++ b/src/definition/Scenery.cpp @@ -108,8 +108,7 @@ void Scenery::autoPreset(RandomGenerator &random) { Logs::debug() << "[Definition] New scenery generated from seed " << random.getSeed() << std::endl; } -void Scenery::autoPreset(unsigned int seed) -{ +void Scenery::autoPreset(unsigned int seed) { RandomGenerator random(seed); autoPreset(random); } diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index f8559b1..c1e1965 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -42,23 +42,11 @@ MainModelerWindow::MainModelerWindow() { render_process = new RenderProcess(this, render_preview_provider); - // Bind file buttons - QObject *button_new = findQmlObject("tool_file_new"); - if (button_new) { - connect(button_new, SIGNAL(clicked()), this, SLOT(newFile())); - } - QObject *button_save = findQmlObject("tool_file_save"); - if (button_save) { - connect(button_save, SIGNAL(clicked()), this, SLOT(saveFile())); - } - QObject *button_load = findQmlObject("tool_file_load"); - if (button_load) { - connect(button_load, SIGNAL(clicked()), this, SLOT(loadFile())); - } - QObject *button_exit = findQmlObject("tool_file_exit"); - if (button_exit) { - connect(button_exit, SIGNAL(clicked()), this, SLOT(exit())); - } + connectQmlSignal("tool_file_new", SIGNAL(clicked()), this, SLOT(newFile())); + connectQmlSignal("tool_file_save", SIGNAL(clicked()), this, SLOT(saveFile())); + connectQmlSignal("tool_file_load", SIGNAL(clicked()), this, SLOT(loadFile())); + connectQmlSignal("tool_file_exit", SIGNAL(clicked()), this, SLOT(exit())); + connectQmlSignal("root", SIGNAL(stopped()), this, SLOT(effectiveExit())); } MainModelerWindow::~MainModelerWindow() { @@ -126,7 +114,7 @@ void MainModelerWindow::loadFile() { } void MainModelerWindow::exit() { - close(); + renderer->stop(); } void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) { @@ -178,3 +166,7 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) { } } } + +void MainModelerWindow::effectiveExit() { + close(); +} diff --git a/src/interface/modeler/quickapp/MainModelerWindow.h b/src/interface/modeler/quickapp/MainModelerWindow.h index 73297ce..8850865 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.h +++ b/src/interface/modeler/quickapp/MainModelerWindow.h @@ -40,6 +40,9 @@ class MainModelerWindow : public QQuickView { protected: virtual void keyReleaseEvent(QKeyEvent *event) override; + protected slots: + void effectiveExit(); + private: Scenery *scenery; OpenGLRenderer *renderer; diff --git a/src/interface/modeler/quickapp/OpenGLView.cpp b/src/interface/modeler/quickapp/OpenGLView.cpp index 3380d4a..89d6c3d 100644 --- a/src/interface/modeler/quickapp/OpenGLView.cpp +++ b/src/interface/modeler/quickapp/OpenGLView.cpp @@ -41,6 +41,11 @@ void OpenGLView::paint() { return; } + if (renderer->isStopped()) { + emit stopped(); + return; + } + if (not initialized or not renderer) { renderer->initialize(); initialized = true; diff --git a/src/interface/modeler/quickapp/OpenGLView.h b/src/interface/modeler/quickapp/OpenGLView.h index d62fd14..605b030 100644 --- a/src/interface/modeler/quickapp/OpenGLView.h +++ b/src/interface/modeler/quickapp/OpenGLView.h @@ -19,6 +19,9 @@ class OpenGLView : public QQuickItem { void handleResize(); void handleSceneGraphReady(); +signals: + void stopped(); + protected: virtual void wheelEvent(QWheelEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override; diff --git a/src/render/opengl/OpenGLPart.cpp b/src/render/opengl/OpenGLPart.cpp index a0bc65e..997e132 100644 --- a/src/render/opengl/OpenGLPart.cpp +++ b/src/render/opengl/OpenGLPart.cpp @@ -1,5 +1,6 @@ #include "OpenGLPart.h" +#include "OpenGLRenderer.h" #include "OpenGLShaderProgram.h" #include "OpenGLVertexArray.h" @@ -7,14 +8,25 @@ OpenGLPart::OpenGLPart(OpenGLRenderer *renderer) : renderer(renderer) { } OpenGLPart::~OpenGLPart() { - for (auto &pair: shaders) { + for (auto pair : shaders) { delete pair.second; } - for (auto &array: arrays) { + for (auto array : arrays) { delete array; } } +void OpenGLPart::destroy() { + OpenGLFunctions *functions = getFunctions(); + + for (auto shader : shaders) { + shader.second->destroy(functions); + } + for (auto array : arrays) { + array->destroy(functions); + } +} + void OpenGLPart::interrupt() { } @@ -29,13 +41,16 @@ OpenGLShaderProgram *OpenGLPart::createShader(const std::string &name) { } } -OpenGLVertexArray *OpenGLPart::createVertexArray(bool has_uv, bool strip) -{ +OpenGLVertexArray *OpenGLPart::createVertexArray(bool has_uv, bool strip) { OpenGLVertexArray *result = new OpenGLVertexArray(has_uv, strip); arrays.push_back(result); return result; } +OpenGLFunctions *OpenGLPart::getFunctions() { + return renderer->getOpenGlFunctions(); +} + void OpenGLPart::updateScenery(bool onlyCommon) { // Let subclass do its own collecting if (not onlyCommon) { diff --git a/src/render/opengl/OpenGLPart.h b/src/render/opengl/OpenGLPart.h index bea0e1a..b37a89d 100644 --- a/src/render/opengl/OpenGLPart.h +++ b/src/render/opengl/OpenGLPart.h @@ -26,6 +26,9 @@ class OPENGLSHARED_EXPORT OpenGLPart { // Do the rendering virtual void render() = 0; + // Free opengl resources generated in context (like textures...) + virtual void destroy(); + // Interrupt the rendering virtual void interrupt(); @@ -46,6 +49,8 @@ class OPENGLSHARED_EXPORT OpenGLPart { */ OpenGLVertexArray *createVertexArray(bool has_uv, bool strip); + OpenGLFunctions *getFunctions(); + // Access to the main scenery renderer OpenGLRenderer *renderer; diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 61ed6ed..20549bb 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -18,6 +18,8 @@ OpenGLRenderer::OpenGLRenderer(Scenery *scenery) : SoftwareRenderer(scenery) { ready = false; paused = false; displayed = false; + stopping = false; + stopped = false; vp_width = 1; vp_height = 1; @@ -65,6 +67,16 @@ void OpenGLRenderer::checkForErrors(const std::string &domain) { } } +void OpenGLRenderer::destroy() { + shared_state->destroy(functions); + + skybox->destroy(); + terrain->destroy(); + water->destroy(); + + checkForErrors("stopping"); +} + void OpenGLRenderer::initialize() { ready = functions->initializeOpenGLFunctions(); @@ -145,7 +157,12 @@ void OpenGLRenderer::resize(int width, int height) { } void OpenGLRenderer::paint(bool clear) { - if (ready and not paused) { + if (stopping) { + if (not stopped) { + destroy(); + stopped = true; + } + } else if (ready and not paused) { checkForErrors("before_paint"); if (clear) { functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -169,6 +186,11 @@ void OpenGLRenderer::paint(bool clear) { } } +bool OpenGLRenderer::stop() { + stopping = true; + return stopped; +} + void OpenGLRenderer::reset() { if (ready) { skybox->updateScenery(); diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index c7ede8b..1fac9bc 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -10,8 +10,8 @@ class QMatrix4x4; namespace paysages { namespace opengl { -/*! - * \brief Scenery renderer in an OpenGL context. +/** + * Scenery renderer in an OpenGL context. */ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer { public: @@ -30,6 +30,12 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer { inline bool isDisplayed() const { return displayed; } + inline bool isStopping() const { + return stopping; + } + inline bool isStopped() const { + return stopped; + } /** * Check for errors in OpenGL context. @@ -38,10 +44,26 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer { */ void checkForErrors(const std::string &domain); + /** + * Release any allocated resource in the opengl context. + * + * Must be called in the opengl rendering thread, and before the destructor is called. + */ + void destroy(); + void initialize(); - void prepareOpenGLState(bool clear=true); + void prepareOpenGLState(bool clear = true); void resize(int width, int height); - void paint(bool clear=true); + void paint(bool clear = true); + + /** + * Ask for the rendering to stop gracefully. + * + * Returns true if the rendering is stopped and resources freed. + * + * This should be called in an idle loop, while it returns false. + */ + bool stop(); /** * Reset the whole state (when the scenery has been massively updated). @@ -95,6 +117,8 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer { bool ready; bool paused; bool displayed; + bool stopping; + bool stopped; int vp_width; int vp_height; diff --git a/src/render/opengl/OpenGLShaderProgram.cpp b/src/render/opengl/OpenGLShaderProgram.cpp index 39c7351..da06458 100644 --- a/src/render/opengl/OpenGLShaderProgram.cpp +++ b/src/render/opengl/OpenGLShaderProgram.cpp @@ -41,6 +41,10 @@ void OpenGLShaderProgram::addFragmentSource(const std::string &path) { } } +void OpenGLShaderProgram::destroy(OpenGLFunctions *functions) { + program->removeAllShaders(); +} + void OpenGLShaderProgram::compile() { std::string prefix = std::string("#version ") + OPENGL_GLSL_VERSION + "\n\n"; diff --git a/src/render/opengl/OpenGLShaderProgram.h b/src/render/opengl/OpenGLShaderProgram.h index 3eedf94..af3d93b 100644 --- a/src/render/opengl/OpenGLShaderProgram.h +++ b/src/render/opengl/OpenGLShaderProgram.h @@ -16,6 +16,13 @@ class OPENGLSHARED_EXPORT OpenGLShaderProgram { void addVertexSource(const std::string &path); void addFragmentSource(const std::string &path); + /** + * Release any allocated resource in the opengl context. + * + * Must be called in the opengl rendering thread, and before the destructor is called. + */ + void destroy(OpenGLFunctions *functions); + /** * Draw a VertexArray object. * diff --git a/src/render/opengl/OpenGLSharedState.cpp b/src/render/opengl/OpenGLSharedState.cpp index 7cd27e9..ad6eacb 100644 --- a/src/render/opengl/OpenGLSharedState.cpp +++ b/src/render/opengl/OpenGLSharedState.cpp @@ -15,6 +15,12 @@ void OpenGLSharedState::apply(OpenGLShaderProgram *program, int &texture_unit) { } } +void OpenGLSharedState::destroy(OpenGLFunctions *functions) { + for (const auto &pair : variables) { + pair.second->destroy(functions); + } +} + OpenGLVariable *OpenGLSharedState::get(const std::string &name) { OpenGLVariable *&var = variables[name]; if (var == NULL) { diff --git a/src/render/opengl/OpenGLSharedState.h b/src/render/opengl/OpenGLSharedState.h index 15bdf48..8185e6d 100644 --- a/src/render/opengl/OpenGLSharedState.h +++ b/src/render/opengl/OpenGLSharedState.h @@ -11,21 +11,28 @@ class QImage; namespace paysages { namespace opengl { -/*! - * \brief OpenGL variables that can be shared between shaders. +/** + * OpenGL variables that can be shared between shaders. */ class OPENGLSHARED_EXPORT OpenGLSharedState { public: OpenGLSharedState(); ~OpenGLSharedState(); - /*! - * \brief Apply the stored variables to the bound program. + /** + * Apply the stored variables to the bound program. */ void apply(OpenGLShaderProgram *program, int &texture_unit); - /*! - * \brief Get or create a variable in the state. + /** + * Release any allocated resource in the opengl context. + * + * Must be called in the opengl rendering thread, and before the destructor is called. + */ + void destroy(OpenGLFunctions *functions); + + /** + * Get or create a variable in the state. */ OpenGLVariable *get(const std::string &name); diff --git a/src/render/opengl/OpenGLTerrain.cpp b/src/render/opengl/OpenGLTerrain.cpp index 18c67a4..491a7ec 100644 --- a/src/render/opengl/OpenGLTerrain.cpp +++ b/src/render/opengl/OpenGLTerrain.cpp @@ -62,7 +62,7 @@ void OpenGLTerrain::initialize() { for (int i = 0; i < chunks; i++) { for (int j = 0; j < chunks; j++) { OpenGLTerrainChunk *chunk = new OpenGLTerrainChunk(renderer, start + chunksize * (double)i, - start + chunksize * (double)j, chunksize, chunks); + start + chunksize * (double)j, chunksize, chunks); _chunks.append(chunk); _updateQueue.append(chunk); } @@ -94,6 +94,13 @@ void OpenGLTerrain::interrupt() { } } +void OpenGLTerrain::destroy() { + OpenGLFunctions *functions = getFunctions(); + for (auto &chunk : _chunks) { + chunk->destroy(functions); + } +} + void OpenGLTerrain::pause() { paused = true; interrupt(); diff --git a/src/render/opengl/OpenGLTerrain.h b/src/render/opengl/OpenGLTerrain.h index 2d24677..5aebb5e 100644 --- a/src/render/opengl/OpenGLTerrain.h +++ b/src/render/opengl/OpenGLTerrain.h @@ -22,6 +22,7 @@ class OPENGLSHARED_EXPORT OpenGLTerrain : public OpenGLPart, public DefinitionWa virtual void update() override; virtual void render() override; virtual void interrupt() override; + virtual void destroy() override; void pause(); void resume(); diff --git a/src/render/opengl/OpenGLTerrainChunk.cpp b/src/render/opengl/OpenGLTerrainChunk.cpp index ac07a5e..ee6d4f5 100644 --- a/src/render/opengl/OpenGLTerrainChunk.cpp +++ b/src/render/opengl/OpenGLTerrainChunk.cpp @@ -146,14 +146,14 @@ void OpenGLTerrainChunk::updatePriority(CameraDefinition *camera) { _lock_data->release(); // Update wanted LOD - if (distance_to_camera < 60.0) { + if (distance_to_camera < 100.0) { _texture_wanted_size = _texture_max_size; - } else if (distance_to_camera < 140.0) { + } else if (distance_to_camera < 200.0) { _texture_wanted_size = _texture_max_size / 4; - } else if (distance_to_camera < 300.0) { + } else if (distance_to_camera < 400.0) { _texture_wanted_size = _texture_max_size / 8; } else { - _texture_wanted_size = 8; + _texture_wanted_size = _texture_max_size / 16; } // Update priority @@ -195,6 +195,11 @@ void OpenGLTerrainChunk::askResume() { interrupt = false; } +void OpenGLTerrainChunk::destroy(OpenGLFunctions *functions) { + vertices->destroy(functions); + glstate->destroy(functions); +} + void OpenGLTerrainChunk::setFirstStepVertices() { OpenGLVertexArray next(true); next.setVertexCount(6); @@ -210,6 +215,9 @@ void OpenGLTerrainChunk::augmentVertices() { // TODO Re-use existing vertices from previous level when possible double quad_size = _size / (double)next_vertices_level; for (int iz = 0; iz < next_vertices_level; iz++) { + if (interrupt or _reset_topology) { + return; + } for (int ix = 0; ix < next_vertices_level; ix++) { fillVerticesFromSquare(&next, (iz * next_vertices_level + ix) * 6, _startx + quad_size * (double)ix, _startz + quad_size * (double)iz, quad_size); diff --git a/src/render/opengl/OpenGLTerrainChunk.h b/src/render/opengl/OpenGLTerrainChunk.h index 4eeff97..159c329 100644 --- a/src/render/opengl/OpenGLTerrainChunk.h +++ b/src/render/opengl/OpenGLTerrainChunk.h @@ -28,6 +28,13 @@ class OPENGLSHARED_EXPORT OpenGLTerrainChunk { return vertices; } + /** + * Release any allocated resource in the opengl context. + * + * Must be called in the opengl rendering thread, and before the destructor is called. + */ + void destroy(OpenGLFunctions *functions); + /** * Fill *vertices* with a quick initial set of vertices, that can be augmented later using *augmentVertices*. */ diff --git a/src/render/opengl/OpenGLVariable.cpp b/src/render/opengl/OpenGLVariable.cpp index 31bad2e..b45402d 100644 --- a/src/render/opengl/OpenGLVariable.cpp +++ b/src/render/opengl/OpenGLVariable.cpp @@ -79,6 +79,13 @@ void OpenGLVariable::apply(OpenGLShaderProgram *program, int &texture_unit) { } } +void OpenGLVariable::destroy(OpenGLFunctions *functions) { + if (texture_id) { + functions->glDeleteTextures(1, &texture_id); + texture_id = 0; + } +} + void OpenGLVariable::set(const Texture2D *texture, bool repeat, bool color) { assert(type == TYPE_NONE or type == TYPE_TEXTURE_2D); @@ -111,8 +118,7 @@ void OpenGLVariable::set(const Texture2D *texture, bool repeat, bool color) { texture_color = color; } -void OpenGLVariable::set(const QImage &texture, bool repeat, bool color) -{ +void OpenGLVariable::set(const QImage &texture, bool repeat, bool color) { assert(type == TYPE_NONE or type == TYPE_TEXTURE_2D); type = TYPE_TEXTURE_2D; @@ -272,8 +278,10 @@ void OpenGLVariable::uploadTexture(OpenGLRenderer *renderer) { int dest_format = texture_color ? GL_RGBA : GL_RED; if (type == TYPE_TEXTURE_2D) { - functions->glTexImage2D(GL_TEXTURE_2D, 0, dest_format, texture_size_x, texture_size_y, 0, GL_RGBA, GL_FLOAT, value_texture_data); + functions->glTexImage2D(GL_TEXTURE_2D, 0, dest_format, texture_size_x, texture_size_y, 0, GL_RGBA, GL_FLOAT, + value_texture_data); } else { - functions->glTexImage3D(GL_TEXTURE_3D, 0, dest_format, texture_size_x, texture_size_y, texture_size_z, 0, GL_RGBA, GL_FLOAT, value_texture_data); + functions->glTexImage3D(GL_TEXTURE_3D, 0, dest_format, texture_size_x, texture_size_y, texture_size_z, 0, + GL_RGBA, GL_FLOAT, value_texture_data); } } diff --git a/src/render/opengl/OpenGLVariable.h b/src/render/opengl/OpenGLVariable.h index 6d977a9..d2d5aa6 100644 --- a/src/render/opengl/OpenGLVariable.h +++ b/src/render/opengl/OpenGLVariable.h @@ -33,6 +33,13 @@ class OpenGLVariable { void apply(OpenGLShaderProgram *program, int &texture_unit); + /** + * Release any allocated resource in the opengl context. + * + * Must be called in the opengl rendering thread, and before the destructor is called. + */ + void destroy(OpenGLFunctions *functions); + void set(const Texture2D *texture, bool repeat = false, bool color = true); void set(const QImage &texture, bool repeat = false, bool color = true); void set(const Texture3D *texture, bool repeat = false, bool color = true); diff --git a/src/render/opengl/OpenGLVertexArray.cpp b/src/render/opengl/OpenGLVertexArray.cpp index 8d6ad34..185b786 100644 --- a/src/render/opengl/OpenGLVertexArray.cpp +++ b/src/render/opengl/OpenGLVertexArray.cpp @@ -30,8 +30,19 @@ OpenGLVertexArray::~OpenGLVertexArray() { free(array_uv); } -void OpenGLVertexArray::destroy() { - // TODO +void OpenGLVertexArray::destroy(OpenGLFunctions *functions) { + if (vbo_vertex) { + functions->glDeleteBuffers(1, &vbo_vertex); + vbo_vertex = 0; + } + if (vbo_uv) { + functions->glDeleteBuffers(1, &vbo_uv); + vbo_uv = 0; + } + if (vao) { + functions->glDeleteVertexArrays(1, &vao); + vao = 0; + } } void OpenGLVertexArray::render(OpenGLFunctions *functions) { @@ -72,8 +83,7 @@ void OpenGLVertexArray::set(int index, const Vector3 &location, double u, double } } -void OpenGLVertexArray::get(int index, Vector3 *location, double *u, double *v) const -{ +void OpenGLVertexArray::get(int index, Vector3 *location, double *u, double *v) const { if (index >= 0 and index < vertexcount) { location->x = array_vertex[index * 3]; location->y = array_vertex[index * 3 + 1]; @@ -85,8 +95,7 @@ void OpenGLVertexArray::get(int index, Vector3 *location, double *u, double *v) } } -void OpenGLVertexArray::copyTo(OpenGLVertexArray *destination) const -{ +void OpenGLVertexArray::copyTo(OpenGLVertexArray *destination) const { destination->setVertexCount(vertexcount); if (vertexcount) { memcpy(destination->array_vertex, array_vertex, sizeof(float) * vertexcount * 3); diff --git a/src/render/opengl/OpenGLVertexArray.h b/src/render/opengl/OpenGLVertexArray.h index fe9ea9b..142825b 100644 --- a/src/render/opengl/OpenGLVertexArray.h +++ b/src/render/opengl/OpenGLVertexArray.h @@ -25,7 +25,7 @@ class OpenGLVertexArray { * * Must be called in the opengl rendering thread, and before the destructor is called. */ - void destroy(); + void destroy(OpenGLFunctions *functions); /** * Render this array in current opengl context. diff --git a/src/system/RandomGenerator.cpp b/src/system/RandomGenerator.cpp index dcaf023..78703c8 100644 --- a/src/system/RandomGenerator.cpp +++ b/src/system/RandomGenerator.cpp @@ -4,11 +4,11 @@ #include static RandomGenerator _RandomGeneratorDefault; -RandomGenerator& paysages::system::RandomGeneratorDefault = _RandomGeneratorDefault; +RandomGenerator &paysages::system::RandomGeneratorDefault = _RandomGeneratorDefault; class RandomGenerator::RandomGeneratorPrivate { public: - RandomGeneratorPrivate(unsigned int seed): generator(seed) { + RandomGeneratorPrivate(unsigned int seed) : generator(seed) { } std::default_random_engine generator; @@ -27,12 +27,10 @@ RandomGenerator::RandomGenerator(RandomGenerator::Seed seed) { data = new RandomGeneratorPrivate(seed); } -RandomGenerator::~RandomGenerator() -{ +RandomGenerator::~RandomGenerator() { delete data; } -double RandomGenerator::genDouble() -{ +double RandomGenerator::genDouble() { return data->distribution_double(data->generator); } diff --git a/src/system/system_global.h b/src/system/system_global.h index 154f1ab..0ff1270 100644 --- a/src/system/system_global.h +++ b/src/system/system_global.h @@ -31,7 +31,7 @@ class PictureWriter; class Time; class RandomGenerator; -extern RandomGenerator& RandomGeneratorDefault; +extern RandomGenerator &RandomGeneratorDefault; } } using namespace paysages::system; diff --git a/src/tests/OpenGLTerrainChunk_Test.cpp b/src/tests/OpenGLTerrainChunk_Test.cpp index 81f12dc..a294dfe 100644 --- a/src/tests/OpenGLTerrainChunk_Test.cpp +++ b/src/tests/OpenGLTerrainChunk_Test.cpp @@ -6,7 +6,8 @@ #include "OpenGLVertexArray.h" #include "Vector3.h" -static void checkVertex(const OpenGLVertexArray *array, int index, const Vector3 &expected_location, double expected_u, double expected_v) { +static void checkVertex(const OpenGLVertexArray *array, int index, const Vector3 &expected_location, double expected_u, + double expected_v) { Vector3 location; double u, v; From 7d4989b670f16a94fffb216369af19bca43cc5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 11 Dec 2015 00:36:50 +0100 Subject: [PATCH 2/4] using namespace std --- src/basics/NoiseState.h | 2 +- src/basics/Texture2D.cpp | 2 +- src/basics/Texture2D.h | 2 +- src/basics/Texture3D.cpp | 2 +- src/basics/Texture3D.h | 2 +- src/basics/Texture4D.cpp | 2 +- src/basics/Texture4D.h | 2 +- src/definition/AtmosphereDefinition.h | 2 +- src/definition/CloudLayerDefinition.cpp | 2 +- src/definition/CloudLayerDefinition.h | 2 +- src/definition/CloudsDefinition.cpp | 2 +- src/definition/DefinitionDiff.h | 8 ++-- src/definition/DefinitionNode.cpp | 42 +++++++++---------- src/definition/DefinitionNode.h | 24 +++++------ src/definition/DiffManager.cpp | 6 +-- src/definition/DiffManager.h | 4 +- src/definition/FloatNode.cpp | 12 +++--- src/definition/FloatNode.h | 6 +-- src/definition/IntNode.cpp | 12 +++--- src/definition/IntNode.h | 6 +-- src/definition/Layers.cpp | 14 +++---- src/definition/Layers.h | 12 +++--- src/definition/NoiseNode.cpp | 2 +- src/definition/Scenery.cpp | 10 ++--- src/definition/Scenery.h | 4 +- src/definition/TextureLayerDefinition.cpp | 2 +- src/definition/TextureLayerDefinition.h | 2 +- src/definition/TexturesDefinition.cpp | 2 +- src/interface/commandline/tests.cpp | 4 +- .../modeler/quickapp/FloatPropertyBind.cpp | 2 +- .../modeler/quickapp/IntPropertyBind.cpp | 2 +- .../modeler/quickapp/MainModelerWindow.cpp | 8 ++-- src/render/opengl/OpenGLPart.cpp | 2 +- src/render/opengl/OpenGLPart.h | 6 +-- src/render/opengl/OpenGLRenderer.cpp | 8 ++-- src/render/opengl/OpenGLRenderer.h | 2 +- src/render/opengl/OpenGLShaderProgram.cpp | 24 +++++------ src/render/opengl/OpenGLShaderProgram.h | 12 +++--- src/render/opengl/OpenGLSharedState.cpp | 2 +- src/render/opengl/OpenGLSharedState.h | 24 +++++------ src/render/opengl/OpenGLVariable.cpp | 4 +- src/render/opengl/OpenGLVariable.h | 4 +- src/render/opengl/OpenGLVertexArray.cpp | 6 +-- .../software/AtmosphereModelBruneton.cpp | 2 +- src/render/software/AtmosphereModelBruneton.h | 2 +- src/render/software/AtmosphereRenderer.cpp | 5 +-- src/render/software/AtmosphereRenderer.h | 4 +- src/render/software/Canvas.cpp | 2 +- src/render/software/Canvas.h | 4 +- src/render/software/CanvasPictureWriter.cpp | 2 +- src/render/software/CanvasPictureWriter.h | 2 +- src/render/software/CanvasPortion.cpp | 7 ++-- src/render/software/CanvasPortion.h | 2 +- src/render/software/CloudsRenderer.cpp | 6 +-- src/render/software/CloudsRenderer.h | 4 +- src/render/software/FluidMediumManager.h | 2 +- src/render/software/LightSource.h | 2 +- src/render/software/LightStatus.h | 2 +- src/render/software/LightingManager.cpp | 14 +++---- src/render/software/LightingManager.h | 6 +-- src/render/software/NightSky.cpp | 2 +- src/render/software/NightSky.h | 2 +- src/render/software/RenderProgress.cpp | 2 +- src/render/software/RenderProgress.h | 2 +- .../software/SoftwareCanvasRenderer.cpp | 2 +- src/render/software/SoftwareCanvasRenderer.h | 4 +- src/system/CacheFile.cpp | 10 ++--- src/system/CacheFile.h | 8 ++-- src/system/DataFile.cpp | 20 ++++----- src/system/DataFile.h | 10 ++--- src/system/FileSystem.cpp | 6 +-- src/system/FileSystem.h | 6 +-- src/system/Logs.cpp | 29 +++++++------ src/system/Logs.h | 8 ++-- src/system/PackStream.cpp | 17 ++++---- src/system/PackStream.h | 10 ++--- src/system/ParallelPool.h | 2 +- src/system/PictureWriter.cpp | 2 +- src/system/PictureWriter.h | 2 +- src/system/RandomGenerator.cpp | 8 ++-- src/system/system_global.h | 2 + src/tests/ColorHSL_Test.cpp | 2 +- src/tests/GodRaysSampler_Test.cpp | 2 +- src/tests/Layers_Test.cpp | 12 +++--- src/tests/LightingManager_Test.cpp | 2 +- src/tests/SpaceSegment_Test.cpp | 2 +- 86 files changed, 270 insertions(+), 272 deletions(-) diff --git a/src/basics/NoiseState.h b/src/basics/NoiseState.h index d0bfae2..223caef 100644 --- a/src/basics/NoiseState.h +++ b/src/basics/NoiseState.h @@ -35,7 +35,7 @@ class BASICSSHARED_EXPORT NoiseState { void setLevelCount(int level_count); private: - std::vector level_offsets; + vector level_offsets; friend class NoiseGenerator; friend class FractalNoise; diff --git a/src/basics/Texture2D.cpp b/src/basics/Texture2D.cpp index fc2d77c..dade33c 100644 --- a/src/basics/Texture2D.cpp +++ b/src/basics/Texture2D.cpp @@ -152,7 +152,7 @@ class Texture2DWriter : public PictureWriter { const Texture2D *tex; }; -void Texture2D::saveToFile(const std::string &filepath) const { +void Texture2D::saveToFile(const string &filepath) const { Texture2DWriter writer(this); writer.save(filepath, xsize, ysize); } diff --git a/src/basics/Texture2D.h b/src/basics/Texture2D.h index b324d00..133a6d7 100644 --- a/src/basics/Texture2D.h +++ b/src/basics/Texture2D.h @@ -21,7 +21,7 @@ class BASICSSHARED_EXPORT Texture2D { void add(Texture2D *other); void save(PackStream *stream) const; void load(PackStream *stream); - void saveToFile(const std::string &filepath) const; + void saveToFile(const string &filepath) const; private: int xsize; diff --git a/src/basics/Texture3D.cpp b/src/basics/Texture3D.cpp index 80fff9b..f598039 100644 --- a/src/basics/Texture3D.cpp +++ b/src/basics/Texture3D.cpp @@ -187,7 +187,7 @@ class Texture3DWriter : public PictureWriter { const Texture3D *tex; }; -void Texture3D::saveToFile(const std::string &filepath) const { +void Texture3D::saveToFile(const string &filepath) const { Texture3DWriter writer(this); writer.save(filepath, xsize, ysize * zsize); } diff --git a/src/basics/Texture3D.h b/src/basics/Texture3D.h index 4cd9331..b833aba 100644 --- a/src/basics/Texture3D.h +++ b/src/basics/Texture3D.h @@ -21,7 +21,7 @@ class BASICSSHARED_EXPORT Texture3D { void add(Texture3D *other); void save(PackStream *stream) const; void load(PackStream *stream); - void saveToFile(const std::string &filepath) const; + void saveToFile(const string &filepath) const; private: int xsize; diff --git a/src/basics/Texture4D.cpp b/src/basics/Texture4D.cpp index d7ba180..e16ea0d 100644 --- a/src/basics/Texture4D.cpp +++ b/src/basics/Texture4D.cpp @@ -230,7 +230,7 @@ class Texture4DWriter : public PictureWriter { const Texture4D *tex; }; -void Texture4D::saveToFile(const std::string &filepath) const { +void Texture4D::saveToFile(const string &filepath) const { Texture4DWriter writer(this); writer.save(filepath, xsize * wsize, ysize * zsize); } diff --git a/src/basics/Texture4D.h b/src/basics/Texture4D.h index 7ab877e..0d16907 100644 --- a/src/basics/Texture4D.h +++ b/src/basics/Texture4D.h @@ -21,7 +21,7 @@ class BASICSSHARED_EXPORT Texture4D { void add(Texture4D *other); void save(PackStream *stream) const; void load(PackStream *stream); - void saveToFile(const std::string &filepath) const; + void saveToFile(const string &filepath) const; private: int xsize; diff --git a/src/definition/AtmosphereDefinition.h b/src/definition/AtmosphereDefinition.h index 5d614b6..4ef63a5 100644 --- a/src/definition/AtmosphereDefinition.h +++ b/src/definition/AtmosphereDefinition.h @@ -77,7 +77,7 @@ class DEFINITIONSHARED_EXPORT AtmosphereDefinition : public DefinitionNode { double moon_theta; double moon_phi; - std::vector stars; + vector stars; private: GodRaysDefinition *godrays; diff --git a/src/definition/CloudLayerDefinition.cpp b/src/definition/CloudLayerDefinition.cpp index 508dd28..911d00b 100644 --- a/src/definition/CloudLayerDefinition.cpp +++ b/src/definition/CloudLayerDefinition.cpp @@ -6,7 +6,7 @@ #include "PackStream.h" #include "FloatNode.h" -CloudLayerDefinition::CloudLayerDefinition(DefinitionNode *parent, const std::string &name) +CloudLayerDefinition::CloudLayerDefinition(DefinitionNode *parent, const string &name) : DefinitionNode(parent, name, "cloudlayer") { type = CIRRUS; altitude = 0.5; diff --git a/src/definition/CloudLayerDefinition.h b/src/definition/CloudLayerDefinition.h index d9c0918..679b448 100644 --- a/src/definition/CloudLayerDefinition.h +++ b/src/definition/CloudLayerDefinition.h @@ -12,7 +12,7 @@ namespace definition { class DEFINITIONSHARED_EXPORT CloudLayerDefinition : public DefinitionNode { public: - CloudLayerDefinition(DefinitionNode *parent, const std::string &name); + CloudLayerDefinition(DefinitionNode *parent, const string &name); virtual ~CloudLayerDefinition(); inline const NoiseState &getNoiseState() const { diff --git a/src/definition/CloudsDefinition.cpp b/src/definition/CloudsDefinition.cpp index abdd862..47ad5c4 100644 --- a/src/definition/CloudsDefinition.cpp +++ b/src/definition/CloudsDefinition.cpp @@ -2,7 +2,7 @@ #include "CloudLayerDefinition.h" -static DefinitionNode *_layerConstructor(Layers *parent, const std::string &name) { +static DefinitionNode *_layerConstructor(Layers *parent, const string &name) { return new CloudLayerDefinition(parent, name); } diff --git a/src/definition/DefinitionDiff.h b/src/definition/DefinitionDiff.h index 6f90bc2..f972d22 100644 --- a/src/definition/DefinitionDiff.h +++ b/src/definition/DefinitionDiff.h @@ -16,16 +16,16 @@ class DEFINITIONSHARED_EXPORT DefinitionDiff { DefinitionDiff(const DefinitionNode *node); virtual ~DefinitionDiff(); - inline const std::string &getTypeName() const { + inline const string &getTypeName() const { return type_name; } - inline const std::string &getPath() const { + inline const string &getPath() const { return path; } private: - std::string type_name; - std::string path; + string type_name; + string path; }; } } diff --git a/src/definition/DefinitionNode.cpp b/src/definition/DefinitionNode.cpp index d6938eb..cf0c34c 100644 --- a/src/definition/DefinitionNode.cpp +++ b/src/definition/DefinitionNode.cpp @@ -9,7 +9,7 @@ #include #include -DefinitionNode::DefinitionNode(DefinitionNode *parent, const std::string &name, const std::string &type_name) +DefinitionNode::DefinitionNode(DefinitionNode *parent, const string &name, const string &type_name) : parent(parent), type_name(type_name), name(name) { if (parent) { root = parent->root; @@ -33,7 +33,7 @@ DefinitionNode::~DefinitionNode() { } // Work on a copy, because the child destructor will modify the array by removing itself using removeChild - std::vector children_copy = children; + vector children_copy = children; for (auto child : children_copy) { if (child->getParent() == this) { delete child; @@ -41,7 +41,7 @@ DefinitionNode::~DefinitionNode() { } } -void DefinitionNode::setName(const std::string &name) { +void DefinitionNode::setName(const string &name) { this->name = name; } @@ -53,8 +53,8 @@ Scenery *DefinitionNode::getScenery() { } } -std::string DefinitionNode::toString(int indent) const { - std::string result; +string DefinitionNode::toString(int indent) const { + string result; for (int i = 0; i < indent; i++) { result += " "; } @@ -67,7 +67,7 @@ std::string DefinitionNode::toString(int indent) const { return result; } -std::string DefinitionNode::getPath() const { +string DefinitionNode::getPath() const { if (parent == root) { return parent->getPath() + name; } else if (parent) { @@ -77,7 +77,7 @@ std::string DefinitionNode::getPath() const { } } -DefinitionNode *DefinitionNode::findByPath(const std::string &path) const { +DefinitionNode *DefinitionNode::findByPath(const string &path) const { if (path.empty()) { return NULL; } else if (path[0] == '/') { @@ -90,11 +90,11 @@ DefinitionNode *DefinitionNode::findByPath(const std::string &path) const { } } else { size_t seppos = path.find("/"); - std::string child_name = (seppos == std::string::npos) ? path : path.substr(0, seppos); + string child_name = (seppos == string::npos) ? path : path.substr(0, seppos); DefinitionNode *child = ((DefinitionNode *)this)->findChildByName(child_name); // FIXME findChildByName should be const if (child) { - if (seppos == std::string::npos) { + if (seppos == string::npos) { return child; } else { return child->findByPath(path.substr(seppos + 1)); @@ -111,18 +111,18 @@ bool DefinitionNode::applyDiff(const DefinitionDiff *diff, bool) { return true; } else { Logs::error() << "[Definition] Can't apply " << diff->getTypeName() << " diff to " << getName() << " " - << type_name << " node" << std::endl; + << type_name << " node" << endl; return false; } } -void DefinitionNode::generateInitDiffs(std::vector *) const { +void DefinitionNode::generateInitDiffs(vector *) const { } void DefinitionNode::addWatcher(DefinitionWatcher *watcher, bool init_diff) { if (root && root->diffs) { if (init_diff) { - std::vector diffs; + vector diffs; generateInitDiffs(&diffs); for (auto diff : diffs) { @@ -156,7 +156,7 @@ void DefinitionNode::save(PackStream *stream) const { } else { // Child size not known, write it to a temporary stream to know it Logs::debug() << "[Definition] Unknown size for child " << child->name - << ", unefficient writing to temporary stream" << std::endl; + << ", unefficient writing to temporary stream" << endl; PackStream substream; child->save(&substream); stream->writeFromBuffer(substream, true); @@ -170,7 +170,7 @@ void DefinitionNode::load(PackStream *stream) { stream->read(&children_count); for (int i = 0; i < children_count; i++) { - std::string child_name = stream->readString(); + string child_name = stream->readString(); int child_size; stream->read(&child_size); @@ -183,7 +183,7 @@ void DefinitionNode::load(PackStream *stream) { // TODO Ask subclass if it can instanciate a child // Else skip length of unknown child stream->skipBytes(child_size); - Logs::warning() << "[Definition] Skipped unknown child '" << child_name << "'" << std::endl; + Logs::warning() << "[Definition] Skipped unknown child '" << child_name << "'" << endl; } } } @@ -197,12 +197,12 @@ void DefinitionNode::copy(DefinitionNode *destination) const { child->copy(dest_child); } else { Logs::warning() << "[Definition] Can't copy to child " << child->name << " of " - << destination->getTypeName() << std::endl; + << destination->getTypeName() << endl; } } } else { Logs::error() << "[Definition] Can't copy from " << getTypeName() << " to " << destination->getTypeName() - << std::endl; + << endl; } } @@ -213,7 +213,7 @@ void DefinitionNode::validate() { } void DefinitionNode::addChild(DefinitionNode *child) { - if (std::find(children.begin(), children.end(), child) == children.end()) { + if (find(children.begin(), children.end(), child) == children.end()) { children.push_back(child); child->parent = this; child->root = this->root; @@ -221,17 +221,17 @@ void DefinitionNode::addChild(DefinitionNode *child) { } void DefinitionNode::removeChild(DefinitionNode *child) { - std::vector::iterator it = std::find(children.begin(), children.end(), child); + vector::iterator it = find(children.begin(), children.end(), child); if (it != children.end()) { child->parent = NULL; children.erase(it); } else { Logs::warning() << "[Definition] Trying to remove not found child '" << child->name << "' from '" << name << "'" - << std::endl; + << endl; } } -DefinitionNode *DefinitionNode::findChildByName(const std::string name) { +DefinitionNode *DefinitionNode::findChildByName(const string name) { for (auto child : children) { if (child->name == name) { return child; diff --git a/src/definition/DefinitionNode.h b/src/definition/DefinitionNode.h index 030ce42..eb2160e 100644 --- a/src/definition/DefinitionNode.h +++ b/src/definition/DefinitionNode.h @@ -13,7 +13,7 @@ namespace definition { */ class DEFINITIONSHARED_EXPORT DefinitionNode { public: - DefinitionNode(DefinitionNode *parent, const std::string &name, const std::string &type_name = ""); + DefinitionNode(DefinitionNode *parent, const string &name, const string &type_name = ""); virtual ~DefinitionNode(); virtual void save(PackStream *stream) const; @@ -22,12 +22,12 @@ class DEFINITIONSHARED_EXPORT DefinitionNode { virtual void copy(DefinitionNode *destination) const; virtual void validate(); - inline const std::string &getName() const { + inline const string &getName() const { return name; } - virtual void setName(const std::string &name); + virtual void setName(const string &name); - inline const std::string &getTypeName() const { + inline const string &getTypeName() const { return type_name; } @@ -49,19 +49,19 @@ class DEFINITIONSHARED_EXPORT DefinitionNode { /** * Return a string representation of the tree (mainly for debugging purposes). */ - virtual std::string toString(int indent = 0) const; + virtual string toString(int indent = 0) const; /** * Return the path to this node, using '/' delimited syntax, with the first '/' being the root node. */ - std::string getPath() const; + string getPath() const; /** * Find a node in this tree, by its path (as returned by getPath). * * Return NULL if the path does not exists. */ - DefinitionNode *findByPath(const std::string &path) const; + DefinitionNode *findByPath(const string &path) const; /** * Apply a diff to the internal value of this node. @@ -79,7 +79,7 @@ class DEFINITIONSHARED_EXPORT DefinitionNode { * * This method should be overridden by subclasses. */ - virtual void generateInitDiffs(std::vector *diffs) const; + virtual void generateInitDiffs(vector *diffs) const; /** * Add a watcher over this node. @@ -98,7 +98,7 @@ class DEFINITIONSHARED_EXPORT DefinitionNode { protected: void addChild(DefinitionNode *child); void removeChild(DefinitionNode *child); - virtual DefinitionNode *findChildByName(const std::string name); + virtual DefinitionNode *findChildByName(const string name); /** * Get the size in bytes this child will consume when serialized to a stream. @@ -121,9 +121,9 @@ class DEFINITIONSHARED_EXPORT DefinitionNode { DefinitionNode *parent; DefinitionNode *root; DiffManager *diffs; - std::string type_name; - std::string name; - std::vector children; + string type_name; + string name; + vector children; }; } } diff --git a/src/definition/DiffManager.cpp b/src/definition/DiffManager.cpp index 5e93d2a..0d661b2 100644 --- a/src/definition/DiffManager.cpp +++ b/src/definition/DiffManager.cpp @@ -18,7 +18,7 @@ DiffManager::~DiffManager() { } void DiffManager::addWatcher(const DefinitionNode *node, DefinitionWatcher *watcher) { - if (std::find(watchers[node].begin(), watchers[node].end(), watcher) == watchers[node].end()) { + if (find(watchers[node].begin(), watchers[node].end(), watcher) == watchers[node].end()) { watchers[node].push_back(watcher); } } @@ -61,7 +61,7 @@ void DiffManager::undo() { watcher->nodeChanged(node, diff); } } else { - Logs::error() << "Can't find node to undo diff : " << diff->getPath() << std::endl; + Logs::error() << "Can't find node to undo diff : " << diff->getPath() << endl; } } } @@ -81,7 +81,7 @@ void DiffManager::redo() { watcher->nodeChanged(node, diff); } } else { - Logs::error() << "Can't find node to redo diff : " << diff->getPath() << std::endl; + Logs::error() << "Can't find node to redo diff : " << diff->getPath() << endl; } } } diff --git a/src/definition/DiffManager.h b/src/definition/DiffManager.h index 8bc4a43..d1acbf9 100644 --- a/src/definition/DiffManager.h +++ b/src/definition/DiffManager.h @@ -56,8 +56,8 @@ class DEFINITIONSHARED_EXPORT DiffManager { private: DefinitionNode *tree; int undone; - std::vector diffs; - std::map> watchers; + vector diffs; + map> watchers; }; } } diff --git a/src/definition/FloatNode.cpp b/src/definition/FloatNode.cpp index 5e6f15d..eda3dbb 100644 --- a/src/definition/FloatNode.cpp +++ b/src/definition/FloatNode.cpp @@ -6,12 +6,12 @@ #include #include -FloatNode::FloatNode(DefinitionNode *parent, const std::string &name, double value) +FloatNode::FloatNode(DefinitionNode *parent, const string &name, double value) : DefinitionNode(parent, name, "float"), value(value) { } -std::string FloatNode::toString(int indent) const { - std::ostringstream stream; +string FloatNode::toString(int indent) const { + ostringstream stream; stream << DefinitionNode::toString(indent) << " " << value; @@ -30,7 +30,7 @@ void FloatNode::copy(DefinitionNode *destination) const { if (destination->getTypeName() == getTypeName()) { ((FloatNode *)destination)->value = value; } else { - Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << std::endl; + Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << endl; } } @@ -42,7 +42,7 @@ const FloatDiff *FloatNode::produceDiff(double new_value) const { return new FloatDiff(this, value, new_value); } -void FloatNode::generateInitDiffs(std::vector *diffs) const { +void FloatNode::generateInitDiffs(vector *diffs) const { diffs->push_back(produceDiff(value)); } @@ -61,7 +61,7 @@ bool FloatNode::applyDiff(const DefinitionDiff *diff, bool backward) { value = next; return true; } else { - Logs::error() << "Can't apply float diff " << previous << " => " << next << " to " << getName() << std::endl; + Logs::error() << "Can't apply float diff " << previous << " => " << next << " to " << getName() << endl; return false; } } diff --git a/src/definition/FloatNode.h b/src/definition/FloatNode.h index f86fded..50f7170 100644 --- a/src/definition/FloatNode.h +++ b/src/definition/FloatNode.h @@ -13,13 +13,13 @@ namespace definition { */ class DEFINITIONSHARED_EXPORT FloatNode : public DefinitionNode { public: - FloatNode(DefinitionNode *parent, const std::string &name, double value = 0.0); + FloatNode(DefinitionNode *parent, const string &name, double value = 0.0); inline double getValue() const { return value; } - virtual std::string toString(int indent) const override; + virtual string toString(int indent) const override; virtual void save(PackStream *stream) const override; virtual void load(PackStream *stream) override; virtual void copy(DefinitionNode *destination) const override; @@ -31,7 +31,7 @@ class DEFINITIONSHARED_EXPORT FloatNode : public DefinitionNode { */ void setValue(double new_value); const FloatDiff *produceDiff(double new_value) const; - void generateInitDiffs(std::vector *diffs) const; + void generateInitDiffs(vector *diffs) const; virtual bool applyDiff(const DefinitionDiff *diff, bool backward = false) override; void addValue(double added); diff --git a/src/definition/IntNode.cpp b/src/definition/IntNode.cpp index a5704af..b54023c 100644 --- a/src/definition/IntNode.cpp +++ b/src/definition/IntNode.cpp @@ -6,12 +6,12 @@ #include #include -IntNode::IntNode(DefinitionNode *parent, const std::string &name, int value) +IntNode::IntNode(DefinitionNode *parent, const string &name, int value) : DefinitionNode(parent, name, "int"), value(value) { } -std::string IntNode::toString(int indent) const { - std::ostringstream stream; +string IntNode::toString(int indent) const { + ostringstream stream; stream << DefinitionNode::toString(indent) << " " << value; @@ -30,7 +30,7 @@ void IntNode::copy(DefinitionNode *destination) const { if (destination->getTypeName() == getTypeName()) { ((IntNode *)destination)->value = value; } else { - Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << std::endl; + Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << endl; } } @@ -42,7 +42,7 @@ const IntDiff *IntNode::produceDiff(int new_value) const { return new IntDiff(this, value, new_value); } -void IntNode::generateInitDiffs(std::vector *diffs) const { +void IntNode::generateInitDiffs(vector *diffs) const { diffs->push_back(produceDiff(value)); } @@ -61,7 +61,7 @@ bool IntNode::applyDiff(const DefinitionDiff *diff, bool backward) { value = next; return true; } else { - Logs::error() << "Can't apply int diff " << previous << " => " << next << " to " << getName() << std::endl; + Logs::error() << "Can't apply int diff " << previous << " => " << next << " to " << getName() << endl; return false; } } diff --git a/src/definition/IntNode.h b/src/definition/IntNode.h index cd531ee..4f23ce8 100644 --- a/src/definition/IntNode.h +++ b/src/definition/IntNode.h @@ -13,13 +13,13 @@ namespace definition { */ class DEFINITIONSHARED_EXPORT IntNode : public DefinitionNode { public: - IntNode(DefinitionNode *parent, const std::string &name, int value = 0); + IntNode(DefinitionNode *parent, const string &name, int value = 0); inline int getValue() const { return value; } - virtual std::string toString(int indent) const override; + virtual string toString(int indent) const override; virtual void save(PackStream *stream) const override; virtual void load(PackStream *stream) override; virtual void copy(DefinitionNode *destination) const override; @@ -31,7 +31,7 @@ class DEFINITIONSHARED_EXPORT IntNode : public DefinitionNode { */ void setValue(int new_value); const IntDiff *produceDiff(int new_value) const; - void generateInitDiffs(std::vector *diffs) const; + void generateInitDiffs(vector *diffs) const; virtual bool applyDiff(const DefinitionDiff *diff, bool backward = false) override; private: diff --git a/src/definition/Layers.cpp b/src/definition/Layers.cpp index 4c31883..031ee2c 100644 --- a/src/definition/Layers.cpp +++ b/src/definition/Layers.cpp @@ -4,7 +4,7 @@ #include "Logs.h" #include "LayersDiff.h" -Layers::Layers(DefinitionNode *parent, const std::string &name, LayerConstructor layer_constructor) +Layers::Layers(DefinitionNode *parent, const string &name, LayerConstructor layer_constructor) : DefinitionNode(parent, name, "layers" + name), layer_constructor(layer_constructor) { max_layer_count = 100; null_layer = layer_constructor(this, "#NULL#"); @@ -69,7 +69,7 @@ DefinitionNode *Layers::getLayer(int position) const { return layers[position]; } else { Logs::warning() << "Asked for a undefined layer " << position << " on a total of " << (int)layers.size() - << std::endl; + << endl; return null_layer; } } @@ -81,12 +81,12 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) { if ((not backward and op == LayersDiff::LAYER_ADDED) or (backward and op == LayersDiff::LAYER_REMOVED)) { if (layer_count >= max_layer_count) { - Logs::warning() << "Add layer ignored because limit of " << max_layer_count << " reached" << std::endl; + Logs::warning() << "Add layer ignored because limit of " << max_layer_count << " reached" << endl; return false; } else { int position = layer_diff->getLayer1(); if (position < 0 or position > layer_count) { - Logs::error() << "Add layer ignored because requested position was incorrect" << std::endl; + Logs::error() << "Add layer ignored because requested position was incorrect" << endl; return false; } else { DefinitionNode *layer = layer_constructor(this, "temp"); @@ -104,7 +104,7 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) { int position = layer_diff->getLayer1(); if (position < 0 or position >= layer_count) { Logs::warning() << "Removing unknown layer " << position << " on " << layer_count << " from '" << getName() - << "'" << std::endl; + << "'" << endl; return false; } else { DefinitionNode *removed = layers[position]; @@ -117,7 +117,7 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) { return false; } -void Layers::generateInitDiffs(std::vector *diffs) const { +void Layers::generateInitDiffs(vector *diffs) const { int i = 0; for (auto layer : layers) { auto diff = new LayersDiff(this, LayersDiff::LAYER_ADDED, i++); @@ -132,7 +132,7 @@ void Layers::addLayer(const DefinitionNode &tocopy) { addDiff(diff); } -void Layers::addLayer(const std::string &name) { +void Layers::addLayer(const string &name) { auto layer = layer_constructor(this, name); addLayer(*layer); delete layer; diff --git a/src/definition/Layers.h b/src/definition/Layers.h index fdba3af..4ea4d69 100644 --- a/src/definition/Layers.h +++ b/src/definition/Layers.h @@ -8,14 +8,14 @@ namespace paysages { namespace definition { -typedef DefinitionNode *(*LayerConstructor)(Layers *parent, const std::string &name); +typedef DefinitionNode *(*LayerConstructor)(Layers *parent, const string &name); /** * @brief Layers of definitions, ideally all of the same type. */ class DEFINITIONSHARED_EXPORT Layers : public DefinitionNode { public: - Layers(DefinitionNode *parent, const std::string &name, LayerConstructor layer_constructor); + Layers(DefinitionNode *parent, const string &name, LayerConstructor layer_constructor); virtual ~Layers(); virtual void save(PackStream *stream) const override; @@ -23,7 +23,7 @@ class DEFINITIONSHARED_EXPORT Layers : public DefinitionNode { virtual void copy(DefinitionNode *destination) const override; virtual bool applyDiff(const DefinitionDiff *diff, bool backward = false) override; - virtual void generateInitDiffs(std::vector *diffs) const override; + virtual void generateInitDiffs(vector *diffs) const override; /** * Set the maximal layer count allowed. @@ -43,12 +43,12 @@ class DEFINITIONSHARED_EXPORT Layers : public DefinitionNode { /** * Retrieve a layer by its name. */ - DefinitionNode *getLayer(const std::string &name) const; + DefinitionNode *getLayer(const string &name) const; /** * Add a new empty layer. */ - void addLayer(const std::string &name); + void addLayer(const string &name); /** * Add a new layer, copying another node into it. @@ -68,7 +68,7 @@ class DEFINITIONSHARED_EXPORT Layers : public DefinitionNode { public: LayerConstructor layer_constructor; int max_layer_count; - std::vector layers; + vector layers; DefinitionNode *null_layer; }; } diff --git a/src/definition/NoiseNode.cpp b/src/definition/NoiseNode.cpp index c362e33..9d9543a 100644 --- a/src/definition/NoiseNode.cpp +++ b/src/definition/NoiseNode.cpp @@ -31,7 +31,7 @@ void NoiseNode::copy(DefinitionNode *destination) const { if (destination->getTypeName() == getTypeName()) { noise->copy(((NoiseNode *)destination)->noise); } else { - Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << std::endl; + Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << endl; } } diff --git a/src/definition/Scenery.cpp b/src/definition/Scenery.cpp index 77ee158..8ea72fa 100644 --- a/src/definition/Scenery.cpp +++ b/src/definition/Scenery.cpp @@ -30,7 +30,7 @@ void Scenery::validate() { keepCameraAboveGround(camera); } -Scenery::FileOperationResult Scenery::saveGlobal(const std::string &filepath) const { +Scenery::FileOperationResult Scenery::saveGlobal(const string &filepath) const { PackStream stream; double app_header = (double)APP_HEADER; double version_header = (double)DATA_VERSION; @@ -47,11 +47,11 @@ Scenery::FileOperationResult Scenery::saveGlobal(const std::string &filepath) co stream.write(&version_header); stream.write(&app_header); - Logs::debug() << "[Definition] Scenery saved to file: " << filepath << std::endl; + Logs::debug() << "[Definition] Scenery saved to file: " << filepath << endl; return FILE_OPERATION_OK; } -Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath) { +Scenery::FileOperationResult Scenery::loadGlobal(const string &filepath) { PackStream stream; double app_header, version_header; @@ -85,7 +85,7 @@ Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath) { return FILE_OPERATION_APP_MISMATCH; } - Logs::debug() << "[Definition] Scenery loaded from file: " << filepath << std::endl; + Logs::debug() << "[Definition] Scenery loaded from file: " << filepath << endl; return FILE_OPERATION_OK; } @@ -105,7 +105,7 @@ void Scenery::autoPreset(RandomGenerator &random) { validate(); - Logs::debug() << "[Definition] New scenery generated from seed " << random.getSeed() << std::endl; + Logs::debug() << "[Definition] New scenery generated from seed " << random.getSeed() << endl; } void Scenery::autoPreset(unsigned int seed) { diff --git a/src/definition/Scenery.h b/src/definition/Scenery.h index 12ba2e0..6304856 100644 --- a/src/definition/Scenery.h +++ b/src/definition/Scenery.h @@ -29,8 +29,8 @@ class DEFINITIONSHARED_EXPORT Scenery : public DefinitionNode { virtual void validate() override; - FileOperationResult saveGlobal(const std::string &filepath) const; - FileOperationResult loadGlobal(const std::string &filepath); + FileOperationResult saveGlobal(const string &filepath) const; + FileOperationResult loadGlobal(const string &filepath); virtual Scenery *getScenery() override; diff --git a/src/definition/TextureLayerDefinition.cpp b/src/definition/TextureLayerDefinition.cpp index 3cf97e3..47ef31f 100644 --- a/src/definition/TextureLayerDefinition.cpp +++ b/src/definition/TextureLayerDefinition.cpp @@ -8,7 +8,7 @@ #include "TerrainDefinition.h" #include "Color.h" -TextureLayerDefinition::TextureLayerDefinition(DefinitionNode *parent, const std::string &name) +TextureLayerDefinition::TextureLayerDefinition(DefinitionNode *parent, const string &name) : DefinitionNode(parent, name, "texturelayer") { terrain_zone = new Zone; _displacement_noise = new NoiseGenerator; diff --git a/src/definition/TextureLayerDefinition.h b/src/definition/TextureLayerDefinition.h index 6b52d1d..c326018 100644 --- a/src/definition/TextureLayerDefinition.h +++ b/src/definition/TextureLayerDefinition.h @@ -20,7 +20,7 @@ class DEFINITIONSHARED_EXPORT TextureLayerDefinition : public DefinitionNode { } TextureLayerPreset; public: - TextureLayerDefinition(DefinitionNode *parent, const std::string &name); + TextureLayerDefinition(DefinitionNode *parent, const string &name); virtual ~TextureLayerDefinition(); virtual void save(PackStream *stream) const override; diff --git a/src/definition/TexturesDefinition.cpp b/src/definition/TexturesDefinition.cpp index 77c10bc..6daf450 100644 --- a/src/definition/TexturesDefinition.cpp +++ b/src/definition/TexturesDefinition.cpp @@ -2,7 +2,7 @@ #include "TextureLayerDefinition.h" -static DefinitionNode *_layer_constructor(Layers *parent, const std::string &name) { +static DefinitionNode *_layer_constructor(Layers *parent, const string &name) { return new TextureLayerDefinition(parent, name); } diff --git a/src/interface/commandline/tests.cpp b/src/interface/commandline/tests.cpp index d88feb6..6680a4f 100644 --- a/src/interface/commandline/tests.cpp +++ b/src/interface/commandline/tests.cpp @@ -23,8 +23,8 @@ void startRender(SoftwareCanvasRenderer *renderer, const char *outputpath); -static void startTestRender(SoftwareCanvasRenderer *renderer, const std::string &name, int iteration = -1) { - std::ostringstream stream; +static void startTestRender(SoftwareCanvasRenderer *renderer, const string &name, int iteration = -1) { + ostringstream stream; stream << "pic_test_" << name; if (iteration >= 0) { diff --git a/src/interface/modeler/quickapp/FloatPropertyBind.cpp b/src/interface/modeler/quickapp/FloatPropertyBind.cpp index d8a58b5..f79cc87 100644 --- a/src/interface/modeler/quickapp/FloatPropertyBind.cpp +++ b/src/interface/modeler/quickapp/FloatPropertyBind.cpp @@ -15,7 +15,7 @@ FloatPropertyBind::FloatPropertyBind(MainModelerWindow *window, const QString &o connect(item, SIGNAL(changed(double)), this, SLOT(propertyChanged(double))); } else { item = NULL; - Logs::error() << "Can't find object :" << object_name.toStdString() << std::endl; + Logs::error() << "Can't find object :" << object_name.toStdString() << endl; } } diff --git a/src/interface/modeler/quickapp/IntPropertyBind.cpp b/src/interface/modeler/quickapp/IntPropertyBind.cpp index 8931a63..fdd61e7 100644 --- a/src/interface/modeler/quickapp/IntPropertyBind.cpp +++ b/src/interface/modeler/quickapp/IntPropertyBind.cpp @@ -13,7 +13,7 @@ IntPropertyBind::IntPropertyBind(MainModelerWindow *window, const QString &objec connect(item, SIGNAL(changed(int)), this, SLOT(propertyChanged(int))); } else { item = NULL; - Logs::error() << "Can't find object :" << object_name.toStdString() << std::endl; + Logs::error() << "Can't find object :" << object_name.toStdString() << endl; } } diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index c1e1965..a032c16 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -74,7 +74,7 @@ void MainModelerWindow::setQmlProperty(const QString &objectName, const QString if (item) { item->setProperty(propertyName.toLocal8Bit(), value); } else { - Logs::error() << "QML object not found :" << objectName.toStdString() << std::endl; + Logs::error() << "QML object not found :" << objectName.toStdString() << endl; } } @@ -84,7 +84,7 @@ void MainModelerWindow::connectQmlSignal(const QString &objectName, const char * if (item) { connect(item, signal, receiver, method); } else { - Logs::error() << "QML object not found :" << objectName.toStdString() << std::endl; + Logs::error() << "QML object not found :" << objectName.toStdString() << endl; } } @@ -137,8 +137,8 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) { } else if (event->key() == Qt::Key_F6) { render_process->showPreviousRender(); } else if (event->key() == Qt::Key_F12) { - Logs::warning() << "Current scenery dump:" << std::endl - << scenery->toString() << std::endl; + Logs::warning() << "Current scenery dump:" << endl + << scenery->toString() << endl; } else if (event->key() == Qt::Key_N) { if (event->modifiers() & Qt::ControlModifier) { newFile(); diff --git a/src/render/opengl/OpenGLPart.cpp b/src/render/opengl/OpenGLPart.cpp index 997e132..f8ae32e 100644 --- a/src/render/opengl/OpenGLPart.cpp +++ b/src/render/opengl/OpenGLPart.cpp @@ -30,7 +30,7 @@ void OpenGLPart::destroy() { void OpenGLPart::interrupt() { } -OpenGLShaderProgram *OpenGLPart::createShader(const std::string &name) { +OpenGLShaderProgram *OpenGLPart::createShader(const string &name) { OpenGLShaderProgram *program = new OpenGLShaderProgram(name, renderer); if (shaders.find(name) == shaders.end()) { diff --git a/src/render/opengl/OpenGLPart.h b/src/render/opengl/OpenGLPart.h index b37a89d..7067a16 100644 --- a/src/render/opengl/OpenGLPart.h +++ b/src/render/opengl/OpenGLPart.h @@ -40,7 +40,7 @@ class OPENGLSHARED_EXPORT OpenGLPart { * * The returned shader's ownership remains in this object. It will taks care of the destruction. */ - OpenGLShaderProgram *createShader(const std::string &name); + OpenGLShaderProgram *createShader(const string &name); /** * Create a vertex array. @@ -55,8 +55,8 @@ class OPENGLSHARED_EXPORT OpenGLPart { OpenGLRenderer *renderer; private: - std::map shaders; - std::vector arrays; + map shaders; + vector arrays; }; } } diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 20549bb..a669398 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -60,10 +60,10 @@ OpenGLRenderer::~OpenGLRenderer() { delete shared_state; } -void OpenGLRenderer::checkForErrors(const std::string &domain) { +void OpenGLRenderer::checkForErrors(const string &domain) { int error_code; while ((error_code = functions->glGetError()) != GL_NO_ERROR) { - Logs::warning() << "[OpenGL] Error in " << domain << " : " << error_code << std::endl; + Logs::warning() << "[OpenGL] Error in " << domain << " : " << error_code << endl; } } @@ -82,7 +82,7 @@ void OpenGLRenderer::initialize() { if (ready) { Logs::debug() << "[OpenGL] renderer started (version " << functions->glGetString(GL_VERSION) - << ", glsl version " << functions->glGetString(GL_SHADING_LANGUAGE_VERSION) << ")" << std::endl; + << ", glsl version " << functions->glGetString(GL_SHADING_LANGUAGE_VERSION) << ")" << endl; prepareOpenGLState(); @@ -105,7 +105,7 @@ void OpenGLRenderer::initialize() { checkForErrors("initialize"); } else { - Logs::error() << "[OpenGL] Failed to initialize api bindings" << std::endl; + Logs::error() << "[OpenGL] Failed to initialize api bindings" << endl; } } diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index 1fac9bc..44f7edd 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -42,7 +42,7 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer { * * Will write the error on standard error output, with the *domain* specified. */ - void checkForErrors(const std::string &domain); + void checkForErrors(const string &domain); /** * Release any allocated resource in the opengl context. diff --git a/src/render/opengl/OpenGLShaderProgram.cpp b/src/render/opengl/OpenGLShaderProgram.cpp index da06458..a3bc2fd 100644 --- a/src/render/opengl/OpenGLShaderProgram.cpp +++ b/src/render/opengl/OpenGLShaderProgram.cpp @@ -12,7 +12,7 @@ #include "Color.h" #include "Logs.h" -OpenGLShaderProgram::OpenGLShaderProgram(const std::string &name, OpenGLRenderer *renderer) +OpenGLShaderProgram::OpenGLShaderProgram(const string &name, OpenGLRenderer *renderer) : renderer(renderer), name(name) { program = new QOpenGLShaderProgram(); functions = renderer->getOpenGlFunctions(); @@ -23,30 +23,30 @@ OpenGLShaderProgram::~OpenGLShaderProgram() { delete program; } -void OpenGLShaderProgram::addVertexSource(const std::string &path) { +void OpenGLShaderProgram::addVertexSource(const string &path) { QFile file(QString(":/shaders/%1.vert").arg(QString::fromStdString(path))); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { source_vertex += QString(file.readAll()).toStdString(); } else { - Logs::error() << "[OpenGL] Can't open vertex file " << file.fileName().toStdString() << std::endl; + Logs::error() << "[OpenGL] Can't open vertex file " << file.fileName().toStdString() << endl; } } -void OpenGLShaderProgram::addFragmentSource(const std::string &path) { +void OpenGLShaderProgram::addFragmentSource(const string &path) { QFile file(QString(":/shaders/%1.frag").arg(QString::fromStdString(path))); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { source_fragment += QString(file.readAll()).toStdString(); } else { - Logs::error() << "[OpenGL] Can't open fragment file " << file.fileName().toStdString() << std::endl; + Logs::error() << "[OpenGL] Can't open fragment file " << file.fileName().toStdString() << endl; } } -void OpenGLShaderProgram::destroy(OpenGLFunctions *functions) { +void OpenGLShaderProgram::destroy(OpenGLFunctions *) { program->removeAllShaders(); } void OpenGLShaderProgram::compile() { - std::string prefix = std::string("#version ") + OPENGL_GLSL_VERSION + "\n\n"; + string prefix = string("#version ") + OPENGL_GLSL_VERSION + "\n\n"; program->addShaderFromSourceCode(QOpenGLShader::Vertex, QString::fromStdString(prefix + source_vertex)); program->addShaderFromSourceCode(QOpenGLShader::Fragment, QString::fromStdString(prefix + source_fragment)); @@ -55,13 +55,13 @@ void OpenGLShaderProgram::compile() { program->bindAttributeLocation("uv", 1); if (not program->link()) { - Logs::warning() << "[OpenGL] Error while compiling shader " << name << std::endl - << program->log().toStdString() << std::endl; + Logs::warning() << "[OpenGL] Error while compiling shader " << name << endl + << program->log().toStdString() << endl; } else if (program->log().length() > 0) { - Logs::debug() << "[OpenGL] Shader " << name << " compilation output:" << std::endl - << program->log().toStdString() << std::endl; + Logs::debug() << "[OpenGL] Shader " << name << " compilation output:" << endl + << program->log().toStdString() << endl; } else { - Logs::debug() << "[OpenGL] Shader " << name << " compiled" << std::endl; + Logs::debug() << "[OpenGL] Shader " << name << " compiled" << endl; } } diff --git a/src/render/opengl/OpenGLShaderProgram.h b/src/render/opengl/OpenGLShaderProgram.h index af3d93b..b0d5857 100644 --- a/src/render/opengl/OpenGLShaderProgram.h +++ b/src/render/opengl/OpenGLShaderProgram.h @@ -10,11 +10,11 @@ namespace opengl { class OPENGLSHARED_EXPORT OpenGLShaderProgram { public: - OpenGLShaderProgram(const std::string &name, OpenGLRenderer *renderer); + OpenGLShaderProgram(const string &name, OpenGLRenderer *renderer); ~OpenGLShaderProgram(); - void addVertexSource(const std::string &path); - void addFragmentSource(const std::string &path); + void addVertexSource(const string &path); + void addFragmentSource(const string &path); /** * Release any allocated resource in the opengl context. @@ -55,12 +55,12 @@ class OPENGLSHARED_EXPORT OpenGLShaderProgram { OpenGLRenderer *renderer; - std::string name; + string name; QOpenGLShaderProgram *program; OpenGLFunctions *functions; - std::string source_vertex; - std::string source_fragment; + string source_vertex; + string source_fragment; }; } } diff --git a/src/render/opengl/OpenGLSharedState.cpp b/src/render/opengl/OpenGLSharedState.cpp index ad6eacb..1ff1feb 100644 --- a/src/render/opengl/OpenGLSharedState.cpp +++ b/src/render/opengl/OpenGLSharedState.cpp @@ -21,7 +21,7 @@ void OpenGLSharedState::destroy(OpenGLFunctions *functions) { } } -OpenGLVariable *OpenGLSharedState::get(const std::string &name) { +OpenGLVariable *OpenGLSharedState::get(const string &name) { OpenGLVariable *&var = variables[name]; if (var == NULL) { var = new OpenGLVariable(name); diff --git a/src/render/opengl/OpenGLSharedState.h b/src/render/opengl/OpenGLSharedState.h index 8185e6d..e715e0f 100644 --- a/src/render/opengl/OpenGLSharedState.h +++ b/src/render/opengl/OpenGLSharedState.h @@ -34,42 +34,42 @@ class OPENGLSHARED_EXPORT OpenGLSharedState { /** * Get or create a variable in the state. */ - OpenGLVariable *get(const std::string &name); + OpenGLVariable *get(const string &name); // Shortcuts - inline void set(const std::string &name, const Texture2D *texture, bool repeat = false, bool color = true) { + inline void set(const string &name, const Texture2D *texture, bool repeat = false, bool color = true) { get(name)->set(texture, repeat, color); } - inline void set(const std::string &name, const QImage &texture, bool repeat = false, bool color = true) { + inline void set(const string &name, const QImage &texture, bool repeat = false, bool color = true) { get(name)->set(texture, repeat, color); } - inline void set(const std::string &name, const Texture3D *texture, bool repeat = false, bool color = true) { + inline void set(const string &name, const Texture3D *texture, bool repeat = false, bool color = true) { get(name)->set(texture, repeat, color); } - inline void set(const std::string &name, const Texture4D *texture, bool repeat = false, bool color = true) { + inline void set(const string &name, const Texture4D *texture, bool repeat = false, bool color = true) { get(name)->set(texture, repeat, color); } - inline void set(const std::string &name, float value) { + inline void set(const string &name, float value) { get(name)->set(value); } - inline void set(const std::string &name, const Vector3 &vector) { + inline void set(const string &name, const Vector3 &vector) { get(name)->set(vector); } - inline void set(const std::string &name, const QVector3D &vector) { + inline void set(const string &name, const QVector3D &vector) { get(name)->set(vector); } - inline void set(const std::string &name, const Matrix4 &matrix) { + inline void set(const string &name, const Matrix4 &matrix) { get(name)->set(matrix); } - inline void set(const std::string &name, const QMatrix4x4 &matrix) { + inline void set(const string &name, const QMatrix4x4 &matrix) { get(name)->set(matrix); } - inline void set(const std::string &name, const Color &color) { + inline void set(const string &name, const Color &color) { get(name)->set(color); } private: - std::map variables; + map variables; }; } } diff --git a/src/render/opengl/OpenGLVariable.cpp b/src/render/opengl/OpenGLVariable.cpp index b45402d..aee7858 100644 --- a/src/render/opengl/OpenGLVariable.cpp +++ b/src/render/opengl/OpenGLVariable.cpp @@ -17,7 +17,7 @@ #include "Texture3D.h" #include "Texture4D.h" -OpenGLVariable::OpenGLVariable(const std::string &name) : name(name) { +OpenGLVariable::OpenGLVariable(const string &name) : name(name) { type = TYPE_NONE; texture_toupload = false; texture_id = 0; @@ -35,7 +35,7 @@ OpenGLVariable::~OpenGLVariable() { delete[] value_texture_data; if (texture_id) { - Logs::warning() << "[OpenGL] Texture ID not freed " << texture_id << std::endl; + Logs::warning() << "[OpenGL] Texture ID not freed " << texture_id << endl; } } diff --git a/src/render/opengl/OpenGLVariable.h b/src/render/opengl/OpenGLVariable.h index d2d5aa6..2ffce1a 100644 --- a/src/render/opengl/OpenGLVariable.h +++ b/src/render/opengl/OpenGLVariable.h @@ -28,7 +28,7 @@ class OpenGLVariable { } OpenGLVariableType; public: - OpenGLVariable(const std::string &name); + OpenGLVariable(const string &name); ~OpenGLVariable(); void apply(OpenGLShaderProgram *program, int &texture_unit); @@ -55,7 +55,7 @@ class OpenGLVariable { void uploadTexture(OpenGLRenderer *renderer); private: - std::string name; + string name; OpenGLVariableType type; float value_float; diff --git a/src/render/opengl/OpenGLVertexArray.cpp b/src/render/opengl/OpenGLVertexArray.cpp index 185b786..4cef172 100644 --- a/src/render/opengl/OpenGLVertexArray.cpp +++ b/src/render/opengl/OpenGLVertexArray.cpp @@ -23,7 +23,7 @@ OpenGLVertexArray::OpenGLVertexArray(bool has_uv, bool strip) : has_uv(has_uv) { OpenGLVertexArray::~OpenGLVertexArray() { if (vao || vbo_vertex || vbo_uv) { - Logs::warning() << "[OpenGL] VertexArray not freed in OpenGL state before destructor called" << std::endl; + Logs::warning() << "[OpenGL] VertexArray not freed in OpenGL state before destructor called" << endl; } free(array_vertex); @@ -79,7 +79,7 @@ void OpenGLVertexArray::set(int index, const Vector3 &location, double u, double array_uv[index * 2 + 1] = v; changed = true; } else { - Logs::error() << "[OpenGL] Setting vertex data outside of array bounds" << std::endl; + Logs::error() << "[OpenGL] Setting vertex data outside of array bounds" << endl; } } @@ -91,7 +91,7 @@ void OpenGLVertexArray::get(int index, Vector3 *location, double *u, double *v) *u = array_uv[index * 2]; *v = array_uv[index * 2 + 1]; } else { - Logs::error() << "[OpenGL] Getting vertex data outside of array bounds" << std::endl; + Logs::error() << "[OpenGL] Getting vertex data outside of array bounds" << endl; } } diff --git a/src/render/software/AtmosphereModelBruneton.cpp b/src/render/software/AtmosphereModelBruneton.cpp index 459239f..e29c439 100644 --- a/src/render/software/AtmosphereModelBruneton.cpp +++ b/src/render/software/AtmosphereModelBruneton.cpp @@ -1130,7 +1130,7 @@ AtmosphereResult AtmosphereModelBruneton::applyAerialPerspective(Vector3 locatio return result; } -bool AtmosphereModelBruneton::getLightsAt(std::vector &result, const Vector3 &location) const { +bool AtmosphereModelBruneton::getLightsAt(vector &result, const Vector3 &location) const { LightComponent sun, irradiance; double muS; diff --git a/src/render/software/AtmosphereModelBruneton.h b/src/render/software/AtmosphereModelBruneton.h index 889fecc..8ef56f8 100644 --- a/src/render/software/AtmosphereModelBruneton.h +++ b/src/render/software/AtmosphereModelBruneton.h @@ -15,7 +15,7 @@ class SOFTWARESHARED_EXPORT AtmosphereModelBruneton : public LightSource { AtmosphereResult getSkyColor(Vector3 eye, const Vector3 &direction, const Vector3 &sun_position, const Color &base); AtmosphereResult applyAerialPerspective(Vector3 location, const Color &base); - virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override; + virtual bool getLightsAt(vector &result, const Vector3 &location) const override; /* Functions to get access to internal textures (for opengl shaders) */ Texture2D *getTextureTransmittance() const; diff --git a/src/render/software/AtmosphereRenderer.cpp b/src/render/software/AtmosphereRenderer.cpp index f84ef4c..8a4dc4c 100644 --- a/src/render/software/AtmosphereRenderer.cpp +++ b/src/render/software/AtmosphereRenderer.cpp @@ -92,7 +92,7 @@ Vector3 BaseAtmosphereRenderer::getSunDirection(bool) const { return Vector3(cos(sun_angle), sin(sun_angle), 0.0); } -bool BaseAtmosphereRenderer::getLightsAt(std::vector &, const Vector3 &) const { +bool BaseAtmosphereRenderer::getLightsAt(vector &, const Vector3 &) const { return false; } @@ -195,8 +195,7 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(const Vector3 & return result; } -bool SoftwareBrunetonAtmosphereRenderer::getLightsAt(std::vector &result, - const Vector3 &location) const { +bool SoftwareBrunetonAtmosphereRenderer::getLightsAt(vector &result, const Vector3 &location) const { bool changed = false; changed |= model->getLightsAt(result, location); changed |= parent->getNightSky()->getLightsAt(result, location); diff --git a/src/render/software/AtmosphereRenderer.h b/src/render/software/AtmosphereRenderer.h index 66b68da..e3bc749 100644 --- a/src/render/software/AtmosphereRenderer.h +++ b/src/render/software/AtmosphereRenderer.h @@ -18,7 +18,7 @@ class BaseAtmosphereRenderer : public LightSource { virtual AtmosphereResult getSkyColor(const Vector3 &direction); virtual Vector3 getSunDirection(bool cache = true) const; - virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override; + virtual bool getLightsAt(vector &result, const Vector3 &location) const override; protected: virtual AtmosphereDefinition *getDefinition() const; @@ -33,7 +33,7 @@ class SoftwareBrunetonAtmosphereRenderer : public BaseAtmosphereRenderer { virtual AtmosphereResult applyAerialPerspective(const Vector3 &location, const Color &base) override; virtual AtmosphereResult getSkyColor(const Vector3 &direction) override; - virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override; + virtual bool getLightsAt(vector &result, const Vector3 &location) const override; inline const AtmosphereModelBruneton *getModel() const { return model; diff --git a/src/render/software/Canvas.cpp b/src/render/software/Canvas.cpp index 929081d..af4cc91 100644 --- a/src/render/software/Canvas.cpp +++ b/src/render/software/Canvas.cpp @@ -99,7 +99,7 @@ CanvasPortion *Canvas::atPixel(int x, int y) const { return at(px, py); } -bool Canvas::saveToDisk(const std::string &filepath, const ColorProfile &profile, int antialias) const { +bool Canvas::saveToDisk(const string &filepath, const ColorProfile &profile, int antialias) const { assert(antialias >= 1); CanvasPictureWriter writer(this); diff --git a/src/render/software/Canvas.h b/src/render/software/Canvas.h index 0643b0e..3b60d9b 100644 --- a/src/render/software/Canvas.h +++ b/src/render/software/Canvas.h @@ -46,10 +46,10 @@ class SOFTWARESHARED_EXPORT Canvas { * * Returns true if the save was successful. */ - bool saveToDisk(const std::string &filepath, const ColorProfile &profile, int antialias) const; + bool saveToDisk(const string &filepath, const ColorProfile &profile, int antialias) const; private: - std::vector portions; + vector portions; int horizontal_portion_count; int vertical_portion_count; int width; diff --git a/src/render/software/CanvasPictureWriter.cpp b/src/render/software/CanvasPictureWriter.cpp index 01a91f3..17ac07f 100644 --- a/src/render/software/CanvasPictureWriter.cpp +++ b/src/render/software/CanvasPictureWriter.cpp @@ -37,7 +37,7 @@ void CanvasPictureWriter::setColorProfile(const ColorProfile &profile) { profile.copy(this->profile); } -bool CanvasPictureWriter::saveCanvas(const std::string &filepath) { +bool CanvasPictureWriter::saveCanvas(const string &filepath) { return save(filepath, width, height); } diff --git a/src/render/software/CanvasPictureWriter.h b/src/render/software/CanvasPictureWriter.h index d6c9ee6..40e65c7 100644 --- a/src/render/software/CanvasPictureWriter.h +++ b/src/render/software/CanvasPictureWriter.h @@ -31,7 +31,7 @@ class SOFTWARESHARED_EXPORT CanvasPictureWriter : public PictureWriter { * * Returns true if saving was successful. */ - bool saveCanvas(const std::string &filepath); + bool saveCanvas(const string &filepath); protected: virtual unsigned int getPixel(int x, int y) override; diff --git a/src/render/software/CanvasPortion.cpp b/src/render/software/CanvasPortion.cpp index 1af36cc..59ad418 100644 --- a/src/render/software/CanvasPortion.cpp +++ b/src/render/software/CanvasPortion.cpp @@ -18,13 +18,13 @@ assert(pixels != NULL) // Keep track of created files to erase them at program exit -static std::vector _files; +static vector _files; static void clean_all_files() { for (auto &filepath : _files) { FileSystem::removeFile(filepath); } } -static int _atexit = std::atexit(clean_all_files); +static int _atexit = atexit(clean_all_files); CanvasPortion::CanvasPortion(int index, CanvasPreview *preview) : index(index), preview(preview) { width = 1; @@ -86,8 +86,7 @@ void CanvasPortion::discardPixels(bool save) { void CanvasPortion::saveToDisk() { if (pixels) { auto pid = System::getProcessId(); - filepath = - FileSystem::getTempFile("paysages_portion_" + std::to_string(index) + "_" + std::to_string(pid) + ".dat"); + filepath = FileSystem::getTempFile("paysages_portion_" + to_string(index) + "_" + to_string(pid) + ".dat"); PackStream stream; stream.bindToFile(filepath, true); stream.write(&width); diff --git a/src/render/software/CanvasPortion.h b/src/render/software/CanvasPortion.h index 4e52bda..b1695ad 100644 --- a/src/render/software/CanvasPortion.h +++ b/src/render/software/CanvasPortion.h @@ -89,7 +89,7 @@ class SOFTWARESHARED_EXPORT CanvasPortion { int yoffset; CanvasPixel *pixels; CanvasPreview *preview; - std::string filepath; + string filepath; }; } } diff --git a/src/render/software/CloudsRenderer.cpp b/src/render/software/CloudsRenderer.cpp index 5f36c6f..1b4ba22 100644 --- a/src/render/software/CloudsRenderer.cpp +++ b/src/render/software/CloudsRenderer.cpp @@ -100,7 +100,7 @@ BaseCloudLayerRenderer *CloudsRenderer::getLayerRenderer(unsigned int layer) { if (layer < layer_renderers.size()) { return layer_renderers[layer]; } else { - Logs::warning() << "Asked for unknown layer renderer " << layer << std::endl; + Logs::warning() << "Asked for unknown layer renderer " << layer << endl; return fake_renderer; } } @@ -109,7 +109,7 @@ BaseCloudsModel *CloudsRenderer::getLayerModel(unsigned int layer) { if (layer < layer_models.size()) { return layer_models[layer]; } else { - Logs::warning() << "Asked for unknown layer model" << layer << std::endl; + Logs::warning() << "Asked for unknown layer model" << layer << endl; return fake_model; } } @@ -121,7 +121,7 @@ void CloudsRenderer::setLayerModel(unsigned int layer, BaseCloudsModel *model, b } layer_models[layer] = model; } else { - Logs::warning() << "Asked to set an unknown layer model" << layer << std::endl; + Logs::warning() << "Asked to set an unknown layer model" << layer << endl; delete model; } } diff --git a/src/render/software/CloudsRenderer.h b/src/render/software/CloudsRenderer.h index 7112af4..585d9a7 100644 --- a/src/render/software/CloudsRenderer.h +++ b/src/render/software/CloudsRenderer.h @@ -80,10 +80,10 @@ class SOFTWARESHARED_EXPORT CloudsRenderer : public LightFilter { bool enabled; SoftwareRenderer *parent; - std::vector layer_renderers; + vector layer_renderers; BaseCloudLayerRenderer *fake_renderer; - std::vector layer_models; + vector layer_models; BaseCloudsModel *fake_model; }; } diff --git a/src/render/software/FluidMediumManager.h b/src/render/software/FluidMediumManager.h index 96e4624..8f5b759 100644 --- a/src/render/software/FluidMediumManager.h +++ b/src/render/software/FluidMediumManager.h @@ -53,7 +53,7 @@ class SOFTWARESHARED_EXPORT FluidMediumManager { private: SoftwareRenderer *renderer; - std::vector media; + vector media; }; } } diff --git a/src/render/software/LightSource.h b/src/render/software/LightSource.h index 20f6e45..d2f3b54 100644 --- a/src/render/software/LightSource.h +++ b/src/render/software/LightSource.h @@ -20,7 +20,7 @@ class SOFTWARESHARED_EXPORT LightSource { * * Returns true if lights were added to *result*. */ - virtual bool getLightsAt(std::vector &result, const Vector3 &location) const = 0; + virtual bool getLightsAt(vector &result, const Vector3 &location) const = 0; }; } } diff --git a/src/render/software/LightStatus.h b/src/render/software/LightStatus.h index d0c36ba..99871e5 100644 --- a/src/render/software/LightStatus.h +++ b/src/render/software/LightStatus.h @@ -48,7 +48,7 @@ class SOFTWARESHARED_EXPORT LightStatus { Vector3 location; Vector3 eye; bool filtered; - std::vector components; + vector components; }; } } diff --git a/src/render/software/LightingManager.cpp b/src/render/software/LightingManager.cpp index f247da9..8ad0fe6 100644 --- a/src/render/software/LightingManager.cpp +++ b/src/render/software/LightingManager.cpp @@ -38,14 +38,14 @@ void LightingManager::clearSources() { } void LightingManager::registerSource(LightSource *source) { - if (std::find(sources.begin(), sources.end(), source) == sources.end()) { + if (find(sources.begin(), sources.end(), source) == sources.end()) { sources.push_back(source); } } void LightingManager::unregisterSource(LightSource *source) { - if (std::find(sources.begin(), sources.end(), source) != sources.end()) { - sources.erase(std::find(sources.begin(), sources.end(), source)); + if (find(sources.begin(), sources.end(), source) != sources.end()) { + sources.erase(find(sources.begin(), sources.end(), source)); } } @@ -54,14 +54,14 @@ void LightingManager::clearFilters() { } void LightingManager::registerFilter(LightFilter *filter) { - if (std::find(filters.begin(), filters.end(), filter) == filters.end()) { + if (find(filters.begin(), filters.end(), filter) == filters.end()) { filters.push_back(filter); } } void LightingManager::unregisterFilter(LightFilter *filter) { - if (std::find(filters.begin(), filters.end(), filter) != filters.end()) { - filters.erase(std::find(filters.begin(), filters.end(), filter)); + if (find(filters.begin(), filters.end(), filter) != filters.end()) { + filters.erase(find(filters.begin(), filters.end(), filter)); } } @@ -165,7 +165,7 @@ void LightingManager::fillStatus(LightStatus &status, const Vector3 &location) c status.pushComponent(light); } for (auto source : sources) { - std::vector lights; + vector lights; if (source->getLightsAt(lights, location)) { for (auto &light : lights) { status.pushComponent(light); diff --git a/src/render/software/LightingManager.h b/src/render/software/LightingManager.h index ec503bc..83b0cd3 100644 --- a/src/render/software/LightingManager.h +++ b/src/render/software/LightingManager.h @@ -102,9 +102,9 @@ class SOFTWARESHARED_EXPORT LightingManager { private: bool specularity; bool filtering; - std::vector static_lights; - std::vector filters; - std::vector sources; + vector static_lights; + vector filters; + vector sources; }; } } diff --git a/src/render/software/NightSky.cpp b/src/render/software/NightSky.cpp index 810e2a8..c48316f 100644 --- a/src/render/software/NightSky.cpp +++ b/src/render/software/NightSky.cpp @@ -83,7 +83,7 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction) { return result; } -bool NightSky::getLightsAt(std::vector &result, const Vector3 &) const { +bool NightSky::getLightsAt(vector &result, const Vector3 &) const { LightComponent moon, sky; AtmosphereDefinition *atmosphere = renderer->getScenery()->getAtmosphere(); diff --git a/src/render/software/NightSky.h b/src/render/software/NightSky.h index b7e1d7a..696ddc2 100644 --- a/src/render/software/NightSky.h +++ b/src/render/software/NightSky.h @@ -27,7 +27,7 @@ class SOFTWARESHARED_EXPORT NightSky : public LightSource { */ virtual const Color getColor(double altitude, const Vector3 &direction); - virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override; + virtual bool getLightsAt(vector &result, const Vector3 &location) const override; private: SoftwareRenderer *renderer; diff --git a/src/render/software/RenderProgress.cpp b/src/render/software/RenderProgress.cpp index 3ba5df2..23916ce 100644 --- a/src/render/software/RenderProgress.cpp +++ b/src/render/software/RenderProgress.cpp @@ -72,7 +72,7 @@ void RenderProgress::exitSub() { void RenderProgress::end() { if (subs.size() > 0) { - Logs::error() << subs.size() << " progress subs remaining at the end of render" << std::endl; + Logs::error() << subs.size() << " progress subs remaining at the end of render" << endl; } end_time = Time::getRelativeTimeMs(); diff --git a/src/render/software/RenderProgress.h b/src/render/software/RenderProgress.h index d9da550..2602e22 100644 --- a/src/render/software/RenderProgress.h +++ b/src/render/software/RenderProgress.h @@ -58,7 +58,7 @@ class SOFTWARESHARED_EXPORT RenderProgress { double prev_est_done; double prev_est_speed; - std::stack subs; + stack subs; }; } } diff --git a/src/render/software/SoftwareCanvasRenderer.cpp b/src/render/software/SoftwareCanvasRenderer.cpp index 7a41632..d6ba8ed 100644 --- a/src/render/software/SoftwareCanvasRenderer.cpp +++ b/src/render/software/SoftwareCanvasRenderer.cpp @@ -131,7 +131,7 @@ const Rasterizer &SoftwareCanvasRenderer::getRasterizer(int client_id) const { return *(rasterizers[client_id]); } -bool SoftwareCanvasRenderer::saveToDisk(const std::string &filepath) const { +bool SoftwareCanvasRenderer::saveToDisk(const string &filepath) const { return getCanvas()->saveToDisk(filepath, *getCanvas()->getPreview()->getToneMapping(), samples); } diff --git a/src/render/software/SoftwareCanvasRenderer.h b/src/render/software/SoftwareCanvasRenderer.h index 1e5b30c..5669b0b 100644 --- a/src/render/software/SoftwareCanvasRenderer.h +++ b/src/render/software/SoftwareCanvasRenderer.h @@ -94,7 +94,7 @@ class SOFTWARESHARED_EXPORT SoftwareCanvasRenderer : public SoftwareRenderer { * * Returns true if the save was successful. */ - bool saveToDisk(const std::string &filepath) const; + bool saveToDisk(const string &filepath) const; protected: /** @@ -112,7 +112,7 @@ class SOFTWARESHARED_EXPORT SoftwareCanvasRenderer : public SoftwareRenderer { Canvas *canvas; int samples; - std::vector rasterizers; + vector rasterizers; bool started; bool finished; bool interrupted; diff --git a/src/system/CacheFile.cpp b/src/system/CacheFile.cpp index 5762411..ca87dc9 100644 --- a/src/system/CacheFile.cpp +++ b/src/system/CacheFile.cpp @@ -3,8 +3,8 @@ #include #include "DataFile.h" -CacheFile::CacheFile(const std::string &module, const std::string &ext, const std::string &tag1, int tag2, int tag3, - int tag4, int tag5, int tag6) { +CacheFile::CacheFile(const string &module, const string &ext, const string &tag1, int tag2, int tag3, int tag4, + int tag5, int tag6) { filepath = QString("cache/%1-%2-%3-%4-%5-%6-%7.%8") .arg(QString::fromStdString(module)) .arg(QString::fromStdString(tag1)) @@ -23,7 +23,7 @@ bool CacheFile::isReadable() { fclose(f); return true; } else { - std::string datapath = DataFile::findFile(filepath); + string datapath = DataFile::findFile(filepath); if (datapath.empty()) { return false; } else { @@ -48,8 +48,8 @@ bool CacheFile::isWritable() { } } -std::string CacheFile::getPath() { - std::string datapath = DataFile::findFile(filepath); +string CacheFile::getPath() { + string datapath = DataFile::findFile(filepath); if (datapath.empty()) { return filepath; } else { diff --git a/src/system/CacheFile.h b/src/system/CacheFile.h index b64d4b9..1afa527 100644 --- a/src/system/CacheFile.h +++ b/src/system/CacheFile.h @@ -8,15 +8,15 @@ namespace system { class SYSTEMSHARED_EXPORT CacheFile { public: - CacheFile(const std::string &module, const std::string &ext, const std::string &tag1, int tag2, int tag3, int tag4, - int tag5, int tag6); + CacheFile(const string &module, const string &ext, const string &tag1, int tag2, int tag3, int tag4, int tag5, + int tag6); bool isReadable(); bool isWritable(); - std::string getPath(); + string getPath(); private: - std::string filepath; + string filepath; }; } } diff --git a/src/system/DataFile.cpp b/src/system/DataFile.cpp index a73acf4..2eb7274 100644 --- a/src/system/DataFile.cpp +++ b/src/system/DataFile.cpp @@ -3,7 +3,7 @@ #include "Logs.h" #include -std::string DataFile::findFile(const std::string &relpath) { +string DataFile::findFile(const string &relpath) { if (dataDir.empty()) { dataDir = initDataDir(); } @@ -16,16 +16,16 @@ std::string DataFile::findFile(const std::string &relpath) { } } -std::string DataFile::findDir(const std::string &relpath) { +string DataFile::findDir(const string &relpath) { return findFile(relpath); } bool DataFile::tryDataDir(const QDir &dir) { - Logs::debug() << "[System] Try data dir " << dir.absolutePath().toStdString() << std::endl; + Logs::debug() << "[System] Try data dir " << dir.absolutePath().toStdString() << endl; return dir.exists("data/.paysages_data"); } -std::string DataFile::locateDataDir() { +string DataFile::locateDataDir() { QDir dir = QDir::current(); int i = 0; @@ -47,16 +47,16 @@ std::string DataFile::locateDataDir() { return ""; } -std::string DataFile::initDataDir() { - std::string parent = locateDataDir(); +string DataFile::initDataDir() { + string parent = locateDataDir(); if (parent.empty()) { - Logs::warning() << "[System] Data files not found" << std::endl; + Logs::warning() << "[System] Data files not found" << endl; return parent; } else { - std::string result = QDir(QString::fromStdString(parent)).absoluteFilePath("data").toStdString(); - Logs::debug() << "[System] Data files found : " << result << std::endl; + string result = QDir(QString::fromStdString(parent)).absoluteFilePath("data").toStdString(); + Logs::debug() << "[System] Data files found : " << result << endl; return result; } } -std::string DataFile::dataDir; +string DataFile::dataDir; diff --git a/src/system/DataFile.h b/src/system/DataFile.h index 3048f4e..d893dbc 100644 --- a/src/system/DataFile.h +++ b/src/system/DataFile.h @@ -18,20 +18,20 @@ class SYSTEMSHARED_EXPORT DataFile { * * Return the absolute data path, or an empty string if not found. */ - static std::string findFile(const std::string &relpath); + static string findFile(const string &relpath); /** * Find a data directory. * * Return the absolute data path, or an empty string if not found. */ - static std::string findDir(const std::string &relpath); + static string findDir(const string &relpath); private: static bool tryDataDir(const QDir &dir); - static std::string locateDataDir(); - static std::string initDataDir(); - static std::string dataDir; + static string locateDataDir(); + static string initDataDir(); + static string dataDir; }; } } diff --git a/src/system/FileSystem.cpp b/src/system/FileSystem.cpp index d4b962b..348ea60 100644 --- a/src/system/FileSystem.cpp +++ b/src/system/FileSystem.cpp @@ -4,15 +4,15 @@ #include #include -std::string FileSystem::getTempFile(const std::string &filename) { +string FileSystem::getTempFile(const string &filename) { return QDir::temp().filePath(QString::fromStdString(filename)).toStdString(); } -bool FileSystem::isFile(const std::string &filepath) { +bool FileSystem::isFile(const string &filepath) { return QFileInfo(QString::fromStdString(filepath)).exists(); } -bool FileSystem::removeFile(const std::string &filepath) { +bool FileSystem::removeFile(const string &filepath) { if (FileSystem::isFile(filepath)) { remove(filepath.c_str()); return true; diff --git a/src/system/FileSystem.h b/src/system/FileSystem.h index 2acd06c..c313b14 100644 --- a/src/system/FileSystem.h +++ b/src/system/FileSystem.h @@ -13,17 +13,17 @@ class SYSTEMSHARED_EXPORT FileSystem { * * filename must not contain directory separators. */ - static std::string getTempFile(const std::string &filename); + static string getTempFile(const string &filename); /** * Returns true if the given path points to a file. */ - static bool isFile(const std::string &filepath); + static bool isFile(const string &filepath); /** * Remove a file by its absolute path. */ - static bool removeFile(const std::string &filepath); + static bool removeFile(const string &filepath); }; } } diff --git a/src/system/Logs.cpp b/src/system/Logs.cpp index ebab594..f19317a 100644 --- a/src/system/Logs.cpp +++ b/src/system/Logs.cpp @@ -5,16 +5,15 @@ #include #include -template > class basic_nullbuf : public std::basic_streambuf { +template > class basic_nullbuf : public basic_streambuf { typename traits::int_type overflow(typename traits::int_type c) { return traits::not_eof(c); // indicate success } }; -template > -class basic_onullstream : public std::basic_ostream { +template > class basic_onullstream : public basic_ostream { public: - basic_onullstream() : std::basic_ios(&m_sbuf), std::basic_ostream(&m_sbuf) { + basic_onullstream() : basic_ios(&m_sbuf), basic_ostream(&m_sbuf) { this->init(&m_sbuf); } @@ -26,39 +25,39 @@ typedef basic_onullstream onullstream; static onullstream NULL_STREAM; static bool enabled = true; -std::ostream &Logs::debug() { +ostream &Logs::debug() { #ifdef NDEBUG return NULL_STREAM; #else if (enabled) { - std::cout << "DEBUG - "; - return std::cout; + cout << "DEBUG - "; + return cout; } else { return NULL_STREAM; } #endif } -std::ostream &Logs::warning() { +ostream &Logs::warning() { if (enabled) { - std::cerr << "WARN - "; - return std::cerr; + cerr << "WARN - "; + return cerr; } else { return NULL_STREAM; } } -std::ostream &Logs::error() { +ostream &Logs::error() { if (enabled) { - std::cerr << "ERROR - "; - return std::cerr; + cerr << "ERROR - "; + return cerr; } else { return NULL_STREAM; } } -void Logs::debugTimestamp(const std::string &message) { - debug() << Time::getRelativeTimeMs() << " - " << message << std::endl; +void Logs::debugTimestamp(const string &message) { + debug() << Time::getRelativeTimeMs() << " - " << message << endl; } void Logs::disable() { diff --git a/src/system/Logs.h b/src/system/Logs.h index 641aeb2..8d12535 100644 --- a/src/system/Logs.h +++ b/src/system/Logs.h @@ -13,12 +13,12 @@ namespace system { */ class SYSTEMSHARED_EXPORT Logs { public: - static std::ostream &debug(); - static std::ostream &warning(); - static std::ostream &error(); + static ostream &debug(); + static ostream &warning(); + static ostream &error(); // Log a timestamp on the debug output - static void debugTimestamp(const std::string &message); + static void debugTimestamp(const string &message); // Disable all logs from now on static void disable(); diff --git a/src/system/PackStream.cpp b/src/system/PackStream.cpp index acc8aa8..58e4c8c 100644 --- a/src/system/PackStream.cpp +++ b/src/system/PackStream.cpp @@ -25,7 +25,7 @@ PackStream::PackStream(const PackStream *other) { buffer = new QByteArray(); if (other->file) { Logs::error() << "Try to read from a substream bound to a file: " << other->file->fileName().toStdString() - << std::endl; + << endl; stream = new QDataStream(buffer, QIODevice::ReadOnly); } else { stream = new QDataStream(other->buffer, QIODevice::ReadOnly); @@ -33,14 +33,14 @@ PackStream::PackStream(const PackStream *other) { stream->setVersion(QDataStream::Qt_5_2); } -PackStream::PackStream(const std::string &buffer_content) { +PackStream::PackStream(const string &buffer_content) { file = NULL; buffer = new QByteArray(buffer_content.c_str(), buffer_content.size()); stream = new QDataStream(buffer, QIODevice::ReadOnly); stream->setVersion(QDataStream::Qt_5_2); } -bool PackStream::bindToFile(const std::string &filepath, bool write) { +bool PackStream::bindToFile(const string &filepath, bool write) { if (not file) { file = new QFile(QString::fromStdString(filepath)); if (not file->open(write ? QIODevice::WriteOnly : QIODevice::ReadOnly)) { @@ -80,14 +80,14 @@ void PackStream::write(const char *value, int max_length) { } } -void PackStream::write(const std::string &value) { +void PackStream::write(const string &value) { *stream << QString::fromStdString(value); } void PackStream::writeFromBuffer(const PackStream &other, bool prepend_size) { if (other.file) { Logs::error() << "Try to write from a substream bound to a file: " << other.file->fileName().toStdString() - << std::endl; + << endl; } else { if (prepend_size) { int buffer_size = (int)other.buffer->size(); @@ -97,10 +97,9 @@ void PackStream::writeFromBuffer(const PackStream &other, bool prepend_size) { } } -std::string PackStream::getBuffer() { +string PackStream::getBuffer() { if (file) { - Logs::error() << "Try to get buffer on a stream bound to a file: " << file->fileName().toStdString() - << std::endl; + Logs::error() << "Try to get buffer on a stream bound to a file: " << file->fileName().toStdString() << endl; return ""; } else { return buffer->toStdString(); @@ -132,7 +131,7 @@ void PackStream::read(char *value, int max_length) { } } -std::string PackStream::readString() { +string PackStream::readString() { if (not stream->atEnd()) { QString output; *stream >> output; diff --git a/src/system/PackStream.h b/src/system/PackStream.h index d72da78..80e573d 100644 --- a/src/system/PackStream.h +++ b/src/system/PackStream.h @@ -28,14 +28,14 @@ class SYSTEMSHARED_EXPORT PackStream { /** * Open a reading stream on a buffer content. */ - PackStream(const std::string &buffer_content); + PackStream(const string &buffer_content); - bool bindToFile(const std::string &filepath, bool write = false); + bool bindToFile(const string &filepath, bool write = false); void write(const int *value); void write(const double *value); void write(const char *value, const int max_length); - void write(const std::string &value); + void write(const string &value); /** * Write the contents of another stream into this one. @@ -49,12 +49,12 @@ class SYSTEMSHARED_EXPORT PackStream { /** * Get the contents of the memory buffer, if this stream is not bound to a file. */ - std::string getBuffer(); + string getBuffer(); void read(int *value); void read(double *value); void read(char *value, int max_length); - std::string readString(); + string readString(); void skip(const int &value, int count = 1); void skip(const double &value, int count = 1); diff --git a/src/system/ParallelPool.h b/src/system/ParallelPool.h index 206f975..899923a 100644 --- a/src/system/ParallelPool.h +++ b/src/system/ParallelPool.h @@ -35,7 +35,7 @@ class SYSTEMSHARED_EXPORT ParallelPool { bool running; private: - std::vector threads; + vector threads; }; } } diff --git a/src/system/PictureWriter.cpp b/src/system/PictureWriter.cpp index ec06e78..36c9bb5 100644 --- a/src/system/PictureWriter.cpp +++ b/src/system/PictureWriter.cpp @@ -2,7 +2,7 @@ #include -bool PictureWriter::save(const std::string &filepath, int width, int height) { +bool PictureWriter::save(const string &filepath, int width, int height) { QImage result(width, height, QImage::Format_ARGB32); for (int y = 0; y < height; y++) { diff --git a/src/system/PictureWriter.h b/src/system/PictureWriter.h index 372b9f7..8dcab57 100644 --- a/src/system/PictureWriter.h +++ b/src/system/PictureWriter.h @@ -11,7 +11,7 @@ class SYSTEMSHARED_EXPORT PictureWriter { /** * @brief Start saving the picture in a file. */ - bool save(const std::string &filepath, int width, int height); + bool save(const string &filepath, int width, int height); protected: /** diff --git a/src/system/RandomGenerator.cpp b/src/system/RandomGenerator.cpp index 78703c8..4ea9779 100644 --- a/src/system/RandomGenerator.cpp +++ b/src/system/RandomGenerator.cpp @@ -11,17 +11,17 @@ class RandomGenerator::RandomGeneratorPrivate { RandomGeneratorPrivate(unsigned int seed) : generator(seed) { } - std::default_random_engine generator; - std::uniform_real_distribution distribution_double; + default_random_engine generator; + uniform_real_distribution distribution_double; }; RandomGenerator::RandomGenerator(RandomGenerator::Seed seed) { if (not seed) { - std::random_device true_random; + random_device true_random; if (true_random.entropy()) { seed = true_random(); } else { - seed = std::chrono::system_clock::now().time_since_epoch().count(); + seed = chrono::system_clock::now().time_since_epoch().count(); } } data = new RandomGeneratorPrivate(seed); diff --git a/src/system/system_global.h b/src/system/system_global.h index 0ff1270..d23ea54 100644 --- a/src/system/system_global.h +++ b/src/system/system_global.h @@ -36,4 +36,6 @@ extern RandomGenerator &RandomGeneratorDefault; } using namespace paysages::system; +using namespace std; + #endif // SYSTEM_GLOBAL_H diff --git a/src/tests/ColorHSL_Test.cpp b/src/tests/ColorHSL_Test.cpp index 85d0933..c356a46 100644 --- a/src/tests/ColorHSL_Test.cpp +++ b/src/tests/ColorHSL_Test.cpp @@ -4,7 +4,7 @@ #include "ColorHSL.h" TEST(ColorHSL, colorFromHSL) { - std::vector colors; + vector colors; colors.push_back(Color()); colors.push_back(Color(1.0, 0.0, 0.0, 1.0)); colors.push_back(Color(0.7, 0.5, 0.3, 1.0)); diff --git a/src/tests/GodRaysSampler_Test.cpp b/src/tests/GodRaysSampler_Test.cpp index 466f7cc..5fb14b0 100644 --- a/src/tests/GodRaysSampler_Test.cpp +++ b/src/tests/GodRaysSampler_Test.cpp @@ -59,7 +59,7 @@ TEST(GodRaysSampler, setQuality) { } class GodRayLightSource : public LightSource { - virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override { + virtual bool getLightsAt(vector &result, const Vector3 &location) const override { LightComponent light; light.direction = VECTOR_DOWN; light.altered = true; diff --git a/src/tests/Layers_Test.cpp b/src/tests/Layers_Test.cpp index 8dc559a..bda6a23 100644 --- a/src/tests/Layers_Test.cpp +++ b/src/tests/Layers_Test.cpp @@ -6,11 +6,11 @@ #include "IntNode.h" #include "DefinitionDiff.h" -static DefinitionNode *_construc1(Layers *, const std::string &name) { +static DefinitionNode *_construc1(Layers *, const string &name) { return new DefinitionNode(NULL, name); } -static DefinitionNode *_construc2(Layers *parent, const std::string &name) { +static DefinitionNode *_construc2(Layers *parent, const string &name) { DefinitionNode *result = new DefinitionNode(parent, name); return result; } @@ -104,7 +104,7 @@ TEST(Layers, saveLoad) { EXPECT_EQ("second", layers2.getLayer(1)->getName()); } -static void checkLayerChild(const Layers &layers, int layer, const std::string &name, int value) { +static void checkLayerChild(const Layers &layers, int layer, const string &name, int value) { ASSERT_EQ(1, layers.getLayerCount()); ASSERT_TRUE(layers.getLayer(layer)->findByPath(name)); ASSERT_EQ("int", layers.getLayer(layer)->findByPath(name)->getTypeName()); @@ -113,13 +113,13 @@ static void checkLayerChild(const Layers &layers, int layer, const std::string & class TestLayer : public DefinitionNode { public: - TestLayer(Layers *parent, const std::string &name) : DefinitionNode(parent, name) { + TestLayer(Layers *parent, const string &name) : DefinitionNode(parent, name) { val = new IntNode(this, "val", 5); } IntNode *val; }; -static DefinitionNode *_construc3(Layers *parent, const std::string &name) { +static DefinitionNode *_construc3(Layers *parent, const string &name) { return new TestLayer(parent, name); } @@ -174,7 +174,7 @@ TEST(Layers, undoRedo) { TEST(Layers, generateInitDiffs) { Layers layers(NULL, "layers", _construc1); - std::vector diffs; + vector diffs; layers.generateInitDiffs(&diffs); EXPECT_EQ(0, (int)diffs.size()); diff --git a/src/tests/LightingManager_Test.cpp b/src/tests/LightingManager_Test.cpp index 97a111d..da12f12 100644 --- a/src/tests/LightingManager_Test.cpp +++ b/src/tests/LightingManager_Test.cpp @@ -5,7 +5,7 @@ #include "LightFilter.h" class FakeLightSource : public LightSource { - virtual bool getLightsAt(std::vector &, const Vector3 &) const override { + virtual bool getLightsAt(vector &, const Vector3 &) const override { return false; } }; diff --git a/src/tests/SpaceSegment_Test.cpp b/src/tests/SpaceSegment_Test.cpp index 4916795..eef1635 100644 --- a/src/tests/SpaceSegment_Test.cpp +++ b/src/tests/SpaceSegment_Test.cpp @@ -5,7 +5,7 @@ class CollectGridIterator : public SpaceGridIterator { public: - std::vector locations; + vector locations; protected: virtual bool onCell(int x, int y, int z) override { From 9cece93ec1b35e959110841dc3bee4f7f44accf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 11 Dec 2015 01:12:55 +0100 Subject: [PATCH 3/4] Refactored opengl parts --- src/render/opengl/OpenGLPart.cpp | 8 ++- src/render/opengl/OpenGLPart.h | 13 ++++- src/render/opengl/OpenGLRenderer.cpp | 73 ++++++++++++++-------------- src/render/opengl/OpenGLRenderer.h | 4 ++ src/render/opengl/OpenGLSkybox.cpp | 2 +- src/render/opengl/OpenGLTerrain.cpp | 2 +- src/render/opengl/OpenGLTerrain.h | 4 +- src/render/opengl/OpenGLWater.cpp | 2 +- src/render/opengl/opengl_global.h | 2 +- 9 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/render/opengl/OpenGLPart.cpp b/src/render/opengl/OpenGLPart.cpp index f8ae32e..e0902cc 100644 --- a/src/render/opengl/OpenGLPart.cpp +++ b/src/render/opengl/OpenGLPart.cpp @@ -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); diff --git a/src/render/opengl/OpenGLPart.h b/src/render/opengl/OpenGLPart.h index 7067a16..106d78a 100644 --- a/src/render/opengl/OpenGLPart.h +++ b/src/render/opengl/OpenGLPart.h @@ -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 shaders; vector arrays; }; diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index a669398..ee0febf 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -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() { - paused = true; - terrain->pause(); + if (not paused) { + paused = true; + for (auto part : parts) { + part->pause(); + } + } } void OpenGLRenderer::resume() { - paused = false; - terrain->resume(); + if (paused) { + for (auto part : parts) { + part->resume(); + } + paused = false; + } } void OpenGLRenderer::setMouseLocation(int x, int y) { diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index 44f7edd..89678d3 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -5,6 +5,8 @@ #include "SoftwareRenderer.h" +#include + class QMatrix4x4; namespace paysages { @@ -135,6 +137,8 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer { OpenGLSkybox *skybox; OpenGLWater *water; OpenGLTerrain *terrain; + + vector parts; }; } } diff --git a/src/render/opengl/OpenGLSkybox.cpp b/src/render/opengl/OpenGLSkybox.cpp index 87718d7..5070a96 100644 --- a/src/render/opengl/OpenGLSkybox.cpp +++ b/src/render/opengl/OpenGLSkybox.cpp @@ -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"); diff --git a/src/render/opengl/OpenGLTerrain.cpp b/src/render/opengl/OpenGLTerrain.cpp index 491a7ec..afa02fc 100644 --- a/src/render/opengl/OpenGLTerrain.cpp +++ b/src/render/opengl/OpenGLTerrain.cpp @@ -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; diff --git a/src/render/opengl/OpenGLTerrain.h b/src/render/opengl/OpenGLTerrain.h index 5aebb5e..8c8cd20 100644 --- a/src/render/opengl/OpenGLTerrain.h +++ b/src/render/opengl/OpenGLTerrain.h @@ -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; } diff --git a/src/render/opengl/OpenGLWater.cpp b/src/render/opengl/OpenGLWater.cpp index aa394fa..160c291 100644 --- a/src/render/opengl/OpenGLWater.cpp +++ b/src/render/opengl/OpenGLWater.cpp @@ -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"); diff --git a/src/render/opengl/opengl_global.h b/src/render/opengl/opengl_global.h index 1acd4d8..a9c95fd 100644 --- a/src/render/opengl/opengl_global.h +++ b/src/render/opengl/opengl_global.h @@ -11,8 +11,8 @@ namespace paysages { namespace opengl { -class WidgetExplorer; class OpenGLRenderer; +class OpenGLPart; class OpenGLShaderProgram; class OpenGLSharedState; class OpenGLVariable; From b54bd65df9055f55d333aeb386a26e8558e8a18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 11 Dec 2015 01:39:47 +0100 Subject: [PATCH 4/4] Added DefinitionWatcher.startWatching --- src/definition/DefinitionWatcher.cpp | 12 +++++++++ src/definition/DefinitionWatcher.h | 6 +++++ src/render/opengl/OpenGLSkybox.cpp | 37 +++++++++++++++---------- src/render/opengl/OpenGLWater.cpp | 40 +++++++++++++++++----------- 4 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/definition/DefinitionWatcher.cpp b/src/definition/DefinitionWatcher.cpp index 888ed13..6c46820 100644 --- a/src/definition/DefinitionWatcher.cpp +++ b/src/definition/DefinitionWatcher.cpp @@ -1,4 +1,16 @@ #include "DefinitionWatcher.h" +#include "DefinitionNode.h" +#include "Logs.h" + DefinitionWatcher::DefinitionWatcher() { } + +void DefinitionWatcher::startWatching(const DefinitionNode *root, const string &path, bool init_diff) { + DefinitionNode *node = root->findByPath(path); + if (node) { + node->addWatcher(this, init_diff); + } else { + Logs::warning() << "[Definition] Node not found for watching : " << path << endl; + } +} diff --git a/src/definition/DefinitionWatcher.h b/src/definition/DefinitionWatcher.h index 84ee460..a0fb8db 100644 --- a/src/definition/DefinitionWatcher.h +++ b/src/definition/DefinitionWatcher.h @@ -19,6 +19,12 @@ class DEFINITIONSHARED_EXPORT DefinitionWatcher { * Abstract method called when a node changed. */ virtual void nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff) = 0; + + protected: + /** + * Start watching a path in a definition tree. + */ + void startWatching(const DefinitionNode *root, const std::string &path, bool init_diff = true); }; } } diff --git a/src/render/opengl/OpenGLSkybox.cpp b/src/render/opengl/OpenGLSkybox.cpp index 5070a96..bde8335 100644 --- a/src/render/opengl/OpenGLSkybox.cpp +++ b/src/render/opengl/OpenGLSkybox.cpp @@ -10,6 +10,11 @@ #include "AtmosphereRenderer.h" #include "AtmosphereModelBruneton.h" #include "FloatNode.h" +#include "Logs.h" + +static const std::string path_daytime = "/atmosphere/daytime"; +static const std::string path_humidity = "/atmosphere/humidity"; +static const std::string path_sun_radius = "/atmosphere/sun_radius"; OpenGLSkybox::OpenGLSkybox(OpenGLRenderer *renderer) : OpenGLPart(renderer, "skybox") { program = createShader("skybox"); @@ -50,12 +55,15 @@ OpenGLSkybox::~OpenGLSkybox() { void OpenGLSkybox::initialize() { // Watch for definition changes - renderer->getScenery()->getAtmosphere()->propDayTime()->addWatcher(this, true); - renderer->getScenery()->getAtmosphere()->propHumidity()->addWatcher(this, true); - renderer->getScenery()->getAtmosphere()->propSunRadius()->addWatcher(this, true); + Scenery *scenery = renderer->getScenery(); + startWatching(scenery, path_daytime); + startWatching(scenery, path_humidity); + startWatching(scenery, path_sun_radius); } void OpenGLSkybox::update() { + Logs::debug() << "[OpenGL] Updating atmosphere textures" << endl; + SoftwareBrunetonAtmosphereRenderer *bruneton = (SoftwareBrunetonAtmosphereRenderer *)renderer->getAtmosphereRenderer(); renderer->getSharedState()->set("transmittanceTexture", bruneton->getModel()->getTextureTransmittance()); @@ -67,19 +75,20 @@ void OpenGLSkybox::render() { } void OpenGLSkybox::nodeChanged(const DefinitionNode *node, const DefinitionDiff *) { - if (node->getPath() == "/atmosphere/daytime") { + OpenGLSharedState *state = renderer->getSharedState(); + AtmosphereDefinition *newdef = renderer->getScenery()->getAtmosphere(); + + if (node->getPath() == path_daytime) { Vector3 sun_direction = renderer->getAtmosphereRenderer()->getSunDirection(false); - renderer->getSharedState()->set("sunDirection", sun_direction); + state->set("sunDirection", sun_direction); - Color sun_color = renderer->getScenery()->getAtmosphere()->sun_color; - renderer->getSharedState()->set("sunColor", sun_color); + Color sun_color = newdef->sun_color; + state->set("sunColor", sun_color); - renderer->getSharedState()->set("dayTime", renderer->getScenery()->getAtmosphere()->propDayTime()->getValue()); - } else if (node->getPath() == "/atmosphere/humidity") { - renderer->getSharedState()->set("atmosphereHumidity", - renderer->getScenery()->getAtmosphere()->propHumidity()->getValue()); - } else if (node->getPath() == "/atmosphere/sun_radius") { - renderer->getSharedState()->set("sunRadius", - renderer->getScenery()->getAtmosphere()->propSunRadius()->getValue()); + state->set("dayTime", newdef->propDayTime()->getValue()); + } else if (node->getPath() == path_humidity) { + state->set("atmosphereHumidity", newdef->propHumidity()->getValue()); + } else if (node->getPath() == path_sun_radius) { + state->set("sunRadius", newdef->propSunRadius()->getValue()); } } diff --git a/src/render/opengl/OpenGLWater.cpp b/src/render/opengl/OpenGLWater.cpp index 160c291..325791f 100644 --- a/src/render/opengl/OpenGLWater.cpp +++ b/src/render/opengl/OpenGLWater.cpp @@ -12,6 +12,11 @@ #include "FloatNode.h" #include "FloatDiff.h" #include "IntNode.h" +#include "Logs.h" + +static const std::string path_height = "/terrain/water_height"; +static const std::string path_reflection = "/water/reflection"; +static const std::string path_model = "/water/model"; OpenGLWater::OpenGLWater(OpenGLRenderer *renderer) : OpenGLPart(renderer, "water") { enabled = true; @@ -38,19 +43,23 @@ OpenGLWater::~OpenGLWater() { void OpenGLWater::initialize() { // Watch for definition changes - renderer->getScenery()->getTerrain()->propWaterHeight()->addWatcher(this, true); - renderer->getScenery()->getWater()->propReflection()->addWatcher(this, true); - renderer->getScenery()->getWater()->propModel()->addWatcher(this, false); + Scenery *scenery = renderer->getScenery(); + startWatching(scenery, path_height); + startWatching(scenery, path_reflection); + startWatching(scenery, path_model, false); } void OpenGLWater::update() { - WaterDefinition *water = renderer->getScenery()->getWater(); - renderer->getSharedState()->set("waterMaterialColor", *water->material->base); - renderer->getSharedState()->set("waterMaterialReflection", water->material->reflection); - renderer->getSharedState()->set("waterMaterialShininess", water->material->shininess); - renderer->getSharedState()->set("waterMaterialHardness", water->material->hardness); + OpenGLSharedState *state = renderer->getSharedState(); - renderer->getSharedState()->set("simplexSampler", NoiseFunctionSimplex::getNormalTexture(), true, true); + WaterDefinition *water = renderer->getScenery()->getWater(); + state->set("waterMaterialColor", *water->material->base); + state->set("waterMaterialReflection", water->material->reflection); + state->set("waterMaterialShininess", water->material->shininess); + state->set("waterMaterialHardness", water->material->hardness); + + Logs::debug() << "[OpenGL] Updating simplex texture" << endl; + state->set("simplexSampler", NoiseFunctionSimplex::getNormalTexture(), true, true); } void OpenGLWater::render() { @@ -60,12 +69,13 @@ void OpenGLWater::render() { } void OpenGLWater::nodeChanged(const DefinitionNode *node, const DefinitionDiff *) { - if (node->getPath() == "/terrain/water_height") { - renderer->getSharedState()->set("waterOffset", renderer->getScenery()->getTerrain()->getWaterOffset()); - } else if (node->getPath() == "/water/reflection") { - renderer->getSharedState()->set("waterReflection", - renderer->getScenery()->getWater()->propReflection()->getValue()); - } else if (node->getPath() == "/water/model") { + OpenGLSharedState *state = renderer->getSharedState(); + + if (node->getPath() == path_height) { + state->set("waterOffset", renderer->getScenery()->getTerrain()->getWaterOffset()); + } else if (node->getPath() == path_reflection) { + state->set("waterReflection", renderer->getScenery()->getWater()->propReflection()->getValue()); + } else if (node->getPath() == path_model) { update(); } }