Testing textures and events
This commit is contained in:
@ -61,6 +61,10 @@ void Shader::compileShader(
|
||||
// Now parse out the variables.
|
||||
}
|
||||
|
||||
void Shader::setTextureSlot(shaderparameter_t param, textureslot_t slot) {
|
||||
glUniform1i(param, slot);
|
||||
}
|
||||
|
||||
shaderparameter_t Shader::getParameterByName(std::string name) {
|
||||
return glGetUniformLocation(this->shaderProgram, name.c_str());
|
||||
}
|
||||
@ -81,6 +85,13 @@ void Shader::setVector3(shaderparameter_t uniform, glm::vec3 vector) {
|
||||
glUniform3f(uniform, vector.x, vector.y, vector.z);
|
||||
}
|
||||
|
||||
void Shader::setTexture(
|
||||
shaderparameter_t param,
|
||||
std::shared_ptr<Texture> texture
|
||||
) {
|
||||
this->bindTexture(param, texture);
|
||||
}
|
||||
|
||||
void Shader::bind() {
|
||||
if(this->shaderProgram == -1) throw "Shader has not yet been compiled";
|
||||
glUseProgram(this->shaderProgram);
|
||||
|
@ -32,6 +32,29 @@ namespace Dawn {
|
||||
*/
|
||||
void compileShader(std::string vertexShader, std::string fragmentShader);
|
||||
|
||||
/**
|
||||
* Bind a specific texture slot (of an already bound texture) to a shader
|
||||
* parameter.
|
||||
*
|
||||
* @param param Parameter to bind the texture slot for.
|
||||
* @param slot Slot to bind.
|
||||
*/
|
||||
void setTextureSlot(shaderparameter_t param, textureslot_t slot);
|
||||
|
||||
/**
|
||||
* Method designed to be overwritten by child shaders on how to handle a
|
||||
* bind texture request. This is left to the discretion of the child
|
||||
* shader for which slot(s) to use, how to handle nullptr textures, etc.
|
||||
*
|
||||
* @param param Parameter to bind the requested texture to.
|
||||
* @param texture Texture trying to be bound, may be nullptr.
|
||||
*/
|
||||
virtual void bindTexture(
|
||||
shaderparameter_t param,
|
||||
std::shared_ptr<Texture> texture
|
||||
) = 0;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Locate a shader parameter by its name.
|
||||
@ -52,6 +75,10 @@ namespace Dawn {
|
||||
void setBoolean(shaderparameter_t parameter, bool_t value) override;
|
||||
void setColor(shaderparameter_t parameter, struct Color color) override;
|
||||
void setVector3(shaderparameter_t parameter, glm::vec3 vector) override;
|
||||
void setTexture(
|
||||
shaderparameter_t parameter,
|
||||
std::shared_ptr<Texture> texture
|
||||
) override;
|
||||
|
||||
/**
|
||||
* Destroys and deletes the shader from the GPU.
|
||||
|
@ -24,7 +24,7 @@ namespace Dawn {
|
||||
|
||||
ps[this->paramColor] = SHADER_PARAMETER_TYPE_COLOR;
|
||||
ps[this->paramHasTexture] = SHADER_PARAMETER_TYPE_BOOLEAN;
|
||||
// ps[paramTexture] SHADER_PARAMETER_TYPE_TEXTURE;
|
||||
ps[this->paramTexture] = SHADER_PARAMETER_TYPE_TEXTURE;
|
||||
|
||||
return ps;
|
||||
}
|
||||
@ -42,6 +42,19 @@ namespace Dawn {
|
||||
this->setMatrix(this->paramModel, transform);
|
||||
}
|
||||
|
||||
void bindTexture(
|
||||
shaderparameter_t param,
|
||||
std::shared_ptr<Texture> texture
|
||||
) override {
|
||||
if(texture == nullptr) {
|
||||
this->setBoolean(this->paramHasTexture, false);
|
||||
} else {
|
||||
this->setBoolean(this->paramHasTexture, true);
|
||||
this->setTextureSlot(param, 0x00);
|
||||
texture->bind(0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void compile() override {
|
||||
this->compileShader(
|
||||
// Vertex Shader
|
||||
|
Reference in New Issue
Block a user