summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-06-11 13:05:49 +0300
committerAndrei Karas <akaras@inbox.ru>2014-06-11 13:05:49 +0300
commit41836760fa59abc74098aed7450b4858dc288e56 (patch)
tree865e87f4adae8301f8d09c7f4f89ac1671054477
parente8a8db1e71d90eda2f76b6c34afc8c1ec5cd2b8b (diff)
downloadmv-41836760fa59abc74098aed7450b4858dc288e56.tar.gz
mv-41836760fa59abc74098aed7450b4858dc288e56.tar.bz2
mv-41836760fa59abc74098aed7450b4858dc288e56.tar.xz
mv-41836760fa59abc74098aed7450b4858dc288e56.zip
In modernopengl add alpha for textures.
-rw-r--r--data/graphics/shaders/texture_frag.glsl3
-rw-r--r--src/render/modernopenglgraphics.cpp22
-rw-r--r--src/render/modernopenglgraphics.h1
-rw-r--r--src/test/testlauncher.cpp2
4 files changed, 15 insertions, 13 deletions
diff --git a/data/graphics/shaders/texture_frag.glsl b/data/graphics/shaders/texture_frag.glsl
index 7eac7771e..db6c7176f 100644
--- a/data/graphics/shaders/texture_frag.glsl
+++ b/data/graphics/shaders/texture_frag.glsl
@@ -2,7 +2,8 @@
in vec2 Texcoord;
out vec4 outColor;
uniform sampler2D tex;
+uniform float color;
void main()
{
- outColor = texture(tex, Texcoord);
+ outColor = texture(tex, Texcoord) * vec4(1.0, 1.0, 1.0, color);
}
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index 3241821ba..a1c2d2bb6 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -100,6 +100,7 @@ ModernOpenGLGraphics::ModernOpenGLGraphics() :
mSimpleColorUniform(0U),
mSimplePosAttrib(0),
mTexturePosAttrib(0),
+ mTextureColorUniform(0U),
mSimpleScreenUniform(0U),
mTextureScreenUniform(0U),
mVao(0U),
@@ -168,6 +169,8 @@ void ModernOpenGLGraphics::postInit()
mglVertexAttribFormat(mSimplePosAttrib, 2, GL_FLOAT, GL_FALSE, 0);
mTexturePosAttrib = mglGetAttribLocation(mTextureProgramId, "position");
+ mTextureColorUniform = mglGetUniformLocation(mTextureProgramId, "color");
+ mglUniform1f(mTextureColorUniform, 1.0f);
mTextureScreenUniform = mglGetUniformLocation(mTextureProgramId, "screen");
mglVertexAttribFormat(mTexturePosAttrib, 4, GL_FLOAT, GL_FALSE, 0);
@@ -247,15 +250,11 @@ void ModernOpenGLGraphics::setColorAll(const Color &color,
void ModernOpenGLGraphics::setColorAlpha(const float alpha)
{
- // here need set alpha uniform for textures only
-/*
- if (!mIsByteColor && mFloatColor == alpha)
- return;
-
- glColor4f(1.0F, 1.0F, 1.0F, alpha);
- mIsByteColor = false;
- mFloatColor = alpha;
-*/
+ if (mAlphaCached != alpha)
+ {
+ mAlphaCached = alpha;
+ mglUniform1f(mTextureColorUniform, alpha);
+ }
}
void ModernOpenGLGraphics::drawQuad(const Image *const image,
@@ -317,12 +316,12 @@ bool ModernOpenGLGraphics::drawImageInline(const Image *const image,
if (!image)
return false;
- setColorAlpha(image->mAlpha);
#ifdef DEBUG_BIND_TEXTURE
debugBindTexture(image);
#endif
bindTexture(GL_TEXTURE_2D, image->mGLImage);
setTexturingAndBlending(true);
+ setColorAlpha(image->mAlpha);
const ClipRect &clipArea = mClipStack.top();
const SDL_Rect &imageRect = image->mBounds;
@@ -385,14 +384,13 @@ void ModernOpenGLGraphics::drawPatternInline(const Image *const image,
const int x2 = x + clipArea.xOffset;
const int y2 = y + clipArea.yOffset;
- setColorAlpha(image->mAlpha);
-
#ifdef DEBUG_BIND_TEXTURE
debugBindTexture(image);
#endif
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
setTexturingAndBlending(true);
+ setColorAlpha(image->mAlpha);
unsigned int vp = 0;
const unsigned int vLimit = mMaxVertices * 4;
diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h
index 5519fd282..d9c043fc0 100644
--- a/src/render/modernopenglgraphics.h
+++ b/src/render/modernopenglgraphics.h
@@ -98,6 +98,7 @@ class ModernOpenGLGraphics final : public Graphics
GLuint mSimpleColorUniform;
GLint mSimplePosAttrib;
GLint mTexturePosAttrib;
+ GLint mTextureColorUniform;
GLuint mSimpleScreenUniform;
GLuint mTextureScreenUniform;
GLuint mVao;
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index da09813d8..623fae805 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -380,7 +380,9 @@ int TestLauncher::testDraw()
mainGraphics->drawRectangle(Rect(0, 0, 400, 200));
mainGraphics->setColor(Color(0xFFU, 0x00U, 0x00U, 0xB0U));
+ img[0]->setAlpha(0.5f);
mainGraphics->drawImage(img[0], 190, 383);
+ img[0]->setAlpha(1.0f);
mainGraphics->setColor(Color(0x80U, 0x00U, 0xA0U, 0x90U));
mainGraphics->fillRectangle(Rect(200, 100, 300, 300));