libgui/include/video/shaders/ColorShader.h

93 lines
3.1 KiB
C
Raw Normal View History

2017-10-29 10:28:14 +01:00
/****************************************************************************
* Copyright (C) 2015 Dimok
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef __COLOR_SHADER_H_
#define __COLOR_SHADER_H_
2018-06-21 20:44:58 +02:00
#include <video/shaders/VertexShader.h>
#include <video/shaders/PixelShader.h>
#include <video/shaders/FetchShader.h>
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
class ColorShader : public Shader {
2017-10-29 10:28:14 +01:00
private:
ColorShader();
virtual ~ColorShader();
2018-06-21 20:44:58 +02:00
static const uint32_t cuAttributeCount = 2;
static const uint32_t cuPositionVtxsSize = 4 * cuVertexAttrSize;
2017-10-29 10:28:14 +01:00
static ColorShader *shaderInstance;
FetchShader *fetchShader;
VertexShader vertexShader;
PixelShader pixelShader;
2018-06-21 20:44:58 +02:00
float *positionVtxs;
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
uint32_t angleLocation;
uint32_t offsetLocation;
uint32_t scaleLocation;
uint32_t colorLocation;
uint32_t colorIntensityLocation;
uint32_t positionLocation;
2017-10-29 10:28:14 +01:00
public:
2018-06-21 20:44:58 +02:00
static const uint32_t cuColorVtxsSize = 4 * cuColorAttrSize;
2017-10-29 10:28:14 +01:00
static ColorShader *instance() {
if(!shaderInstance) {
shaderInstance = new ColorShader();
}
return shaderInstance;
}
static void destroyInstance() {
if(shaderInstance) {
delete shaderInstance;
shaderInstance = NULL;
}
}
2018-06-21 20:44:58 +02:00
void setShaders(void) const {
2017-10-29 10:28:14 +01:00
fetchShader->setShader();
vertexShader.setShader();
pixelShader.setShader();
}
2018-06-21 20:44:58 +02:00
void setAttributeBuffer(const uint8_t * colorAttr, const float * posVtxs_in = NULL, const uint32_t & vtxCount = 0) const {
2017-10-29 10:28:14 +01:00
if(posVtxs_in && vtxCount) {
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
VertexShader::setAttributeBuffer(1, vtxCount * cuColorAttrSize, cuColorAttrSize, colorAttr);
2018-06-21 20:44:58 +02:00
} else {
2017-10-29 10:28:14 +01:00
VertexShader::setAttributeBuffer(0, cuPositionVtxsSize, cuVertexAttrSize, positionVtxs);
VertexShader::setAttributeBuffer(1, cuColorVtxsSize, cuColorAttrSize, colorAttr);
}
}
2018-06-21 20:44:58 +02:00
void setAngle(const float & val) {
2017-10-29 10:28:14 +01:00
VertexShader::setUniformReg(angleLocation, 4, &val);
}
2018-06-21 20:44:58 +02:00
void setOffset(const glm::vec3 & vec) {
2017-10-29 10:28:14 +01:00
VertexShader::setUniformReg(offsetLocation, 4, &vec[0]);
}
2018-06-21 20:44:58 +02:00
void setScale(const glm::vec3 & vec) {
2017-10-29 10:28:14 +01:00
VertexShader::setUniformReg(scaleLocation, 4, &vec[0]);
}
2018-06-21 20:44:58 +02:00
void setColorIntensity(const glm::vec4 & vec) {
2017-10-29 10:28:14 +01:00
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
}
};
#endif // __COLOR_SHADER_H_