85 lines
2.7 KiB
C++
85 lines
2.7 KiB
C++
// Copyright (c) 2022 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "display/shader/_Shader.hpp"
|
|
#include "dawnopengl.hpp"
|
|
#include "display/Color.hpp"
|
|
|
|
typedef GLuint shaderparameter_t;
|
|
|
|
namespace Dawn {
|
|
class Shader : public IShader<shaderparameter_t> {
|
|
private:
|
|
/** Pointer to an uploaded vertex shader program */
|
|
GLuint shaderVertex = -1;
|
|
|
|
/** Pointer to an uploaded fragment shader program */
|
|
GLuint shaderFrag = -1;
|
|
|
|
/** Pointer to an uploaded shader program linked */
|
|
GLuint shaderProgram = -1;
|
|
|
|
protected:
|
|
/**
|
|
* Compiles a GLSL shader and stores it on the GPU, updates the underlying
|
|
* pointers for you.
|
|
*
|
|
* @param vertexShader The string source of the vertex shader.
|
|
* @param fragmentShader The string source of the fragment shader.
|
|
*/
|
|
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,
|
|
Texture *texture
|
|
) = 0;
|
|
|
|
|
|
public:
|
|
/**
|
|
* Locate a shader parameter by its name.
|
|
*
|
|
* @param name Name of the parameter to get.
|
|
* @return The shader parameter.
|
|
*/
|
|
shaderparameter_t getParameterByName(std::string name);
|
|
|
|
/**
|
|
* Method to request that this shader be compiled and put on the GPU. This
|
|
* method should call the protected compileShader method.
|
|
*/
|
|
virtual void compile() = 0;
|
|
|
|
void bind() override;
|
|
void setMatrix(shaderparameter_t parameter, glm::mat4 matrix) override;
|
|
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, Texture *texture) override;
|
|
|
|
/**
|
|
* Destroys and deletes the shader from the GPU.
|
|
*/
|
|
virtual ~Shader();
|
|
};
|
|
} |