Added convenience function to add texture to shader
This commit is contained in:
parent
f1f076acf4
commit
1c008b1c9d
3 changed files with 42 additions and 5 deletions
|
@ -86,12 +86,9 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
oglu::ClearScreen(GL_COLOR_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
oglu::ClearScreen(GL_COLOR_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
||||||
|
|
||||||
crate->BindAs(0);
|
|
||||||
opengl->BindAs(1);
|
|
||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetUniform("texture1", 0);
|
shader->SetUniform("texture1", crate, 0);
|
||||||
shader->SetUniform("texture2", 1);
|
shader->SetUniform("texture2", opengl, 1);
|
||||||
|
|
||||||
square->BindAndDraw();
|
square->BindAndDraw();
|
||||||
|
|
||||||
|
|
|
@ -281,6 +281,34 @@ namespace oglu
|
||||||
*/
|
*/
|
||||||
void SetUniform(GLint location, const Color& v0, bool ignoreAlpha = false);
|
void SetUniform(GLint location, const Color& v0, bool ignoreAlpha = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set uniform sampler2D.
|
||||||
|
*
|
||||||
|
* Activates and binds the given texture, then sets the uniform.
|
||||||
|
* Note: In many cases, using AbstractTexture::BindAs(GLbyte index) to activate and bind the textures
|
||||||
|
* seperately and then using SetUniform(GLint location, GLint v0) to set the uniform might
|
||||||
|
* be more efficient.
|
||||||
|
*
|
||||||
|
* @param[in] name Name of the uniform
|
||||||
|
* @param[in] v0 Value to set the uniform to
|
||||||
|
* @param[in] index Index of the texture unit
|
||||||
|
*/
|
||||||
|
void SetUniform(const GLchar* name, const Texture& v0, GLbyte index = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set uniform color.
|
||||||
|
*
|
||||||
|
* Activates and binds the given texture, then sets the uniform
|
||||||
|
* Note: In many cases, using AbstractTexture::BindAs(GLbyte index) to activate and bind the textures
|
||||||
|
* seperately and then using SetUniform(const GLchar* name, GLint v0) to set the uniform might
|
||||||
|
* be more efficient.
|
||||||
|
*
|
||||||
|
* @param[in] location Location of the uniform
|
||||||
|
* @param[in] v0 Value to set the uniform to
|
||||||
|
* @param[in] ignoreAlpha Index of the texture unit
|
||||||
|
*/
|
||||||
|
void SetUniform(GLint location, const Texture& v0, GLbyte index = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set array of uniform float.
|
* @brief Set array of uniform float.
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <color.hpp>
|
#include <color.hpp>
|
||||||
|
#include <texture.hpp>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
|
@ -235,6 +236,17 @@ namespace oglu
|
||||||
glUniform4f(location, v0.r, v0.g, v0.b, v0.a);
|
glUniform4f(location, v0.r, v0.g, v0.b, v0.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractShader::SetUniform(const GLchar* name, const Texture& v0, GLbyte index)
|
||||||
|
{
|
||||||
|
SetUniform(glGetUniformLocation(program, name), v0, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractShader::SetUniform(GLint location, const Texture& v0, GLbyte index)
|
||||||
|
{
|
||||||
|
v0->BindAs(index);
|
||||||
|
glUniform1i(location, index);
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value)
|
void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value)
|
||||||
{
|
{
|
||||||
glUniform1fv(glGetUniformLocation(program, name), count, value);
|
glUniform1fv(glGetUniformLocation(program, name), count, value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue