animations/math/FUiAnim_MathVector2.cpp
animations/math/FUiAnim_MathVector3.cpp
animations/math/FUiAnim_MathVector4.cpp
+#=====================================================
+ animations/FUiAnim_CustomShader.cpp
+#=====================================================
)
INCLUDE(FindPkgConfig)
return _pShaderProgramImpl->SetUniform(name, value);
}
+
+result
+ShaderProgram::BindAttribute(ProgramLocation location, const Tizen::Base::String &name)
+{
+ SysAssertf(_pShaderProgramImpl != null,
+ "Not yet constructed. Construct() should be called before use.");
+
+ return _pShaderProgramImpl->BindAttribute(location, name);
+}
+
+result
+ShaderProgram::BindUniform(ProgramLocation location, const Tizen::Base::String &name)
+{
+ SysAssertf(_pShaderProgramImpl != null,
+ "Not yet constructed. Construct() should be called before use.");
+
+ return _pShaderProgramImpl->BindUniform(location, name);
+}
+
+bool
+ShaderProgram::IsParameterAvailable(const ProgramLocation location) const
+{
+ return _pShaderProgramImpl->IsParameterAvailable(location);
+}
+
+
+bool
+ShaderProgram::IsParameterAvailable(const Tizen::Base::String& name) const
+{
+ return _pShaderProgramImpl->IsParameterAvailable(name);
+}
}}} // Tizen::Ui::Animations
namespace Tizen { namespace Ui { namespace Animations
{
+/**
+ * @enum ProgramLocation
+ *
+ * Defines the basic types for program location in shader program.
+ *
+ * @since 3.0
+ */
+enum ProgramLocation
+ {
+ UNIFORM_MAT4_MVP = 0, /**< Uniform for matrix view projection*/
+ UNIFORM_VEC4_COLOR, /**< Uniform for color*/
+ UNIFORM_SAMPLER2D_TEXTURE, /**< Uniform for texture*/
+ UNIFORM_FLOAT_OPACITY, /**< Uniform for opacity*/
+ UNIFORM_MAT4_MODEL_VIEW, /**< Uniform for model view matrix*/
+ UNIFORM_MAT4_INV_MODEL_VIEW, /**< Uniform for inverted model view*/
+ ATTRIBUTE_VEC2_TEXTURE_COORD, /**< Attribute for texture coordinate*/
+ ATTRIBUTE_VEC4_POSITION, /**< Attribute for position*/
+ ATTRIBUTE_VEC4_COLOR, /**< Attribute for color*/
+ ATTRIBUTE_VEC3_NORMAL, /**< Attribute for normal*/
+ PROGRAM_LOCATION_MAX /**< Maximum of program location*/
+ };
class _ShaderProgramImpl;
class _OSP_EXPORT_ ShaderProgram
ShaderProgram(void);
virtual ~ShaderProgram(void);
+ /**
+ * Constructs the ShaderProgram using vertexShader and fragmentShader.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ *
+ * @param[in] vertexShader compiled vertex shader
+ * @param[in] fragmentShader compiled fragment shader
+ *
+ * @exception E_SUCCESS
+ * @exception E_OUT_OF_MEMORY
+ * @exception E_SYSTEM if shader was not constructed or compiled with an error
+ */
result Construct(Shader& vertexShader, Shader& fragmentShader);
Variant GetUniform(const Tizen::Base::String& name) const;
result SetUniform(const Tizen::Base::String& name, const Tizen::Ui::Variant& value);
+ /**
+ * Binds an attribute to the ShaderProgram.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ *
+ * @param[in] location possibly program locations
+ * @param[in] name attribute name in shader program
+ *
+ * @exception E_SUCCESS
+ * @exception E_INVALID_ARG if name was not found in shader program
+ * @see ProgramLocation
+ */
+ result BindAttribute(ProgramLocation location, const Tizen::Base::String &name);
+
+ /**
+ * Binds the uniform to the ShaderProgram.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ *
+ * @param[in] location possibly location
+ * @param[in] name uniform name in shader program
+ *
+ * @exception E_SUCCESS
+ * @exception E_INVALID_ARG if name was not found in shader program
+ * @see ProgramLocation
+ */
+ result BindUniform(ProgramLocation location, const Tizen::Base::String &name);
+
+ /**
+ * Checks the program location for been bind with uniform or attribute in shader program
+ *
+ * @since 3.0
+ *
+ * @return true, if location is bind, false otherwise
+ *
+ * @param[in] location requested location
+ * @see ProgramLocation
+ */
+ bool IsParameterAvailable(const ProgramLocation location) const;
+
+ /**
+ * Checks for the uniform or attribute by name in shader program been bind with program location
+ *
+ * @since 3.0
+ *
+ * @return true, if name is bind, false otherwise
+ *
+ * @param[in] name Tizen::Base::String name of the uniform or attribute in shader program
+ */
+ bool IsParameterAvailable(const Tizen::Base::String& name) const;
private:
ShaderProgram(const ShaderProgram& program);
ShaderProgram& operator =(const ShaderProgram& rhs);
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2013 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.
+//
+
+/**
+ * @file FUiAnim_CustomShader.cpp
+ * @brief This file contains implementation of _CustomShader class
+ *
+ * This file contains implementation _CustomShader class.
+ */
+
+
+#include "FUiAnim_CustomShader.h"
+
+using namespace Tizen::Base;
+using std::pair;
+
+namespace Tizen { namespace Ui { namespace Animations
+{
+
+_CustomShader::_CustomShader(unsigned int program)
+{
+ SetProgram(program);
+}
+
+_CustomShader::~_CustomShader(void)
+{
+ __attributeLocations.clear();
+ __uniformLocations.clear();
+}
+
+
+bool
+_CustomShader::IsParameterAvailable(const ProgramLocation location) const
+{
+ containerLocations::const_iterator it;
+ for (it = __attributeLocations.begin(); it != __attributeLocations.end(); it++)
+ {
+ if ((it->first).first == location)
+ {
+ return true;
+ }
+ }
+ for (it = __uniformLocations.begin(); it != __uniformLocations.end(); it++)
+ {
+ if ((it->first).first == location)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+bool
+_CustomShader::IsParameterAvailable(const Tizen::Base::String& name) const
+{
+ containerLocations::const_iterator it;
+ for (it = __attributeLocations.begin(); it != __attributeLocations.end(); it++)
+ {
+ if (String::Compare((it->first).second, name) == 0)
+ {
+ return true;
+ }
+ }
+ for (it = __uniformLocations.begin(); it != __uniformLocations.end(); it++)
+ {
+ if (String::Compare((it->first).second, name) == 0)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+void
+_CustomShader::BindAttributes()
+{
+ const int numOfAttributes = 10;
+ char *attributes[numOfAttributes] = {
+ "u_mvp",
+ "u_color",
+ "u_texture",
+ "u_opacity",
+ "u_modelview",
+ "u_invmodelview",
+ "a_textcoord",
+ "a_position",
+ "a_color",
+ "a_normal"
+ };
+
+ int glAttribute = -1;
+ int program = GetProgram();
+
+ for (int i = 0; i < numOfAttributes; i++)
+ {
+ if ((glAttribute = glGetAttribLocation(program, attributes[i])) != -1)
+ {
+ String locationName(attributes[i]);
+ __attributeLocations.push_back(pair <pair<ProgramLocation, String>, int>(pair<ProgramLocation, String>((ProgramLocation)i, locationName), glAttribute));
+ }
+ if ((glAttribute = glGetUniformLocation(program, attributes[i])) != -1)
+ {
+ String locationName(attributes[i]);
+ __uniformLocations.push_back(pair <pair<ProgramLocation, String>, int>(pair<ProgramLocation, String>((ProgramLocation)i, locationName), glAttribute));
+ }
+ }
+ return;
+}
+
+
+int
+_CustomShader::GetAttributes(const ProgramLocation location) const
+{
+ containerLocations::const_iterator it;
+ for (it = __attributeLocations.begin(); it != __attributeLocations.end(); it++)
+ {
+ if ((it->first).first == location)
+ {
+ return it->second;
+ }
+ }
+ return -1;
+}
+
+
+int
+_CustomShader::GetUniforms(const ProgramLocation location) const
+{
+ containerLocations::const_iterator it;
+ for (it = __uniformLocations.begin(); it != __uniformLocations.end(); it++)
+ {
+ if ((it->first).first == location)
+ {
+ return it->second;
+ }
+ }
+ return -1;
+}
+
+
+
+void
+_CustomShader::OnProgramReferenced(void)
+{
+ containerLocations::iterator it;
+ for (it = __attributeLocations.begin(); it != __attributeLocations.end(); it++)
+ {
+ glEnableVertexAttribArray(it->second);
+ }
+ return;
+}
+
+void
+_CustomShader::OnProgramDereferenced(void)
+{
+ containerLocations::iterator it;
+ for (it = __attributeLocations.begin(); it != __attributeLocations.end(); it++)
+ {
+ glDisableVertexAttribArray(it->second);
+ }
+ return;
+}
+
+result
+_CustomShader::BindAttribute(const ProgramLocation location,const Tizen::Base::String &name)
+{
+ std::wstring wStr(name.GetPointer());
+ std::string locationName(wStr.begin(), wStr.end());
+ int glAttribute;
+ glAttribute = glGetAttribLocation(GetProgram(), locationName.c_str());
+ SysTryReturnResult(NID_UI_ANIM, glAttribute != -1, E_INVALID_ARG, "Can't bind a \"%s\" attribute", locationName.c_str());
+ __attributeLocations.push_back(pair< pair<ProgramLocation, String>, int>(pair<ProgramLocation, String>(location, name), glAttribute));
+ return E_SUCCESS;
+}
+
+
+result
+_CustomShader::BindUniform(const ProgramLocation location,const Tizen::Base::String &name)
+{
+ std::wstring wStr(name.GetPointer());
+ std::string locationName(wStr.begin(), wStr.end());
+ int glAttribute;
+ glAttribute = glGetUniformLocation(GetProgram(), locationName.c_str());
+ SysTryReturnResult(NID_UI_ANIM, glAttribute != -1, E_INVALID_ARG, "Can't bind a \"%s\" uniform", locationName.c_str());
+ __uniformLocations.push_back(pair< pair<ProgramLocation, String>, int>(pair<ProgramLocation, String>(location, name), glAttribute));
+ return E_SUCCESS;
+}
+
+
+}}} //Tizen::Ui::Animations
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2013 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.
+//
+
+/**
+ * @file FUiAnim_CustomShader.h
+ * @brief This is the header file for the _CustomShader class.
+ *
+ * This header file contains the declarations of the _CustomShader class.
+ */
+
+
+#ifndef _FUI_ANIM_CUSTOM_SHADER_
+#define _FUI_ANIM_CUSTOM_SHADER_
+
+#include "FUiAnim_GlShaderProgram.h"
+#include "FUiAnimShaderProgram.h"
+#include <FBaseSysLog.h>
+#include <string>
+#include <GLES2/gl2.h>
+#include <vector>
+#include <utility>
+namespace Tizen { namespace Ui { namespace Animations
+{
+
+class _CustomShader
+ : public _GlShaderProgram
+{
+public:
+ _CustomShader(unsigned int program);
+ virtual ~_CustomShader(void);
+ virtual void OnProgramCreated(void) {};
+ virtual void OnProgramReferenced(void);
+ virtual void OnProgramDereferenced(void);
+ void BindAttributes();
+ bool IsParameterAvailable(const ProgramLocation location) const;
+ bool IsParameterAvailable(const Tizen::Base::String& name) const;
+ int GetAttributes(const ProgramLocation location) const;
+ int GetUniforms(const ProgramLocation location) const;
+ result BindAttribute(const ProgramLocation location, const Tizen::Base::String& name);
+ result BindUniform(const ProgramLocation location, const Tizen::Base::String& name);
+private:
+ typedef std::vector<std::pair< std::pair<ProgramLocation, Tizen::Base::String>, int> > containerLocations;
+
+ containerLocations __attributeLocations;
+ containerLocations __uniformLocations;
+};
+
+}}} //Tizen::Ui::Animations
+
+#endif //_FUI_ANIM_CUSTOM_SHADER_
__pProgram = _GlRenderManager::GetInstance()->__pLightShader;
}
-
- // Set program info
- __uMVP = __pProgram->GetMVPUniformLocation();
- __uOpacity = __pProgram->GetOpacityUniformLocation();
- __uColor = __pProgram->GetColorUniformLocation();
-
- __aPosition = __pProgram->GetPositionAttributeLocation();
- __aTexCoord = __pProgram->GetTextureCoordinatesAttributeLocation();
- __aColor = __pProgram->GetColorAttributeLocation();
- __aNormal = __pProgram->GetNormalAttributeLocation();
-
+ if (pNode->__pShaderProgram != null)
+ {
+ _ShaderProgramImpl* pShaderProgramImpl = _ShaderProgramImpl::GetInstance(*pNode->__pShaderProgram);
+ __pProgram = pShaderProgramImpl->GetCusomShader();
+
+ __pLight = null;
+ __uMVP = pShaderProgramImpl->GetUniform(UNIFORM_MAT4_MVP);
+ __aPosition = pShaderProgramImpl->GetAttribute(ATTRIBUTE_VEC4_POSITION);
+ __aColor = pShaderProgramImpl->GetAttribute(ATTRIBUTE_VEC4_COLOR);
+ __uOpacity = pShaderProgramImpl->GetUniform(UNIFORM_FLOAT_OPACITY);
+ __uColor = pShaderProgramImpl->GetUniform(UNIFORM_VEC4_COLOR);
+ __aTexCoord = pShaderProgramImpl->GetAttribute(ATTRIBUTE_VEC2_TEXTURE_COORD);
+ __aNormal = pShaderProgramImpl->GetAttribute(ATTRIBUTE_VEC3_NORMAL);
+ }
+ else
+ {
+ // Set program info
+ __uMVP = __pProgram->GetMVPUniformLocation();
+ __uOpacity = __pProgram->GetOpacityUniformLocation();
+ __uColor = __pProgram->GetColorUniformLocation();
+
+ __aPosition = __pProgram->GetPositionAttributeLocation();
+ __aTexCoord = __pProgram->GetTextureCoordinatesAttributeLocation();
+ __aColor = __pProgram->GetColorAttributeLocation();
+ __aNormal = __pProgram->GetNormalAttributeLocation();
+ }
return;
}
case COMMAND_DELETE_TEXTURE:
pThis->CommandHandlerDeleteTexture(commandArg.__pCommandTextureInfo);
break;
-
+ case COMMAND_BUILD_SHADER_PROGRAM:
+ pThis->CommandHandlerBuildShaderProgram(commandArg.__pCommandShaderProgram);
+ break;
+ case COMMAND_BUILD_SHADER:
+ pThis->CommandHandlerBuildShader(commandArg.__pCommandShader);
+ break;
case COMMAND_COMPOSITE:
PRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - start \n");
return true;
}
+
+void
+_GlShaderProgram::SetProgram(unsigned int program)
+{
+__program = program;
+}
+
+
bool
_GlShaderProgram::LoadShader(const char* pVertexShaderBin, int vertexLength, const char* pFragmentShaderBin, int fragmentLength)
{
bool LoadShader(const char* pVertexShaderSrc, const char* pFragmentShaderSrc);
bool LoadShader(const char* pVertexShaderBin, int vertexLength, const char* pFragmentShaderBin, int fragmentLength);
-
+ void SetProgram(unsigned int program);
int GetProgram(void) const { return __program; }
int GetAttribLocation(const char* name);
int GetUniformLocation(const char* name);
: __program(0)
, __vertexShader(0)
, __fragmentShader(0)
+ , __pCustomShader(null)
{
memset(__locationId, 0, sizeof(unsigned int) * PROGRAM_LOCATION_MAX);
}
-
+ delete __pCustomShader;
__locations.RemoveAll();
}
SysTryReturnResult(NID_UI_ANIM, __program > 0, E_SYSTEM, "Failed to build shader program.");
+ __pCustomShader = new (std::nothrow) _CustomShader(__program);
+ SysTryReturnResult(NID_UI_ANIM, __pCustomShader, E_OUT_OF_MEMORY, "Memory allocation failed.");
+ __pCustomShader->BindAttributes();
return E_SUCCESS;
}
return E_SUCCESS;
}
+_CustomShader*
+_ShaderProgramImpl::GetCusomShader()
+{
+ return __pCustomShader;
+}
+
+int
+_ShaderProgramImpl::GetAttribute(const ProgramLocation location)
+{
+ return __pCustomShader->GetAttributes(location);
+}
+int
+_ShaderProgramImpl::GetUniform(const ProgramLocation location)
+{
+ return __pCustomShader->GetUniforms(location);
+}
+
+
+result
+_ShaderProgramImpl::BindAttribute(ProgramLocation location, const Tizen::Base::String &name)
+{
+ return __pCustomShader->BindAttribute(location,name);
+}
+
+
+result
+_ShaderProgramImpl::BindUniform(ProgramLocation location, const Tizen::Base::String &name)
+{
+ return __pCustomShader->BindUniform(location,name);
+}
+
+bool
+_ShaderProgramImpl::IsParameterAvailable(const ProgramLocation location) const
+{
+ return __pCustomShader->IsParameterAvailable(location);
+}
+
+
+bool
+_ShaderProgramImpl::IsParameterAvailable(const Tizen::Base::String& name) const
+{
+ return __pCustomShader->IsParameterAvailable(name);
+}
+
+
int
_ShaderProgramImpl::GetUniformLocation(const Tizen::Base::String& name)
{
if (name == UniformMVP)
{
- return __locationId[UNIFORM_MVP];
+ return __locationId[UNIFORM_MAT4_MVP];
}
else if (name == UniformColor)
{
- return __locationId[ATTRIBUTE_COLOR];
+ return __locationId[ATTRIBUTE_VEC4_COLOR];
}
return 0;//GetLocation(UNIFORM_TYPE, name);
{
if (name == AttributePosition)
{
- return __locationId[ATTRIBUTE_POSITION];
+ return __locationId[ATTRIBUTE_VEC4_POSITION];
}
else if (name == AttributeTexCoord)
{
- return __locationId[ATTRIBUTE_TEXTURE_COORD];
+ return __locationId[ATTRIBUTE_VEC2_TEXTURE_COORD];
}
else if (name == AttributeColor)
{
- return __locationId[ATTRIBUTE_COLOR];
+ return __locationId[ATTRIBUTE_VEC4_COLOR];
}
return 0;//GetLocation(ATTRIBUTE_TYPE, name);
#include <FBaseObject.h>
#include <FBaseString.h>
#include <FBaseColHashMapT.h>
-
+#include "FUiAnim_CustomShader.h"
#include <FUiAnimShaderProgram.h>
namespace Tizen { namespace Ui { namespace Animations
: public Tizen::Base::Object
{
public:
- enum PROGRAM_LOCATION
+ /*enum PROGRAM_LOCATION
{
UNIFORM_MVP = 0,
UNIFORM_COLOR,
ATTRIBUTE_COLOR,
// LIGHT_COLOR,
PROGRAM_LOCATION_MAX
- };
+ };*/
public:
_ShaderProgramImpl(void);
int GetUniformLocation(const Tizen::Base::String& name);
int GetAttribLocation(const Tizen::Base::String& name);
+ result BindAttribute(ProgramLocation location, const Tizen::Base::String &name);
+ result BindUniform(ProgramLocation location, const Tizen::Base::String &name);
+ _CustomShader* GetCusomShader();
+ int GetAttribute(const ProgramLocation location);
+ int GetUniform(const ProgramLocation location);
+ bool IsParameterAvailable(const ProgramLocation location) const;
+ bool IsParameterAvailable(const Tizen::Base::String& name) const;
+
static _ShaderProgramImpl* GetInstance(ShaderProgram& program);
static const _ShaderProgramImpl* GetInstance(const ShaderProgram& program);
_RequestItem __request;
private:
+ _CustomShader* __pCustomShader;
_ShaderProgramImpl(const _ShaderProgramImpl& shader);
_ShaderProgramImpl& operator =(const _ShaderProgramImpl& rhs);
};