Merge branch 'master' into vegetation

Conflicts:
	src/render/opengl/OpenGLRenderer.cpp
	src/render/opengl/OpenGLRenderer.h
	src/render/opengl/OpenGLShaderProgram.cpp
	src/render/opengl/OpenGLShaderProgram.h
	src/render/opengl/OpenGLSharedState.cpp
This commit is contained in:
Michaël Lemaire 2015-12-04 00:04:07 +01:00
commit e346f07c22
17 changed files with 130 additions and 82 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@
/output/
/perf.*
/pic*.png
core
*.pro.user
*.pro.user.*
qrc_*.cpp

View file

@ -110,8 +110,8 @@ bool DefinitionNode::applyDiff(const DefinitionDiff *diff, bool) {
if (diff->getTypeName() == type_name) {
return true;
} else {
Logs::error() << "Can't apply " << diff->getTypeName() << " diff to " << getName() << " " << type_name
<< " node" << std::endl;
Logs::error() << "[Definition] Can't apply " << diff->getTypeName() << " diff to " << getName() << " "
<< type_name << " node" << std::endl;
return false;
}
}
@ -155,8 +155,8 @@ void DefinitionNode::save(PackStream *stream) const {
child->save(stream);
} else {
// Child size not known, write it to a temporary stream to know it
Logs::debug() << "Unknown size for child " << child->name << ", unefficient writing to temporary stream"
<< std::endl;
Logs::debug() << "[Definition] Unknown size for child " << child->name
<< ", unefficient writing to temporary stream" << std::endl;
PackStream substream;
child->save(&substream);
stream->writeFromBuffer(substream, true);
@ -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() << "Skipped unknown child '" << child_name << "'" << std::endl;
Logs::warning() << "[Definition] Skipped unknown child '" << child_name << "'" << std::endl;
}
}
}
@ -196,12 +196,13 @@ void DefinitionNode::copy(DefinitionNode *destination) const {
if (dest_child) {
child->copy(dest_child);
} else {
Logs::warning() << "Can't copy to child " << child->name << " of " << destination->getTypeName()
<< std::endl;
Logs::warning() << "[Definition] Can't copy to child " << child->name << " of "
<< destination->getTypeName() << std::endl;
}
}
} else {
Logs::error() << "Can't copy from " << getTypeName() << " to " << destination->getTypeName() << std::endl;
Logs::error() << "[Definition] Can't copy from " << getTypeName() << " to " << destination->getTypeName()
<< std::endl;
}
}
@ -225,7 +226,7 @@ void DefinitionNode::removeChild(DefinitionNode *child) {
child->parent = NULL;
children.erase(it);
} else {
Logs::warning() << "Trying to remove not found child '" << child->name << "' from '" << name << "'"
Logs::warning() << "[Definition] Trying to remove not found child '" << child->name << "' from '" << name << "'"
<< std::endl;
}
}

View file

@ -49,7 +49,7 @@ Scenery::FileOperationResult Scenery::saveGlobal(const std::string &filepath) co
stream.write(&version_header);
stream.write(&app_header);
Logs::debug() << "Scenery saved to file: " << filepath << std::endl;
Logs::debug() << "[Definition] Scenery saved to file: " << filepath << std::endl;
return FILE_OPERATION_OK;
}
@ -87,7 +87,7 @@ Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath) {
return FILE_OPERATION_APP_MISMATCH;
}
Logs::debug() << "Scenery loaded from file: " << filepath << std::endl;
Logs::debug() << "[Definition] Scenery loaded from file: " << filepath << std::endl;
return FILE_OPERATION_OK;
}
@ -113,7 +113,7 @@ void Scenery::autoPreset(int seed) {
validate();
Logs::debug() << "New scenery generated from seed " << seed << std::endl;
Logs::debug() << "[Definition] New scenery generated from seed " << seed << std::endl;
}
void Scenery::setAtmosphere(AtmosphereDefinition *atmosphere) {

View file

@ -16,6 +16,11 @@
#include <QGuiApplication>
MainModelerWindow::MainModelerWindow() {
/*QSurfaceFormat new_format = format();
new_format.setVersion(3, 3);
new_format.setProfile(QSurfaceFormat::CoreProfile);
setFormat(new_format);*/
scenery = new Scenery();
scenery->autoPreset();

View file

@ -20,7 +20,6 @@ OpenGLView::OpenGLView(QQuickItem *parent) : QQuickItem(parent) {
connect(this, SIGNAL(windowChanged(QQuickWindow *)), this, SLOT(handleWindowChanged(QQuickWindow *)));
connect(this, SIGNAL(widthChanged()), this, SLOT(handleResize()));
connect(this, SIGNAL(heightChanged()), this, SLOT(handleResize()));
startTimer(50);
}
void OpenGLView::handleWindowChanged(QQuickWindow *win) {
@ -28,12 +27,11 @@ void OpenGLView::handleWindowChanged(QQuickWindow *win) {
window = qobject_cast<MainModelerWindow *>(win);
if (window) {
renderer = window->getRenderer();
connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
initialized = false;
win->setClearBeforeRendering(false);
initialized = false;
connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(handleSceneGraphReady()));
}
}
}
@ -66,6 +64,11 @@ void OpenGLView::handleResize() {
resized = true;
}
void OpenGLView::handleSceneGraphReady() {
connect(window, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
startTimer(50);
}
void OpenGLView::wheelEvent(QWheelEvent *event) {
if (not acceptInputs()) {
return;

View file

@ -17,6 +17,7 @@ class OpenGLView : public QQuickItem {
void handleWindowChanged(QQuickWindow *win);
void paint();
void handleResize();
void handleSceneGraphReady();
protected:
virtual void wheelEvent(QWheelEvent *event) override;

View file

@ -1,8 +1,8 @@
#include "ExplorerChunkTerrain.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include <cmath>
#include <QImage>
#include "OpenGLFunctions.h"
#include "ColorProfile.h"
#include "CameraDefinition.h"
#include "OpenGLRenderer.h"

View file

@ -0,0 +1,9 @@
#ifndef OPENGLFUNCTIONS
#define OPENGLFUNCTIONS
#include "opengl_global.h"
#define _OPENGL_FUNCTIONS_INCLUDE <OpenGLFunctions>
#include _OPENGL_FUNCTIONS_INCLUDE
#endif // OPENGLFUNCTIONS

View file

@ -1,6 +1,6 @@
#include "OpenGLRenderer.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include "OpenGLFunctions.h"
#include "CameraDefinition.h"
#include "OpenGLSharedState.h"
#include "OpenGLSkybox.h"
@ -72,10 +72,20 @@ void OpenGLRenderer::prepare() {
getVegetationRenderer()->setEnabled(false);
}
void OpenGLRenderer::checkForErrors(const std::string &domain) {
int error_code;
while ((error_code = functions->glGetError()) != GL_NO_ERROR) {
Logs::warning() << "[OpenGL] Error in " << domain << " : " << error_code << std::endl;
}
}
void OpenGLRenderer::initialize() {
bool init = functions->initializeOpenGLFunctions();
if (init) {
Logs::debug() << "[OpenGL] renderer started (version " << functions->glGetString(GL_VERSION)
<< ", glsl version " << functions->glGetString(GL_SHADING_LANGUAGE_VERSION) << ")" << std::endl;
prepareOpenGLState();
prepare();
@ -94,9 +104,10 @@ void OpenGLRenderer::initialize() {
cameraChangeEvent(render_camera);
checkForErrors("initialize");
ready = true;
} else {
Logs::error() << "Failed to initialize OpenGL bindings" << std::endl;
Logs::error() << "[OpenGL] Failed to initialize api bindings" << std::endl;
}
}
@ -144,25 +155,31 @@ void OpenGLRenderer::resize(int width, int height) {
cameraChangeEvent(render_camera);
prepareOpenGLState();
checkForErrors("resize");
}
}
void OpenGLRenderer::paint() {
if (ready and not paused) {
checkForErrors("before_paint");
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
skybox->render();
checkForErrors("skybox");
terrain->render();
checkForErrors("terrain");
water->render();
checkForErrors("water");
vegetation->render();
checkForErrors("vegetation");
if (mouse_tracking) {
updateMouseProjection();
}
int error_code;
while ((error_code = functions->glGetError()) != GL_NO_ERROR) {
Logs::warning() << "[OpenGL] ERROR : " << error_code << std::endl;
checkForErrors("mouse_tracking");
}
displayed = true;

View file

@ -36,6 +36,13 @@ class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer {
virtual void prepare() override;
/**
* Check for errors in OpenGL context.
*
* Will write the error on standard error output, with the *domain* specified.
*/
void checkForErrors(const std::string &domain);
void initialize();
void prepareOpenGLState();
void resize(int width, int height);

View file

@ -1,8 +1,8 @@
#include "OpenGLShaderProgram.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include <QOpenGLShaderProgram>
#include <QDir>
#include "OpenGLFunctions.h"
#include "OpenGLRenderer.h"
#include "OpenGLSharedState.h"
#include "Texture2D.h"
@ -29,7 +29,7 @@ void OpenGLShaderProgram::addVertexSource(QString path) {
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
source_vertex += QString(file.readAll()).toStdString();
} else {
Logs::error() << "Can't open vertex file " << file.fileName().toStdString() << std::endl;
Logs::error() << "[OpenGL] Can't open vertex file " << file.fileName().toStdString() << std::endl;
}
}
@ -38,7 +38,7 @@ void OpenGLShaderProgram::addFragmentSource(QString path) {
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
source_fragment += QString(file.readAll()).toStdString();
} else {
Logs::error() << "Can't open fragment file " << file.fileName().toStdString() << std::endl;
Logs::error() << "[OpenGL] Can't open fragment file " << file.fileName().toStdString() << std::endl;
}
}
@ -47,25 +47,30 @@ void OpenGLShaderProgram::compile() {
program->addShaderFromSourceCode(QOpenGLShader::Fragment, QString::fromStdString(source_fragment));
if (not program->link()) {
Logs::warning() << "Error while compiling shader " << name << std::endl
Logs::warning() << "[OpenGL] Error while compiling shader " << name << std::endl
<< program->log().toStdString() << std::endl;
} else if (program->log().length() > 0) {
Logs::debug() << "Shader " << name << " compilation output:" << std::endl
Logs::debug() << "[OpenGL] Shader " << name << " compilation output:" << std::endl
<< program->log().toStdString() << std::endl;
} else {
Logs::debug() << "[OpenGL] Shader " << name << " compiled" << std::endl;
}
}
void OpenGLShaderProgram::bind() {
bool OpenGLShaderProgram::bind() {
if (not compiled) {
compile();
compiled = true;
}
program->bind();
if (program->bind()) {
int texture_unit = 0;
renderer->getSharedState()->apply(this, texture_unit);
state->apply(this, texture_unit);
return true;
} else {
return false;
}
}
void OpenGLShaderProgram::release() {
@ -73,8 +78,7 @@ void OpenGLShaderProgram::release() {
}
void OpenGLShaderProgram::drawTriangles(float *vertices, int triangle_count) {
bind();
if (bind()) {
GLuint array_vertex = program->attributeLocation("vertex");
program->setAttributeArray(array_vertex, GL_FLOAT, vertices, 3);
program->enableAttributeArray(array_vertex);
@ -84,11 +88,11 @@ void OpenGLShaderProgram::drawTriangles(float *vertices, int triangle_count) {
program->disableAttributeArray(array_vertex);
release();
}
}
void OpenGLShaderProgram::drawTriangleStrip(float *vertices, int vertex_count) {
bind();
if (bind()) {
GLuint array_vertex = program->attributeLocation("vertex");
program->setAttributeArray(array_vertex, GL_FLOAT, vertices, 3);
program->enableAttributeArray(array_vertex);
@ -98,11 +102,11 @@ void OpenGLShaderProgram::drawTriangleStrip(float *vertices, int vertex_count) {
program->disableAttributeArray(array_vertex);
release();
}
}
void OpenGLShaderProgram::drawTrianglesUV(float *vertices, float *uv, int triangle_count) {
bind();
if (bind()) {
GLuint array_vertex = program->attributeLocation("vertex");
program->setAttributeArray(array_vertex, GL_FLOAT, vertices, 3);
program->enableAttributeArray(array_vertex);
@ -117,11 +121,11 @@ void OpenGLShaderProgram::drawTrianglesUV(float *vertices, float *uv, int triang
program->disableAttributeArray(array_uv);
release();
}
}
void OpenGLShaderProgram::drawTriangleStripUV(float *vertices, float *uv, int vertex_count) {
bind();
if (bind()) {
GLuint array_vertex = program->attributeLocation("vertex");
program->setAttributeArray(array_vertex, GL_FLOAT, vertices, 3);
program->enableAttributeArray(array_vertex);
@ -136,4 +140,5 @@ void OpenGLShaderProgram::drawTriangleStripUV(float *vertices, float *uv, int ve
program->disableAttributeArray(array_uv);
release();
}
}

View file

@ -24,7 +24,7 @@ class OPENGLSHARED_EXPORT OpenGLShaderProgram {
void drawTrianglesUV(float *vertices, float *uv, int triangle_count);
void drawTriangleStripUV(float *vertices, float *uv, int vertex_count);
void bind();
bool bind();
void release();
inline QOpenGLShaderProgram *getProgram() const {

View file

@ -1,6 +1,6 @@
#include "OpenGLTerrain.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include "OpenGLFunctions.h"
#include "OpenGLRenderer.h"
#include "OpenGLShaderProgram.h"
#include "ParallelPool.h"

View file

@ -1,8 +1,8 @@
#include "OpenGLVariable.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include <QOpenGLShaderProgram>
#include <cassert>
#include "OpenGLFunctions.h"
#include "OpenGLRenderer.h"
#include "OpenGLShaderProgram.h"
#include "Vector3.h"

View file

@ -1,10 +1,10 @@
#include "OpenGLVegetationLayer.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include <algorithm>
#include "Vector3.h"
#include "CameraDefinition.h"
#include "Mutex.h"
#include "OpenGLFunctions.h"
#include "OpenGLVegetation.h"
#include "OpenGLVegetationInstance.h"
#include "OpenGLVegetationImpostor.h"

View file

@ -3,9 +3,9 @@
#include "opengl_global.h"
#include OPENGL_FUNCTIONS_INCLUDE
#include <cassert>
#include <QOpenGLShaderProgram>
#include "OpenGLFunctions.h"
namespace paysages {
namespace opengl {

View file

@ -29,9 +29,8 @@ template <typename Vertex> class VertexArray;
}
using namespace paysages::opengl;
//#define OpenGLFunctions QOpenGLFunctions_3_2_Core
#define OpenGLFunctions QOpenGLFunctions_3_0
#define OPENGL_FUNCTIONS_INCLUDE <OpenGLFunctions>
//#define OpenGLFunctions QOpenGLFunctions_3_3_Core
class OpenGLFunctions;
#endif // OPENGL_GLOBAL_H