@@ -58,7 +58,7 @@ class UniformColoredTextureRectShader : public TextureShader<UniformColoredTextu
5858}; // UniformColoredTextureRectShader
5959
6060// ============================================================================
61- class TextureRectShader : public TextureShader <TextureRectShader, 1 ,
61+ class TextureRectShader : public TextureShader <TextureRectShader, 1 ,
6262 core::vector2df, core::vector2df,
6363 core::vector2df, core::vector2df,
6464 float >
@@ -74,6 +74,24 @@ class TextureRectShader : public TextureShader<TextureRectShader, 1,
7474 } // TextureRectShader
7575}; // TextureRectShader
7676
77+ // ============================================================================
78+ class TextureRectCustomAlphaShader : public TextureShader <TextureRectCustomAlphaShader, 1 ,
79+ core::vector2df, core::vector2df,
80+ core::vector2df, core::vector2df,
81+ float , float >
82+ {
83+ public:
84+ TextureRectCustomAlphaShader ()
85+ {
86+ loadProgram (OBJECT, GL_VERTEX_SHADER, " texturedquad.vert" ,
87+ GL_FRAGMENT_SHADER, " texturedquad_custom_alpha.frag" );
88+ assignUniforms (" center" , " size" , " texcenter" , " texsize" , " rotation" ,
89+ " custom_alpha" );
90+
91+ assignSamplerNames (0 , " tex" , ST_BILINEAR_CLAMPED_FILTERED);
92+ } // TextureRectCustomAlphaShader
93+ }; // TextureRectCustomAlphaShader
94+
7795// ============================================================================
7896class ColoredRectShader : public Shader <ColoredRectShader, core::vector2df,
7997 core::vector2df, video::SColor>
@@ -521,6 +539,61 @@ void draw2DImage(const video::ITexture* texture,
521539 glGetError ();
522540} // draw2DImage
523541
542+ // ----------------------------------------------------------------------------
543+ void draw2DImageCustomAlpha (const irr::video::ITexture* texture,
544+ const irr::core::rect<irr::s32>& destRect,
545+ const irr::core::rect<irr::s32>& sourceRect,
546+ const irr::core::rect<irr::s32>* clipRect,
547+ float rotation, float custom_alpha)
548+ {
549+ if (!CVS->isGLSL ())
550+ return ;
551+
552+ float width, height, center_pos_x, center_pos_y, tex_width, tex_height;
553+ float tex_center_pos_x, tex_center_pos_y;
554+
555+ getSize (texture->getSize ().Width , texture->getSize ().Height ,
556+ texture->isRenderTarget (), destRect, sourceRect, width, height,
557+ center_pos_x, center_pos_y, tex_width, tex_height,
558+ tex_center_pos_x, tex_center_pos_y);
559+
560+ glEnable (GL_BLEND);
561+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
562+ if (clipRect)
563+ {
564+ if (!clipRect->isValid ())
565+ return ;
566+
567+ glEnable (GL_SCISSOR_TEST);
568+ const core::dimension2d<u32 >& render_target_size =
569+ irr_driver->getActualScreenSize ();
570+ glScissor (clipRect->UpperLeftCorner .X ,
571+ (s32)render_target_size.Height - clipRect->LowerRightCorner .Y +
572+ irr_driver->getDevice ()->getMovedHeight (),
573+ clipRect->getWidth (), clipRect->getHeight ());
574+ }
575+
576+ TextureRectCustomAlphaShader::getInstance ()->use ();
577+ glBindVertexArray (SharedGPUObjects::getUI_VAO ());
578+
579+ TextureRectCustomAlphaShader::getInstance ()->setTextureUnits (texture->getOpenGLTextureName ());
580+ TextureRectCustomAlphaShader::getInstance ()->setUniforms (
581+ core::vector2df (center_pos_x, center_pos_y),
582+ core::vector2df (width, height),
583+ core::vector2df (tex_center_pos_x, tex_center_pos_y),
584+ core::vector2df (tex_width, tex_height), rotation, custom_alpha);
585+
586+ glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
587+ glBindVertexArray (0 );
588+ glBindBuffer (GL_ARRAY_BUFFER, 0 );
589+
590+ if (clipRect)
591+ glDisable (GL_SCISSOR_TEST);
592+ glUseProgram (0 );
593+
594+ glGetError ();
595+ } // draw2DImage
596+
524597// ----------------------------------------------------------------------------
525598void draw2DImage (const video::ITexture* texture,
526599 const core::rect<float >& destRect,
0 commit comments