2013-12-21 22:48:54 +00:00
|
|
|
#include "OpenGLPart.h"
|
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
#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
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
OpenGLPart::OpenGLPart(OpenGLRenderer *renderer) : renderer(renderer) {
|
2013-12-21 22:48:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
OpenGLPart::~OpenGLPart() {
|
2015-12-10 22:41:42 +00:00
|
|
|
for (auto pair : shaders) {
|
2015-12-07 22:32:55 +00:00
|
|
|
delete pair.second;
|
|
|
|
}
|
2015-12-10 22:41:42 +00:00
|
|
|
for (auto array : arrays) {
|
2015-12-07 22:32:55 +00:00
|
|
|
delete array;
|
2013-12-21 22:48:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
void OpenGLPart::destroy() {
|
|
|
|
OpenGLFunctions *functions = getFunctions();
|
|
|
|
|
|
|
|
for (auto shader : shaders) {
|
|
|
|
shader.second->destroy(functions);
|
|
|
|
}
|
|
|
|
for (auto array : arrays) {
|
|
|
|
array->destroy(functions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void OpenGLPart::interrupt() {
|
2013-12-30 15:02:33 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2013-12-21 22:48:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
OpenGLFunctions *OpenGLPart::getFunctions() {
|
|
|
|
return renderer->getOpenGlFunctions();
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void OpenGLPart::updateScenery(bool onlyCommon) {
|
2013-12-21 22:48:54 +00:00
|
|
|
// Let subclass do its own collecting
|
2015-11-09 21:30:46 +00:00
|
|
|
if (not onlyCommon) {
|
2013-12-21 22:48:54 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|