mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 19:29:04 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user