// CLASS HEADER
#include <dali/internal/render/gl-resources/bitmap-texture.h>
-// EXTERNAL INCLUDES
-#include <math.h>
-#include <memory.h>
-
// INTERNAL INCLUDES
-#include <dali/public-api/math/rect.h>
-#include <dali/public-api/math/math-utils.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/common/performance-monitor.h>
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
namespace Dali
{
CreateGlTexture();
}
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
GLenum pixelDataType = GL_UNSIGNED_BYTE;
Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
}
DALI_ASSERT_DEBUG( mId != 0 );
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
GLenum pixelDataType = GL_UNSIGNED_BYTE;
Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
size_t numPixels = blockSize*blockSize;
// CLASS HEADER
#include <dali/internal/render/gl-resources/compressed-bitmap-texture.h>
-// EXTERNAL INCLUDES
-#include <math.h>
-#include <memory.h>
-
// INTERNAL INCLUDES
-#include <dali/public-api/math/rect.h>
-#include <dali/public-api/math/math-utils.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/common/performance-monitor.h>
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
namespace Dali
{
}
DALI_ASSERT_DEBUG( mId != 0 );
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture(TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD )); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
GLenum pixelFormat = GL_RGBA;
// INTERNAL INCLUDES
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/integration-api/debug.h>
namespace Dali
DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
mContext.GenTextures(1, &mId);
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
// set texture parameters
// INTERNAL INCLUDES
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/integration-api/debug.h>
namespace Dali
if( mNativeImage->GlExtensionCreate() )
{
mContext.GenTextures(1, &mId);
- mContext.ActiveTexture(GL_TEXTURE7); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture(mId);
mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
// CLASS HEADER
#include <dali/internal/render/gl-resources/native-texture.h>
-// EXTERNAL INCLUDES
-#include <math.h>
-#include <memory.h>
-
// INTERNAL INCLUDES
-#include <dali/public-api/math/rect.h>
-#include <dali/public-api/math/math-utils.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/gl-resources/texture.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
namespace Dali
{
if( mNativeImage->GlExtensionCreate() )
{
mContext.GenTextures( 1, &mId );
- mContext.ActiveTexture( GL_TEXTURE7 ); // bind in unused unit so rebind works the first time
+ mContext.ActiveTexture( TextureUnitAsGLenum( TEXTURE_UNIT_UPLOAD ) ); // bind in unused unit so rebind works the first time
mContext.Bind2dTexture( mId );
mContext.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
--- /dev/null
+#ifndef __DALI_INTERNAL_TEXTURE_UNITS_H__
+#define __DALI_INTERNAL_TEXTURE_UNITS_H__
+
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/gl-defines.h>
+
+namespace Dali
+{
+namespace Internal
+{
+
+enum TextureUnit
+{
+ TEXTURE_UNIT_IMAGE = 0,
+ TEXTURE_UNIT_TEXT = 0, // for now use same texture unit as text to avoid too many ActiveTexture Calls
+ TEXTURE_UNIT_MATERIAL_DIFFUSE,
+ TEXTURE_UNIT_MATERIAL_OPACITY,
+ TEXTURE_UNIT_MATERIAL_NORMAL_MAP,
+ TEXTURE_UNIT_SHADER,
+ TEXTURE_UNIT_UPLOAD,
+};
+
+inline unsigned int TextureUnitAsGLenum( TextureUnit unit )
+{
+ // GL texture units are #defines in growing order to converting that to index
+ return GL_TEXTURE0 + static_cast<unsigned int>( unit );
+}
+
+}//Internal
+
+}//Dali
+
+#endif // __DALI_INTERNAL_TEXTURE_UNITS_H__
uniforms.SetUniforms( *this, program, shaderType );
}
-void RenderMaterial::BindTexture( Program& program, ResourceId id, Texture* texture, unsigned int textureUnit, Program::UniformType samplerIndex ) const
+void RenderMaterial::BindTexture( Program& program, ResourceId id, Texture* texture, TextureUnit textureUnit, Program::UniformType samplerIndex ) const
{
DALI_ASSERT_DEBUG( NULL != mTextureCache );
if( texture != NULL )
{
- mTextureCache->BindTexture( texture, id, GL_TEXTURE_2D, GL_TEXTURE0 + textureUnit );
+ mTextureCache->BindTexture( texture, id, GL_TEXTURE_2D, TextureUnitAsGLenum( textureUnit ) );
// Set sampler uniforms for textures
GLint samplerLoc = program.GetUniformLocation( samplerIndex );
- if( -1 != samplerLoc )
+ if( Program::UNIFORM_UNKNOWN != samplerLoc )
{
program.SetUniform1i( samplerLoc, textureUnit );
}
}
}
- BindTexture( program, mDiffuseTextureId, mDiffuseTexture, 0, Program::UNIFORM_SAMPLER );
+ BindTexture( program, mDiffuseTextureId, mDiffuseTexture, TEXTURE_UNIT_MATERIAL_DIFFUSE, Program::UNIFORM_SAMPLER );
if( mDiffuseTexture )
{
}
// GL_TEXTURE1 is used by shader effect texture
- BindTexture( program, mOpacityTextureId, mOpacityTexture, 2, Program::UNIFORM_SAMPLER_OPACITY );
+ BindTexture( program, mOpacityTextureId, mOpacityTexture, TEXTURE_UNIT_MATERIAL_OPACITY, Program::UNIFORM_SAMPLER_OPACITY );
if( mOpacityTexture )
{
mOpacityTexture->ApplySampler( textureSampler );
}
- BindTexture( program, mNormalMapTextureId, mNormalMapTexture, 3, Program::UNIFORM_SAMPLER_NORMAL_MAP );
+ BindTexture( program, mNormalMapTextureId, mNormalMapTexture, TEXTURE_UNIT_MATERIAL_NORMAL_MAP, Program::UNIFORM_SAMPLER_NORMAL_MAP );
if( mNormalMapTexture )
{
#include <dali/internal/event/effects/shader-declarations.h>
#include <dali/internal/render/shaders/custom-uniform.h>
#include <dali/internal/render/gl-resources/texture-observer.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/internal/render/shaders/program.h>
namespace Dali
* @param[in] textureUnit Texture unit ( should be a value between 0 and the max number of samplers - 1 )
* @param[in] samplerIndex The index of the uniform to bind the texture sampler
*/
- void BindTexture( Program& program, unsigned int textureId, Texture* texture, unsigned int textureUnit, Program::UniformType samplerIndex ) const;
+ void BindTexture( Program& program, unsigned int textureId, Texture* texture, TextureUnit textureUnit, Program::UniformType samplerIndex ) const;
private:
TextureCache* mTextureCache; ///< Texture cache of GL resources
#include <dali/internal/render/gl-resources/gpu-buffer.h>
#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/internal/render/renderers/scene-graph-renderer-debug.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/shaders/shader.h>
DALI_ASSERT_DEBUG( mVertexBuffer );
- mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, GL_TEXTURE0 );
+ mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TextureUnitAsGLenum( TEXTURE_UNIT_IMAGE ) );
if( mTexture->GetTextureId() == 0 )
{
mTexture->ApplySampler( mSamplerBitfield );
- // make sure the vertex is bound, this has to be done before
- // we call VertexAttribPointer otherwise you get weird output on the display
- mVertexBuffer->Bind();
-
// Set sampler uniform
GLint samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER );
if( -1 != samplerLoc )
{
// set the uniform
- program.SetUniform1i( samplerLoc, 0 );
+ program.SetUniform1i( samplerLoc, TEXTURE_UNIT_IMAGE );
}
+ // make sure the vertex is bound, this has to be done before
+ // we call VertexAttribPointer otherwise you get weird output on the display
+ mVertexBuffer->Bind();
+
samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER_RECT );
if( -1 != samplerLoc )
{
#include <dali/internal/common/text-vertex-2d.h>
#include <dali/internal/event/text/font-impl.h>
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/gl-resources/texture.h>
+#include <dali/internal/render/gl-resources/texture-cache.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/internal/render/common/culling-algorithms.h>
#include <dali/internal/render/common/performance-monitor.h>
#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/renderers/scene-graph-renderer-debug.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/shaders/shader.h>
-#include <dali/internal/render/gl-resources/texture-cache.h>
-#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/update/controllers/scene-controller.h>
#if defined(DEBUG_ENABLED)
DALI_LOG_INFO( gTextFilter, Debug::General, "TextRenderer::DoRender(this: %p) textureId:%d\n", this, mTextureId );
+ mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TextureUnitAsGLenum( TEXTURE_UNIT_TEXT ) );
+ if( mTexture->GetTextureId() == 0 )
+ {
+ return; // early out if we haven't got a GL texture yet (e.g. due to context loss)
+ }
+
// Set sampler uniform
const GLint samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER );
if( Program::UNIFORM_UNKNOWN != samplerLoc )
{
// set the uniform
- program.SetUniform1i( samplerLoc, 0 );
+ program.SetUniform1i( samplerLoc, TEXTURE_UNIT_TEXT );
}
+ mTexture->ApplySampler( mSamplerBitfield );
+
const float SMOOTHING_ADJUSTMENT( 12.0f );
const float SMOOTHING_ADJUSTMENT_PIXEL_SIZE( 32.0f );
const GLint positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
const GLint texCoordLoc = program.GetAttribLocation(Program::ATTRIB_TEXCOORD);
- mTexture->Bind(GL_TEXTURE_2D, GL_TEXTURE0);
- mTexture->ApplySampler( mSamplerBitfield );
-
mContext->EnableVertexAttributeArray( positionLoc );
mContext->EnableVertexAttributeArray( texCoordLoc );
#include <dali/internal/render/shaders/shader.h>
// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/common/stage.h>
-#include <dali/public-api/math/matrix.h>
-#include <dali/public-api/math/matrix3.h>
-#include <dali/public-api/math/vector4.h>
-#include <dali/internal/event/effects/shader-factory.h>
#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/render/common/render-debug.h>
#include <dali/internal/render/common/post-process-resource-dispatcher.h>
#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/shaders/uniform-meta.h>
#include <dali/internal/common/image-sampler.h>
if( mTexture )
{
// got effect texture, bind it to texture unit 1
- mTextureCache->BindTexture( mTexture, mRenderTextureId, GL_TEXTURE_2D, GL_TEXTURE1 );
+ mTextureCache->BindTexture( mTexture, mRenderTextureId, GL_TEXTURE_2D, TextureUnitAsGLenum( TEXTURE_UNIT_SHADER ) );
// Just apply the default sampling options for now
mTexture->ApplySampler( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) );
const GLint loc = program.GetUniformLocation( Program::UNIFORM_EFFECT_SAMPLER );
if( Program::UNIFORM_UNKNOWN != loc )
{
- DALI_PRINT_UNIFORM( debugStream, bufferIndex, "sEffect", 1 );
+ DALI_PRINT_UNIFORM( debugStream, bufferIndex, "sEffect", TEXTURE_UNIT_SHADER );
// set the uniform
- program.SetUniform1i( loc, 1 );
+ program.SetUniform1i( loc, TEXTURE_UNIT_SHADER );
}
}