paysages3d/src/render/opengl/OpenGLPart.cpp

74 lines
1.6 KiB
C++
Raw Normal View History

2013-12-21 22:48:54 +00:00
#include "OpenGLPart.h"
#include "OpenGLRenderer.h"
#include "OpenGLShaderProgram.h"
2015-12-07 22:32:55 +00:00
#include "OpenGLVertexArray.h"
2013-12-21 22:48:54 +00:00
2015-12-11 00:12:55 +00:00
OpenGLPart::OpenGLPart(OpenGLRenderer *renderer, const string &name) : renderer(renderer), name(name) {
2013-12-21 22:48:54 +00:00
}
OpenGLPart::~OpenGLPart() {
for (auto pair : shaders) {
2015-12-07 22:32:55 +00:00
delete pair.second;
}
for (auto array : arrays) {
2015-12-07 22:32:55 +00:00
delete array;
2013-12-21 22:48:54 +00:00
}
}
void OpenGLPart::destroy() {
OpenGLFunctions *functions = getFunctions();
for (auto shader : shaders) {
shader.second->destroy(functions);
}
for (auto array : arrays) {
array->destroy(functions);
}
}
void OpenGLPart::interrupt() {
}
2015-12-11 00:12:55 +00:00
void OpenGLPart::pause() {
}
void OpenGLPart::resume() {
}
2015-12-10 23:36:50 +00:00
OpenGLShaderProgram *OpenGLPart::createShader(const string &name) {
2015-12-07 22:32:55 +00:00
OpenGLShaderProgram *program = new OpenGLShaderProgram(name, renderer);
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
if (shaders.find(name) == shaders.end()) {
2013-12-21 22:48:54 +00:00
shaders[name] = program;
return program;
} else {
2013-12-21 22:48:54 +00:00
return 0;
}
}
OpenGLVertexArray *OpenGLPart::createVertexArray(bool has_uv, bool strip) {
2015-12-07 22:32:55 +00:00
OpenGLVertexArray *result = new OpenGLVertexArray(has_uv, strip);
arrays.push_back(result);
return result;
}
OpenGLFunctions *OpenGLPart::getFunctions() {
return renderer->getOpenGlFunctions();
}
void OpenGLPart::updateScenery(bool onlyCommon) {
2013-12-21 22:48:54 +00:00
// Let subclass do its own collecting
if (not onlyCommon) {
2013-12-21 22:48:54 +00:00
update();
}
}
Scenery *OpenGLPart::getScenery() const {
return renderer->getScenery();
}
OpenGLFunctions *OpenGLPart::getOpenGlFunctions() const {
return renderer->getOpenGlFunctions();
}