// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "display/shader/IShader.hpp" #include "dawnopengl.hpp" typedef GLuint shaderparameter_t; namespace Dawn { class Shader : public IShader { 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/HLSL 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::map attributeLocations, const std::string vertexShader, const std::string fragmentShader ); /** * Typically HLSL only, this method allows you to specify where vbo * attributes are bound. Typically 0 for positions, 1 for coordinates, * etc. * * @param name Attribute name in the HLSL shader. * @param location Index pointing to which location it is to be bound to. */ void bindAttributeLocation( const std::string name, const int32_t location ); public: /** * Locate a shader parameter by its name. * * @param name Name of the parameter to get. * @return The shader parameter. */ shaderparameter_t getParameterByName(const std::string name); /** * Locate a shader buffer parameter set by its name. * * @param name Name of the buffer to get. * @return The shader buffer. */ shaderbufferlocation_t getBufferLocationByName(const std::string name); virtual void compile() override = 0; void bind() override; void setParameterBuffer( const shaderbufferlocation_t location, const shaderbufferslot_t slot ); void setMatrix( const shaderparameter_t parameter, const glm::mat4 matrix ) override; void setBoolean( const shaderparameter_t parameter, const bool_t value ) override; void setColor( const shaderparameter_t parameter, const struct Color color ) override; void setVector3( const shaderparameter_t parameter, const glm::vec3 vector ) override; void setTexture( const shaderparameter_t parameter, const textureslot_t texture ) override; void setFloat( const shaderparameter_t parameter, const float_t value ) override; /** * Destroys and deletes the shader from the GPU. */ ~Shader(); }; }