paysages3d/src/render/opengl/OpenGLPart.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

2013-12-21 22:48:54 +00:00
#include "OpenGLPart.h"
#include "OpenGLRenderer.h"
2013-12-21 22:48:54 +00:00
#include "OpenGLShaderProgram.h"
2015-12-07 22:32:55 +00:00
#include "OpenGLVertexArray.h"
2013-12-21 22:48:54 +00:00
OpenGLPart::OpenGLPart(OpenGLRenderer *renderer) : renderer(renderer) {
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-07 22:32:55 +00:00
OpenGLShaderProgram *OpenGLPart::createShader(const std::string &name) {
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();
}
}