libgui/include/video/shaders/ShaderFractalColor.h

112 lines
4.2 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 SHADER_FRACTAL_COLOR_H_
#define SHADER_FRACTAL_COLOR_H_
2018-06-21 20:44:58 +02:00
#include <video/shaders/VertexShader.h>
#include <video/shaders/PixelShader.h>
#include <video/shaders/FetchShader.h>
class ShaderFractalColor : public Shader {
2017-10-29 10:28:14 +01:00
private:
ShaderFractalColor();
virtual ~ShaderFractalColor();
static ShaderFractalColor * shaderInstance;
static const unsigned char cuAttributeCount = 3;
2018-06-21 20:44:58 +02:00
static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize;
static const uint32_t ciTexCoordsVtxsSize = 4 * cuTexCoordAttrSize;
static const uint32_t ciColorVtxsSize = 4 * cuColorAttrSize;
2017-10-29 10:28:14 +01:00
FetchShader *fetchShader;
VertexShader vertexShader;
PixelShader pixelShader;
2018-06-21 20:44:58 +02:00
float *posVtxs;
float *texCoords;
uint8_t *colorVtxs;
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
uint32_t modelMatrixLocation;
uint32_t viewMatrixLocation;
uint32_t projectionMatrixLocation;
uint32_t positionLocation;
uint32_t colorLocation;
uint32_t texCoordLocation;
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
uint32_t blurLocation;
uint32_t colorIntensityLocation;
uint32_t fadeOutLocation;
uint32_t fractalLocation;
2017-10-29 10:28:14 +01:00
public:
static ShaderFractalColor *instance() {
if(!shaderInstance) {
shaderInstance = new ShaderFractalColor();
}
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 uint32_t & vtxCount = 0, const float * posVtxs_in = NULL, const float * texCoords_in = NULL, const uint8_t * colorVtxs_in = NULL) const {
if(posVtxs_in && texCoords_in && vtxCount) {
2017-10-29 10:28:14 +01:00
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in);
VertexShader::setAttributeBuffer(2, vtxCount * cuColorAttrSize, cuColorAttrSize, colorVtxs_in);
2018-06-21 20:44:58 +02:00
} else {
2017-10-29 10:28:14 +01:00
//! use default quad vertex and texture coordinates if nothing is passed
VertexShader::setAttributeBuffer(0, ciPositionVtxsSize, cuVertexAttrSize, posVtxs);
VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords);
VertexShader::setAttributeBuffer(2, ciColorVtxsSize, cuColorAttrSize, colorVtxs);
}
}
2018-06-21 20:44:58 +02:00
void setProjectionMtx(const glm::mat4 & mtx) {
2017-10-29 10:28:14 +01:00
VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]);
}
2018-06-21 20:44:58 +02:00
void setViewMtx(const glm::mat4 & mtx) {
2017-10-29 10:28:14 +01:00
VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]);
}
2018-06-21 20:44:58 +02:00
void setModelViewMtx(const glm::mat4 & mtx) {
2017-10-29 10:28:14 +01:00
VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]);
}
2018-06-21 20:44:58 +02:00
void setBlurBorder(const float & blurBorderSize) {
2017-10-29 10:28:14 +01:00
PixelShader::setUniformReg(blurLocation, 4, &blurBorderSize);
}
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]);
}
2018-06-21 20:44:58 +02:00
void setAlphaFadeOut(const glm::vec4 & vec) {
2017-10-29 10:28:14 +01:00
PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]);
}
2018-06-21 20:44:58 +02:00
void setFractalColor(const int & fractalColorEnable) {
2017-10-29 10:28:14 +01:00
PixelShader::setUniformReg(fractalLocation, 4, &fractalColorEnable);
}
};
#endif // SHADER_FRACTAL_COLOR_H_