#define _FUI_ANIM_SHADER_PROGRAM_H_
#include <FBaseObject.h>
-
#include <FUiVariant.h>
-
#include <FUiAnimShader.h>
namespace Tizen { namespace Ui { namespace Animations
result Construct(Shader& vertexShader, Shader& fragmentShader);
/**
- * Constructs the ShaderProgram using vertexShader and fragmentShader.
- *
- * @since 3.0
- *
- * @return An error code
- *
- * @param[in] vertexShader source code of vertex shader
- * @param[in] fragmentShader source code of 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(const Tizen::Base::String& vertexShader, const Tizen::Base::String& fragmentShader);
-
- /**
* Gets the value of uniform by name of the current instance of %ShaderProgram
*
* @since 3.0
*/
result SetUniform(const Tizen::Base::String& name, const Tizen::Ui::Variant& value);
+ bool Equals(const ShaderProgram& obj) const;
+
private:
ShaderProgram& operator =(const ShaderProgram& rhs);
*
* This file contains implementation ShaderProgram class.
*/
-
-
#include <FBaseSysLog.h>
#include <FUiVariant.h>
#include <FUiAnimShader.h>
#include "FUiAnim_ShaderProgramImpl.h"
-
namespace Tizen { namespace Ui { namespace Animations
{
-
-
ShaderProgram::ShaderProgram(void)
: __pShaderProgramImpl(null)
{
}
+
ShaderProgram::ShaderProgram(const ShaderProgram& shaderProgram)
: __pShaderProgramImpl(null)
{
__pShaderProgramImpl = shaderProgram.__pShaderProgramImpl;
- if(__pShaderProgramImpl != null)
+ if (__pShaderProgramImpl != null)
{
__pShaderProgramImpl->AddRef();
}
}
+
ShaderProgram::~ShaderProgram(void)
{
if (__pShaderProgramImpl)
result r = __pShaderProgramImpl->Construct(vertexShader, fragmentShader);
SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, r, "Propagating.");
- return E_SUCCESS;
-}
-result
-ShaderProgram::Construct(const Tizen::Base::String& vertexShader, const Tizen::Base::String& fragmentShader)
-{
- ClearLastResult();
- SysAssertf(__pShaderProgramImpl == null,
- "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
- __pShaderProgramImpl = new (std::nothrow) _ShaderProgramImpl();
- SysTryReturnResult(NID_UI_ANIM, __pShaderProgramImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
- result r = __pShaderProgramImpl->Construct(vertexShader, fragmentShader);
- SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, r, "Propagating.");
return E_SUCCESS;
}
+
Variant
ShaderProgram::GetUniform(const Tizen::Base::String& name) const
{
return __pShaderProgramImpl->SetUniform(name, value);
}
+
+bool
+ShaderProgram::Equals(const ShaderProgram& obj) const
+{
+ ClearLastResult();
+ SysAssertf(__pShaderProgramImpl != null,
+ "Not yet constructed. Construct() should be called before use.");
+
+ return __pShaderProgramImpl->Equals(obj);
+}
+
}}} // Tizen::Ui::Animations
{
unsigned int program = 0;
- if (pShaderProgram)
+ if (pShaderProgram != null)
{
program = _ShaderProgramImpl::GetInstance(*pShaderProgram)->__program;
if (program <= 0)
{
- //__pShaderProgram = null;
if (__pShaderProgram != null)
{
delete __pShaderProgram;
SysLog(NID_UI_ANIM, "[E_INVALID_ARG] Invalid argument is used. programId = %d", program);
return E_INVALID_ARG;
}
- }
- if (pShaderProgram != null)
- {
- if (__pShaderProgram)
- {
- delete __pShaderProgram;
- __pShaderProgram = new (std::nothrow) ShaderProgram(*pShaderProgram);
- }
- else
- {
- __pShaderProgram = new (std::nothrow) ShaderProgram(*pShaderProgram);
- }
- }
+ if (!__pShaderProgram || !pShaderProgram->Equals(*__pShaderProgram))
+ {
+ if (__pShaderProgram)
+ {
+ delete __pShaderProgram;
+ __pShaderProgram = null;
+ }
+
+ __pShaderProgram = new (std::nothrow) ShaderProgram(*pShaderProgram);
+ SysAssertf(__pShaderProgram, "failed to create shader program");
+ }
+ }
else
{
if (__pShaderProgram != null)
}
}
- //__pShaderProgram = pShaderProgram;
__isShaderProgramUpdated = true;
return E_SUCCESS;
}
}
- //temp for shader
- ShaderProgram* pProgram = element.GetSharedData().geometry.GetShaderProgram();
+ ShaderProgram* pShaderProgram = element.GetSharedData().geometry.GetShaderProgram();
- if (__pShaderProgram && pProgram)
+ if (unlikely(pShaderProgram))
{
- if (_ShaderProgramImpl::GetInstance(*__pShaderProgram)->__program != _ShaderProgramImpl::GetInstance(*pProgram)->__program)
+ if (!__pShaderProgram || !pShaderProgram->Equals(*__pShaderProgram))
{
- __pShaderProgram = pProgram;
+ if (__pShaderProgram)
+ {
+ delete __pShaderProgram;
+ __pShaderProgram = null;
+ }
+
+ __pShaderProgram = new (std::nothrow) ShaderProgram(*pShaderProgram);
+ SysAssertf(__pShaderProgram, "failed to create shader program");
}
}
else
{
- __pShaderProgram = pProgram;
+ if (__pShaderProgram)
+ {
+ delete __pShaderProgram;
+ __pShaderProgram = null;
+ }
}
__syncNeeded = false;
return E_SUCCESS;
}
-
VisualElementSurface*
_GlNode::GetSurface(void) const
{
return E_SUCCESS;
}
-result
-_ShaderProgramImpl::Construct(const Tizen::Base::String&vertexShader, const Tizen::Base::String& fragmentShader)
-{
- std::wstring wStr(vertexShader.GetPointer());
- std::string vertexShaderStr(wStr.begin(), wStr.end());
-
- std::wstring wStr1(fragmentShader.GetPointer());
- std::string fragmentShaderStr(wStr1.begin(), wStr1.end());
- Shader vert;
- vert.Construct(Shader::SHADER_VERTEX,vertexShaderStr.c_str());
- Shader frag;
- frag.Construct(Shader::SHADER_FRAGMENT,fragmentShaderStr.c_str());
- __vertexShader = _ShaderImpl::GetInstance(vert)->__shaderId;
- __fragmentShader = _ShaderImpl::GetInstance(frag)->__shaderId;
- _GlRenderManager::GetInstance()->BuildShaderProgram(this);
-
- return E_SUCCESS;
-}
-
Variant
_ShaderProgramImpl::GetUniform(const Tizen::Base::String& name) const
{
return E_INVALID_ARG;
}
+bool
+_ShaderProgramImpl::Equals(const ShaderProgram& program) const
+{
+ const ShaderProgram* pProgram = dynamic_cast< const ShaderProgram* >(&program);
+ if (pProgram == null)
+ {
+ return false;
+ }
+
+ const _ShaderProgramImpl* pProgramImpl = _ShaderProgramImpl::GetInstance(program);
+
+ return (pProgramImpl == this);
+}
+
_ShaderProgramImpl*
_ShaderProgramImpl::GetInstance(ShaderProgram& program)
{
virtual ~_ShaderProgramImpl(void);
result Construct(Shader& vertexShader, Shader& fragmentShader);
- result Construct(const Tizen::Base::String& vertexShader, const Tizen::Base::String& fragmentShader); // TODO: remove
Variant GetUniform(const Tizen::Base::String& name) const;
result SetUniform(const Tizen::Base::String& name, const Tizen::Ui::Variant& value);
+
+ bool Equals(const ShaderProgram& program) const;
+
static _ShaderProgramImpl* GetInstance(ShaderProgram& program);
static const _ShaderProgramImpl* GetInstance(const ShaderProgram& program);
void MoveUniformItem(int index, const wchar_t* pUniformName);
private:
- _ShaderProgramImpl(const _ShaderProgramImpl& shader);
+ _ShaderProgramImpl(const _ShaderProgramImpl& program);
_ShaderProgramImpl& operator =(const _ShaderProgramImpl& rhs);
private:
friend class _GlContext;
friend class _GlRenderManager;
- friend class _GlNode; // TODO: remove. add GetProgramId()
- friend class _GeometryInfo; // TODO: remove. add GetProgramId()
+ friend class _GeometryInfo;
};
}}} //Tizen::Ui::Animations