Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[idea / wip] - ofShader::setUniformBufferObject to easily pass a struct to a shader #8097

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libs/openFrameworks/gl/ofShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,15 @@ void ofShader::setUniform4i(const string & name, int v1, int v2, int v3, int v4)
}
}

//--------------------------------------------------------------
void ofShader::setUniformBufferObject(const std::string & name, const void * data, GLsizeiptr dataSize) {
if (!bufferObjectsCache[name].isAllocated()) {
bufferObjectsCache[name].allocate(dataSize, GL_STATIC_DRAW);
}
bufferObjectsCache[name].updateData(dataSize, data);
bufferObjectsCache[name].bindBase(GL_UNIFORM_BUFFER, getUniformBlockIndex(name));
}

//--------------------------------------------------------------
void ofShader::setUniform1f(const string & name, float v1) const {
if (bLoaded) {
Expand Down
6 changes: 6 additions & 0 deletions libs/openFrameworks/gl/ofShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class ofShader {
void setUniform3i(const std::string & name, int v1, int v2, int v3) const;
void setUniform4i(const std::string & name, int v1, int v2, int v3, int v4) const;


// Dmtr testing
void setUniformBufferObject(const std::string & name, const void * data, GLsizeiptr dataSize);

void setUniform1f(const std::string & name, float v1) const;
void setUniform2f(const std::string & name, float v1, float v2) const;
void setUniform3f(const std::string & name, float v1, float v2, float v3) const;
Expand Down Expand Up @@ -278,6 +282,8 @@ class ofShader {
};

std::unordered_map<GLenum, Shader> shaders;

std::unordered_map<std::string, ofBufferObject> bufferObjectsCache;
std::unordered_map<std::string, GLint> uniformsCache;
mutable std::unordered_map<std::string, GLint> attributesBindingsCache;

Expand Down
2 changes: 1 addition & 1 deletion scripts/apothecary
Submodule apothecary updated 254 files
Loading