Make use of UniformCache in many Renderables and switch from setUniform(const std::string&, ...) to setUniform(GLint, ...) in those cases

This commit is contained in:
Alexander Bock
2017-12-31 17:31:10 -05:00
parent 8ea5837f00
commit 47233b8e6f
41 changed files with 1329 additions and 855 deletions
+18 -16
View File
@@ -37,6 +37,7 @@
#include <openspace/properties/vector/vec3property.h>
#include <ghoul/glm.h>
#include <ghoul/opengl/uniformcache.h>
#include <memory>
#include <vector>
@@ -46,28 +47,29 @@ namespace ghoul::opengl { class ProgramObject; }
namespace openspace {
class TouchMarker : public properties::PropertyOwner {
public:
TouchMarker();
public:
TouchMarker();
bool initialize();
bool deinitialize();
void initialize();
void deinitialize();
void render(const std::vector<TUIO::TuioCursor>& list);
void render(const std::vector<TUIO::TuioCursor>& list);
private:
void createVertexList(const std::vector<TUIO::TuioCursor>& list);
private:
void createVertexList(const std::vector<TUIO::TuioCursor>& list);
properties::BoolProperty _visible;
properties::FloatProperty _radiusSize;
properties::FloatProperty _transparency;
properties::FloatProperty _thickness;
properties::Vec3Property _color;
properties::BoolProperty _visible;
properties::FloatProperty _radiusSize;
properties::FloatProperty _transparency;
properties::FloatProperty _thickness;
properties::Vec3Property _color;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
UniformCache(radius, transparency, thickness, color) _uniformCache;
GLuint _quad = 0;
GLuint _vertexPositionBuffer = 0;
int _numFingers = 0;
GLuint _quad = 0;
GLuint _vertexPositionBuffer = 0;
int _numFingers = 0;
};
} // openspace namespace
+16 -18
View File
@@ -89,24 +89,23 @@ TouchMarker::TouchMarker()
addProperty(_color);
}
bool TouchMarker::initialize() {
void TouchMarker::initialize() {
glGenVertexArrays(1, &_quad); // generate array
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
try {
_shader = OsEng.renderEngine().buildRenderProgram(
"MarkerProgram",
absPath("${MODULE_TOUCH}/shaders/marker_vs.glsl"),
absPath("${MODULE_TOUCH}/shaders/marker_fs.glsl")
);
}
catch (const ghoul::opengl::ShaderObject::ShaderCompileError& e) {
LERRORC(e.component, e.what());
}
return (_shader != nullptr);
_shader = OsEng.renderEngine().buildRenderProgram(
"MarkerProgram",
absPath("${MODULE_TOUCH}/shaders/marker_vs.glsl"),
absPath("${MODULE_TOUCH}/shaders/marker_fs.glsl")
);
_uniformCache.radius = _shader->uniformLocation("radius");
_uniformCache.transparency = _shader->uniformLocation("transparency");
_uniformCache.thickness = _shader->uniformLocation("thickness");
_uniformCache.color = _shader->uniformLocation("color");
}
bool TouchMarker::deinitialize() {
void TouchMarker::deinitialize() {
glDeleteVertexArrays(1, &_quad);
_quad = 0;
@@ -118,7 +117,6 @@ bool TouchMarker::deinitialize() {
renderEngine.removeRenderProgram(_shader);
_shader = nullptr;
}
return true;
}
void TouchMarker::render(const std::vector<TUIO::TuioCursor>& list) {
@@ -126,10 +124,10 @@ void TouchMarker::render(const std::vector<TUIO::TuioCursor>& list) {
createVertexList(list);
_shader->activate();
_shader->setUniform("radius", _radiusSize);
_shader->setUniform("transparency", _transparency);
_shader->setUniform("thickness", _thickness);
_shader->setUniform("color", _color.value());
_shader->setUniform(_uniformCache.radius, _radiusSize);
_shader->setUniform(_uniformCache.transparency, _transparency);
_shader->setUniform(_uniformCache.thickness, _thickness);
_shader->setUniform(_uniformCache.color, _color.value());
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);