#ifndef __DALI_INTERNAL_PROGRAM_H__
#define __DALI_INTERNAL_PROGRAM_H__
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2016 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.
+ *
+ */
// EXTERNAL INCLUDES
#include <string>
// INTERNAL INCLUDES
#include <dali/public-api/common/vector-wrapper.h>
-#include <dali/public-api/common/set-wrapper.h>
#include <dali/public-api/object/ref-object.h>
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/integration-api/resource-cache.h>
+#include <dali/integration-api/gl-abstraction.h>
+#include <dali/internal/common/shader-data.h>
namespace Dali
{
namespace Internal
{
-class Context;
+class ProgramCache;
/*
* A program contains a vertex & fragment shader.
*
- * A program will contain vertex attributes and uniform variables
- * E.g. inside the code for our text fragment shaders we have the line:
- * \code
- * uniform lowp vec4 uColor
- * \endcode
- *
- * This describes a variable used to color text as it is drawn.
+ * A program will contain vertex attributes and uniform variables.
*
* uColor is set to the value specified by Actor::SetColor and is
* animatable through the property Actor::COLOR
{
ATTRIB_UNKNOWN = -1,
ATTRIB_POSITION,
- ATTRIB_NORMAL,
ATTRIB_TEXCOORD,
- ATTRIB_COLOR,
- ATTRIB_BONE_WEIGHTS,
- ATTRIB_BONE_INDICES,
ATTRIB_TYPE_LAST
};
UNIFORM_VIEW_MATRIX,
UNIFORM_NORMAL_MATRIX,
UNIFORM_COLOR,
- UNIFORM_CUSTOM_TEXTURE_COORDS,
UNIFORM_SAMPLER,
UNIFORM_SAMPLER_RECT,
UNIFORM_EFFECT_SAMPLER,
- UNIFORM_EFFECT_SAMPLER_RECT,
- UNIFORM_TIME_DELTA,
- UNIFORM_SAMPLER_OPACITY,
- UNIFORM_SAMPLER_NORMAL_MAP,
-
- UNIFORM_TEXT_COLOR,
- UNIFORM_SMOOTHING,
- UNIFORM_OUTLINE,
- UNIFORM_OUTLINE_COLOR,
- UNIFORM_GLOW,
- UNIFORM_GLOW_COLOR,
- UNIFORM_SHADOW,
- UNIFORM_SHADOW_COLOR,
- UNIFORM_SHADOW_SMOOTHING,
- UNIFORM_GRADIENT_COLOR,
- UNIFORM_GRADIENT_LINE,
- UNIFORM_INVERSE_TEXT_SIZE,
+ UNIFORM_SIZE,
UNIFORM_TYPE_LAST
};
/**
* Creates a new program, or returns a copy of an existing program in the program cache
- * maintained by Context
- * @param [in] resourceId ResourceManager resourceId for the shader source and binary.
- * Used as a lookup key in the program cache
+ * @param[in] cache where the programs are stored
* @param[in] shaderData A pointer to a data structure containing the program source
* and optionally precompiled binary. If the binary is empty the program bytecode
* is copied into it after compilation and linking)
- * @param [in] context GL context
+ * @param[in] modifiesGeometry True if the shader modifies geometry
* @return pointer to the program
*/
- static Program* New( const Integration::ResourceId& resourceId, Integration::ShaderData* shaderData, Context& context );
+ static Program* New( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
/**
* Takes this program into use
GLint GetAttribLocation( AttribType type );
/**
- * Register a uniform name in our local cache
- * @param [in] name uniform name
- * @return the index of the uniform name in local cache
+ * Register an attribute name in our local cache
+ * @param [in] name attribute name
+ * @return the index of the attribute name in local cache
+ */
+ unsigned int RegisterCustomAttribute( const std::string& name );
+
+ /**
+ * Gets the location of a pre-registered attribute.
+ * @param [in] attributeIndex of the attribute in local cache
+ * @return the index of the attribute in the GL program
*/
- unsigned int RegisterExternalUniform( const std::string& name );
+ GLint GetCustomAttributeLocation( unsigned int attributeIndex );
/**
* Register a uniform name in our local cache
* @param [in] name uniform name
* @return the index of the uniform name in local cache
*/
- unsigned int RegisterUniform( const char* name );
+ unsigned int RegisterUniform( const std::string& name );
/**
* Gets the location of a pre-registered uniform.
GLint GetUniformLocation( unsigned int uniformIndex );
/**
+ * Introspect the newly loaded shader to get the active sampler locations
+ */
+ void GetActiveSamplerUniforms();
+
+ /**
+ * Gets the uniform location for a sampler
+ * @param [in] index The index of the active sampler
+ * @param [out] location The location of the requested sampler
+ * @return true if the active sampler was found
+ */
+ bool GetSamplerUniformLocation( unsigned int index, GLint& location );
+
+ /**
+ * Get the number of active samplers present in the shader
+ * @return The number of active samplers
+ */
+ size_t GetActiveSamplerCount() const;
+
+ /**
* Sets the uniform value
* @param [in] location of uniform
* @param [in] value0 as int
void SetUniform2f( GLint location, GLfloat value0, GLfloat value1 );
/**
+ * Special handling for size as we're using uniform geometry so size is passed on to most programs
+ * but it rarely changes so we can cache it
+ * @param [in] location of uniform
+ * @param [in] value0 as float
+ * @param [in] value1 as float
+ * @param [in] value2 as float
+ */
+ void SetSizeUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 );
+
+ /**
* Sets the uniform value
* @param [in] location of uniform
* @param [in] value0 as float
*/
void GlContextDestroyed();
+ /**
+ * @return true if this program modifies geometry
+ */
+ bool ModifiesGeometry();
+
+ /**
+ * Set the projection matrix that has currently been sent
+ * @param matrix to set
+ */
+ void SetProjectionMatrix( const Matrix* matrix )
+ {
+ mProjectionMatrix = matrix;
+ }
+
+ /**
+ * Get the projection matrix that has currently been sent
+ * @return the matrix that is set
+ */
+ const Matrix* GetProjectionMatrix()
+ {
+ return mProjectionMatrix;
+ }
+
+ /**
+ * Set the projection matrix that has currently been sent
+ * @param matrix to set
+ */
+ void SetViewMatrix( const Matrix* matrix )
+ {
+ mViewMatrix = matrix;
+ }
+
+ /**
+ * Get the projection matrix that has currently been sent
+ * @return the matrix that is set
+ */
+ const Matrix* GetViewMatrix()
+ {
+ return mViewMatrix;
+ }
+
private: // Implementation
/**
* Constructor, private so no direct instantiation
- * @param[in] shaderData A pointer to a data structure containing the program source and binary
- * @param[in] context The GL context state cache.
+ * @param[in] cache where the programs are stored
+ * @param[in] shaderData A smart pointer to a data structure containing the program source and binary
+ * @param[in] modifiesGeometry True if the vertex shader changes geometry
*/
- Program( Integration::ShaderData* shaderData, Context& context );
+ Program( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
public:
private:
- // default constructor, not defined
- Program();
- // assignment operator, not defined
- Program& operator=( const Program& );
+ Program(); ///< default constructor, not defined
+ Program( const Program& ); ///< copy constructor, not defined
+ Program& operator=( const Program& ); ///< assignment operator, not defined
/**
* Load the shader, from a precompiled binary if available, else from source code
/**
* Resets caches
*/
- void ResetAttribsUniforms();
+ void ResetAttribsUniformCache();
private: // Data
- Context& mContext; ///< The GL context state cache
+ ProgramCache& mCache; ///< The program cache
Integration::GlAbstraction& mGlAbstraction; ///< The OpenGL Abstraction layer
+ const Matrix* mProjectionMatrix; ///< currently set projection matrix
+ const Matrix* mViewMatrix; ///< currently set view matrix
bool mLinked; ///< whether the program is linked
GLuint mVertexShaderId; ///< GL identifier for vertex shader
GLuint mFragmentShaderId; ///< GL identifier for fragment shader
GLuint mProgramId; ///< GL identifier for program
- Integration::ShaderData* mProgramData; ///< Shader program source and binary (when compiled & linked or loaded)
+ Internal::ShaderDataPtr mProgramData; ///< Shader program source and binary (when compiled & linked or loaded)
+
+ // location caches
+ typedef std::pair< std::string, GLint > NameLocationPair;
+ typedef std::vector< NameLocationPair > Locations;
- // uniform location caches
- GLint mAttribLocations[ ATTRIB_TYPE_LAST ]; ///< attribute location cache
- GLint mBuiltinUniformLocations[ UNIFORM_TYPE_LAST ]; ///< uniform location cache for built in uniforms
- std::vector< std::pair< const char *, GLint > > mCustomUniformLocations; ///< uniform location cache for custom uniforms
- static std::set< std::string > mExternalUniformNames; /// < names for externally specified uniforms, set to avoid duplicates
+ Locations mAttributeLocations; ///< attribute location cache
+ Locations mUniformLocations; ///< uniform location cache
+ std::vector<GLint> mSamplerUniformLocations; ///< sampler uniform location cache
// uniform value caching
GLint mUniformCacheInt[ MAX_UNIFORM_CACHE_SIZE ]; ///< Value cache for uniforms of single int
GLfloat mUniformCacheFloat[ MAX_UNIFORM_CACHE_SIZE ]; ///< Value cache for uniforms of single float
- GLfloat mUniformCacheFloat4[ MAX_UNIFORM_CACHE_SIZE ][4]; ///< Value cache for uniforms of four float
+ GLfloat mUniformCacheFloat2[ MAX_UNIFORM_CACHE_SIZE ][2]; ///< Value cache for uniforms of two floats
+ GLfloat mUniformCacheFloat4[ MAX_UNIFORM_CACHE_SIZE ][4]; ///< Value cache for uniforms of four floats
+ Vector3 mSizeUniformCache; ///< Cache value for size uniform
+ bool mModifiesGeometry; ///< True if the program changes geometry
};