libgui/include/video/shaders/FXAAShader.h

83 lines
2.6 KiB
C
Raw Permalink 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 __FXAA_SHADER_H_
#define __FXAA_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 FXAAShader : public Shader {
2017-10-29 10:28:14 +01:00
public:
static FXAAShader *instance() {
if(!shaderInstance) {
shaderInstance = new FXAAShader();
}
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 {
2017-10-29 10:28:14 +01:00
VertexShader::setAttributeBuffer(0, ciPositionVtxsSize, cuVertexAttrSize, posVtxs);
VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords);
}
2018-06-21 20:44:58 +02:00
void setResolution(const glm::vec2 & vec) {
2017-10-29 10:28:14 +01:00
PixelShader::setUniformReg(resolutionLocation, 4, &vec[0]);
}
void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const {
2018-06-21 20:44:58 +02:00
GX2SetPixelTexture((GX2Texture*)texture, samplerLocation);
GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation);
2017-10-29 10:28:14 +01:00
}
private:
FXAAShader();
virtual ~FXAAShader();
2018-06-21 20:44:58 +02:00
static const uint32_t cuAttributeCount = 2;
static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize;
static const uint32_t ciTexCoordsVtxsSize = 4 * cuTexCoordAttrSize;
2017-10-29 10:28:14 +01:00
static FXAAShader *shaderInstance;
FetchShader *fetchShader;
VertexShader vertexShader;
PixelShader pixelShader;
2018-06-21 20:44:58 +02:00
float *posVtxs;
float *texCoords;
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
uint32_t samplerLocation;
uint32_t positionLocation;
uint32_t texCoordLocation;
uint32_t resolutionLocation;
2017-10-29 10:28:14 +01:00
};
#endif // __FXAA_SHADER_H_