Dawn/src/dawn/display/shader/_Shader.hpp
2022-10-20 07:49:42 -07:00

97 lines
2.8 KiB
C++

// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
class Material;
enum ShaderParameterType {
SHADER_PARAMETER_TYPE_MATRIX,
SHADER_PARAMETER_TYPE_BOOLEAN,
SHADER_PARAMETER_TYPE_COLOR,
SHADER_PARAMETER_TYPE_VECTOR3
};
template<typename T>
class IShader {
public:
/**
* Attaches the supplied shader as the current shader.
*/
virtual void bind() = 0;
/**
* Requested by the Material to set the default parameters of the shader.
* Each parameter really should have a default value set so that there is
* no nullptr's or other issues.
*
* @param material Material to set the default parameters on to.
*/
virtual void setDefaultParameters(Material &material) = 0;
/**
* Requested by the render pipeline (typically) to set global level (once
* per frame) parameters.
*
* @param projection Projection matrix of the current viewport.
* @param view View matrix of the current viewport.
*/
virtual void setGlobalParameters(
glm::mat4 projection,
glm::mat4 view
) = 0;
/**
* Requested by the render pipeline (typically) to set mesh-level params.
* This may be performed multiple times per frame.
*
* @param position Matrix of the position of the mesh.
*/
virtual void setMeshParameters(glm::mat4 position) = 0;
/**
* Retreives the list of all parameters that the shader supports. This
* should not include the GLOBAL shader parameters (listed above) since
* those will be modified by the engine directly.
*
* @return Key-Value-Pair of Shader parameters and their type.
*/
virtual std::map<T, enum ShaderParameterType> getParameters() = 0;
/**
* Set's a specific shader parameter to a matrix.
*
* @param parameter parameter on the shader to set.
* @param matrix Matrix to apply.
*/
virtual void setMatrix(T parameter, glm::mat4 matrix) = 0;
/**
* Attaches a boolean to a shader.
*
* @param parameter parameter to set.
* @param value Value to set.
*/
virtual void setBoolean(T parameter, bool_t value) = 0;
/**
* Set a color on to the shader.
*
* @param parameter parameter to set the color to.
* @param color Color to set.
*/
virtual void setColor(T parameter, struct Color color) = 0;
/**
* Set a 3D vector on to the shader.
*
* @param parameter parameter to set the vector to.
* @param vector Vector to set.
*/
virtual void setVector3(T parameter, glm::vec3 vector) = 0;
};
}