Shader: Group all shaders in one collective struct
Makes sharedstate.{cpp|h} a lot easier to read, and adding new shaders a one liner.
This commit is contained in:
parent
8c6648f47e
commit
0035c23641
|
@ -162,7 +162,7 @@ struct BitmapPrivate
|
||||||
if (pointArray.count() == 0)
|
if (pointArray.count() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SimpleColorShader &shader = shState->simpleColorShader();
|
SimpleColorShader &shader = shState->shaders().simpleColor;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.setTranslation(Vec2i());
|
shader.setTranslation(Vec2i());
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
||||||
((float) source.width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
((float) source.width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
||||||
((float) source.height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
((float) source.height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
||||||
|
|
||||||
BltShader &shader = shState->bltShader();
|
BltShader &shader = shState->shaders().blt;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.setDestination(gpTex.tex);
|
shader.setDestination(gpTex.tex);
|
||||||
shader.setSubRect(bltSubRect);
|
shader.setSubRect(bltSubRect);
|
||||||
|
@ -465,7 +465,7 @@ void Bitmap::gradientFillRect(const IntRect &rect,
|
||||||
|
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
SimpleColorShader &shader = shState->simpleColorShader();
|
SimpleColorShader &shader = shState->shaders().simpleColor;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.setTranslation(Vec2i());
|
shader.setTranslation(Vec2i());
|
||||||
|
|
||||||
|
@ -530,7 +530,7 @@ void Bitmap::blur()
|
||||||
|
|
||||||
TEXFBO auxTex = shState->texPool().request(width(), height());
|
TEXFBO auxTex = shState->texPool().request(width(), height());
|
||||||
|
|
||||||
BlurShader &shader = shState->blurShader();
|
BlurShader &shader = shState->shaders().blur;
|
||||||
BlurShader::HPass &pass1 = shader.pass1;
|
BlurShader::HPass &pass1 = shader.pass1;
|
||||||
BlurShader::VPass &pass2 = shader.pass2;
|
BlurShader::VPass &pass2 = shader.pass2;
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ void Bitmap::radialBlur(int angle, int divisions)
|
||||||
|
|
||||||
glState.blendMode.pushSet(BlendAddition);
|
glState.blendMode.pushSet(BlendAddition);
|
||||||
|
|
||||||
SimpleMatrixShader &shader = shState->simpleMatrixShader();
|
SimpleMatrixShader &shader = shState->shaders().simpleMatrix;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
||||||
p->bindTexture(shader);
|
p->bindTexture(shader);
|
||||||
|
@ -740,7 +740,7 @@ void Bitmap::hueChange(int hue)
|
||||||
hue = wrapRange(hue, 0, 359);
|
hue = wrapRange(hue, 0, 359);
|
||||||
float hueAdj = -((M_PI * 2) / 360) * hue;
|
float hueAdj = -((M_PI * 2) / 360) * hue;
|
||||||
|
|
||||||
HueShader &shader = shState->hueShader();
|
HueShader &shader = shState->shaders().hue;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.setHueAdjust(hueAdj);
|
shader.setHueAdjust(hueAdj);
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align)
|
||||||
(float) gpTexSize.x / gpTex2.width,
|
(float) gpTexSize.x / gpTex2.width,
|
||||||
(float) gpTexSize.y / gpTex2.height);
|
(float) gpTexSize.y / gpTex2.height);
|
||||||
|
|
||||||
BltShader &shader = shState->bltShader();
|
BltShader &shader = shState->shaders().blt;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.setTexSize(gpTexSize);
|
shader.setTexSize(gpTexSize);
|
||||||
shader.setSource();
|
shader.setSource();
|
||||||
|
|
|
@ -154,7 +154,7 @@ public:
|
||||||
#ifdef RGSS2
|
#ifdef RGSS2
|
||||||
if (brightEffect)
|
if (brightEffect)
|
||||||
{
|
{
|
||||||
SimpleColorShader &shader = shState->simpleColorShader();
|
SimpleColorShader &shader = shState->shaders().simpleColor;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setTranslation(Vec2i());
|
shader.setTranslation(Vec2i());
|
||||||
|
@ -177,7 +177,7 @@ public:
|
||||||
pp.blitFBOs();
|
pp.blitFBOs();
|
||||||
glState.scissorTest.pop();
|
glState.scissorTest.pop();
|
||||||
|
|
||||||
PlaneShader &shader = shState->planeShader();
|
PlaneShader &shader = shState->shaders().plane;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.setColor(c);
|
shader.setColor(c);
|
||||||
shader.setFlash(f);
|
shader.setFlash(f);
|
||||||
|
@ -585,7 +585,7 @@ void Graphics::transition(int duration,
|
||||||
* we can use a simplified shader */
|
* we can use a simplified shader */
|
||||||
if (transMap)
|
if (transMap)
|
||||||
{
|
{
|
||||||
TransShader &shader = shState->transShader();
|
TransShader &shader = shState->shaders().trans;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setFrozenScene(p->frozenScene.tex);
|
shader.setFrozenScene(p->frozenScene.tex);
|
||||||
|
@ -596,7 +596,7 @@ void Graphics::transition(int duration,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SimpleTransShader &shader = shState->sTransShader();
|
SimpleTransShader &shader = shState->shaders().simpleTrans;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setFrozenScene(p->frozenScene.tex);
|
shader.setFrozenScene(p->frozenScene.tex);
|
||||||
|
@ -617,9 +617,9 @@ void Graphics::transition(int duration,
|
||||||
const float prog = i * (1.0 / duration);
|
const float prog = i * (1.0 / duration);
|
||||||
|
|
||||||
if (transMap)
|
if (transMap)
|
||||||
shState->transShader().setProg(prog);
|
shState->shaders().trans.setProg(prog);
|
||||||
else
|
else
|
||||||
shState->sTransShader().setProg(prog);
|
shState->shaders().simpleTrans.setProg(prog);
|
||||||
|
|
||||||
/* Draw the composed frame to a buffer first
|
/* Draw the composed frame to a buffer first
|
||||||
* (we need this because we're skipping PingPong) */
|
* (we need this because we're skipping PingPong) */
|
||||||
|
|
|
@ -204,7 +204,7 @@ void Plane::draw()
|
||||||
|
|
||||||
if (p->color->hasEffect() || p->tone->hasEffect() || p->opacity != 255)
|
if (p->color->hasEffect() || p->tone->hasEffect() || p->opacity != 255)
|
||||||
{
|
{
|
||||||
PlaneShader &shader = shState->planeShader();
|
PlaneShader &shader = shState->shaders().plane;
|
||||||
|
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
|
@ -217,7 +217,7 @@ void Plane::draw()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SimpleShader &shader = shState->simpleShader();
|
SimpleShader &shader = shState->shaders().simple;
|
||||||
|
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
|
|
21
src/shader.h
21
src/shader.h
|
@ -247,4 +247,25 @@ private:
|
||||||
GLint u_source, u_destination, u_subRect, u_opacity;
|
GLint u_source, u_destination, u_subRect, u_opacity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Global object containing all available shaders */
|
||||||
|
struct ShaderSet
|
||||||
|
{
|
||||||
|
SimpleShader simple;
|
||||||
|
SimpleColorShader simpleColor;
|
||||||
|
SimpleAlphaShader simpleAlpha;
|
||||||
|
SimpleSpriteShader simpleSprite;
|
||||||
|
SpriteShader sprite;
|
||||||
|
PlaneShader plane;
|
||||||
|
FlashMapShader flashMap;
|
||||||
|
TransShader trans;
|
||||||
|
SimpleTransShader simpleTrans;
|
||||||
|
HueShader hue;
|
||||||
|
BltShader blt;
|
||||||
|
|
||||||
|
#ifdef RGSS2
|
||||||
|
SimpleMatrixShader simpleMatrix;
|
||||||
|
BlurShader blur;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
#endif // SHADER_H
|
#endif // SHADER_H
|
||||||
|
|
|
@ -65,22 +65,7 @@ struct SharedStatePrivate
|
||||||
|
|
||||||
GLState _glState;
|
GLState _glState;
|
||||||
|
|
||||||
SimpleShader simpleShader;
|
ShaderSet shaders;
|
||||||
SimpleColorShader simpleColorShader;
|
|
||||||
SimpleAlphaShader simpleAlphaShader;
|
|
||||||
SimpleSpriteShader simpleSpriteShader;
|
|
||||||
SpriteShader spriteShader;
|
|
||||||
PlaneShader planeShader;
|
|
||||||
FlashMapShader flashMapShader;
|
|
||||||
TransShader transShader;
|
|
||||||
SimpleTransShader sTransShader;
|
|
||||||
HueShader hueShader;
|
|
||||||
BltShader bltShader;
|
|
||||||
|
|
||||||
#ifdef RGSS2
|
|
||||||
SimpleMatrixShader simpleMatrixShader;
|
|
||||||
BlurShader blurShader;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TexPool texPool;
|
TexPool texPool;
|
||||||
FontPool fontPool;
|
FontPool fontPool;
|
||||||
|
@ -192,26 +177,11 @@ GSATT(Graphics&, graphics)
|
||||||
GSATT(Input&, input)
|
GSATT(Input&, input)
|
||||||
GSATT(Audio&, audio)
|
GSATT(Audio&, audio)
|
||||||
GSATT(GLState&, _glState)
|
GSATT(GLState&, _glState)
|
||||||
GSATT(SimpleShader&, simpleShader)
|
GSATT(ShaderSet&, shaders)
|
||||||
GSATT(SimpleColorShader&, simpleColorShader)
|
|
||||||
GSATT(SimpleAlphaShader&, simpleAlphaShader)
|
|
||||||
GSATT(SimpleSpriteShader&, simpleSpriteShader)
|
|
||||||
GSATT(SpriteShader&, spriteShader)
|
|
||||||
GSATT(PlaneShader&, planeShader)
|
|
||||||
GSATT(FlashMapShader&, flashMapShader)
|
|
||||||
GSATT(TransShader&, transShader)
|
|
||||||
GSATT(SimpleTransShader&, sTransShader)
|
|
||||||
GSATT(HueShader&, hueShader)
|
|
||||||
GSATT(BltShader&, bltShader)
|
|
||||||
GSATT(TexPool&, texPool)
|
GSATT(TexPool&, texPool)
|
||||||
GSATT(FontPool&, fontPool)
|
GSATT(FontPool&, fontPool)
|
||||||
GSATT(Quad&, gpQuad)
|
GSATT(Quad&, gpQuad)
|
||||||
|
|
||||||
#ifdef RGSS2
|
|
||||||
GSATT(SimpleMatrixShader&, simpleMatrixShader)
|
|
||||||
GSATT(BlurShader&, blurShader)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SharedState::setBindingData(void *data)
|
void SharedState::setBindingData(void *data)
|
||||||
{
|
{
|
||||||
p->bindingData = data;
|
p->bindingData = data;
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct mrb_state;
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
struct TEXFBO;
|
struct TEXFBO;
|
||||||
struct Quad;
|
struct Quad;
|
||||||
|
struct ShaderSet;
|
||||||
|
|
||||||
class Scene;
|
class Scene;
|
||||||
class FileSystem;
|
class FileSystem;
|
||||||
|
@ -42,18 +43,6 @@ class Graphics;
|
||||||
class Input;
|
class Input;
|
||||||
class Audio;
|
class Audio;
|
||||||
class GLState;
|
class GLState;
|
||||||
class SimpleShader;
|
|
||||||
class SimpleColorShader;
|
|
||||||
class SimpleAlphaShader;
|
|
||||||
class SimpleSpriteShader;
|
|
||||||
class SimpleMatrixShader;
|
|
||||||
class SpriteShader;
|
|
||||||
class PlaneShader;
|
|
||||||
class FlashMapShader;
|
|
||||||
class TransShader;
|
|
||||||
class SimpleTransShader;
|
|
||||||
class HueShader;
|
|
||||||
class BltShader;
|
|
||||||
class TexPool;
|
class TexPool;
|
||||||
class FontPool;
|
class FontPool;
|
||||||
class Font;
|
class Font;
|
||||||
|
@ -84,22 +73,7 @@ struct SharedState
|
||||||
|
|
||||||
GLState &_glState();
|
GLState &_glState();
|
||||||
|
|
||||||
SimpleShader &simpleShader();
|
ShaderSet &shaders();
|
||||||
SimpleColorShader &simpleColorShader();
|
|
||||||
SimpleAlphaShader &simpleAlphaShader();
|
|
||||||
SimpleSpriteShader &simpleSpriteShader();
|
|
||||||
SpriteShader &spriteShader();
|
|
||||||
PlaneShader &planeShader();
|
|
||||||
FlashMapShader &flashMapShader();
|
|
||||||
TransShader &transShader();
|
|
||||||
SimpleTransShader &sTransShader();
|
|
||||||
HueShader &hueShader();
|
|
||||||
BltShader &bltShader();
|
|
||||||
|
|
||||||
#ifdef RGSS2
|
|
||||||
SimpleMatrixShader &simpleMatrixShader();
|
|
||||||
BlurShader &blurShader();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TexPool &texPool();
|
TexPool &texPool();
|
||||||
FontPool &fontPool();
|
FontPool &fontPool();
|
||||||
|
|
|
@ -378,7 +378,7 @@ void Sprite::draw()
|
||||||
|
|
||||||
if (renderEffect)
|
if (renderEffect)
|
||||||
{
|
{
|
||||||
SpriteShader &shader = shState->spriteShader();
|
SpriteShader &shader = shState->shaders().sprite;
|
||||||
|
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
|
@ -400,7 +400,7 @@ void Sprite::draw()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SimpleSpriteShader &shader = shState->simpleSpriteShader();
|
SimpleSpriteShader &shader = shState->shaders().simpleSprite;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
||||||
shader.setSpriteMat(p->trans.getMatrix());
|
shader.setSpriteMat(p->trans.getMatrix());
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ GroundLayer::GroundLayer(TilemapPrivate *p, Viewport *viewport)
|
||||||
|
|
||||||
void GroundLayer::draw()
|
void GroundLayer::draw()
|
||||||
{
|
{
|
||||||
SimpleShader &shader = shState->simpleShader();
|
SimpleShader &shader = shState->shaders().simple;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
|
|
||||||
|
@ -1142,7 +1142,7 @@ void GroundLayer::draw()
|
||||||
glState.blendMode.pushSet(BlendAddition);
|
glState.blendMode.pushSet(BlendAddition);
|
||||||
glState.texture2D.pushSet(false);
|
glState.texture2D.pushSet(false);
|
||||||
|
|
||||||
FlashMapShader &shader = shState->flashMapShader();
|
FlashMapShader &shader = shState->shaders().flashMap;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setAlpha(flashAlpha[p->flash.alphaIdx] / 255.f);
|
shader.setAlpha(flashAlpha[p->flash.alphaIdx] / 255.f);
|
||||||
|
@ -1199,7 +1199,7 @@ void ScanRow::draw()
|
||||||
if (batchedFlag)
|
if (batchedFlag)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SimpleShader &shader = shState->simpleShader();
|
SimpleShader &shader = shState->shaders().simple;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ struct WindowPrivate
|
||||||
glState.viewport.pushSet(IntRect(0, 0, baseTex.width, baseTex.height));
|
glState.viewport.pushSet(IntRect(0, 0, baseTex.width, baseTex.height));
|
||||||
glState.clearColor.pushSet(Vec4());
|
glState.clearColor.pushSet(Vec4());
|
||||||
|
|
||||||
SimpleAlphaShader &shader = shState->simpleAlphaShader();
|
SimpleAlphaShader &shader = shState->shaders().simpleAlpha;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setTranslation(Vec2i());
|
shader.setTranslation(Vec2i());
|
||||||
|
@ -560,7 +560,7 @@ struct WindowPrivate
|
||||||
Vec2i trans(position.x + sceneOffset.x,
|
Vec2i trans(position.x + sceneOffset.x,
|
||||||
position.y + sceneOffset.y);
|
position.y + sceneOffset.y);
|
||||||
|
|
||||||
SimpleAlphaShader &shader = shState->simpleAlphaShader();
|
SimpleAlphaShader &shader = shState->shaders().simpleAlpha;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setTranslation(trans);
|
shader.setTranslation(trans);
|
||||||
|
@ -609,7 +609,7 @@ struct WindowPrivate
|
||||||
glState.scissorBox.push();
|
glState.scissorBox.push();
|
||||||
glState.scissorBox.setIntersect(windowRect);
|
glState.scissorBox.setIntersect(windowRect);
|
||||||
|
|
||||||
SimpleAlphaShader &shader = shState->simpleAlphaShader();
|
SimpleAlphaShader &shader = shState->shaders().simpleAlpha;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setTranslation(Vec2i(effectX, effectY));
|
shader.setTranslation(Vec2i(effectX, effectY));
|
||||||
|
|
Loading…
Reference in New Issue