// __pCurrentShader->OnProgramReferenced();
unsigned int program = _ShaderProgramImpl::GetInstance(*pShaderProgram)->__program;
- AppLog("\n jinstar -- use program %d", program);
glUseProgram(program);
}
else
type = GL_FRAGMENT_SHADER;
break;
default:
- break;
-// return 0;
- };
-
- if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER)
return 0;
-
-#ifndef VE_USE_GL_MULTI_CONTEXT
- CHECK_GL_CONTEXT();
-#endif
+ };
GLuint shaderId = glCreateShader(type);
if (shaderId == 0)
return 0;
}
- //for log
- switch(type)
- {
- case GL_VERTEX_SHADER:
- AppLog("\n jinstar -- BuildShader vertex %d", shaderId);
- break;
- case GL_FRAGMENT_SHADER:
- AppLog("\n jinstar -- BuildShader fragment %d", shaderId);
- break;
- }
-
return shaderId;
}
bool
_GlContext::DeleteShader(GLuint shaderId)
{
-#ifndef VE_USE_GL_MULTI_CONTEXT
- CHECK_GL_CONTEXT();
-#endif
-
- AppLog("\n jinstar -- Delete Shader %d", shaderId);
-
glDeleteShader(shaderId);
return true;
GLuint
_GlContext::BuildShaderProgram(GLuint vertexShader, GLuint fragmentShader)
{
-#ifndef VE_USE_GL_MULTI_CONTEXT
- CHECK_GL_CONTEXT();
-#endif
-
if (vertexShader <= 0 || fragmentShader <= 0)
{
return 0;
return 0;
}
- AppLog("\n jinstar -- Build Program %d", programId);
-
return programId;
}
bool
_GlContext::DeleteShaderProgram(GLuint programId)
{
-#ifndef VE_USE_GL_MULTI_CONTEXT
- CHECK_GL_CONTEXT();
-#endif
-
- AppLog("\n jinstar -- Delete Program %d", programId);
-
glDeleteProgram(programId);
return true;
int
_GlContext::GetAttribLocation(int program, const char* name)
{
- int location = glGetAttribLocation(program, name);
-
- AppLog("\n jinstar -- GetAttribLocation %d %s %d [error:%d]", program, name, location, glGetError());
-
- return location;
-// return glGetAttribLocation(program, name);
+ return glGetAttribLocation(program, name);
}
int
_GlContext::GetUniformLocation(int program, const char* name)
{
- int location = glGetUniformLocation(program, name);
-
- AppLog("\n jinstar -- GetUniformLocation %d %s %d [error:%d]", program, name, location, glGetError());
-
- return location;
-// return glGetUniformLocation(program, name);
+ return glGetUniformLocation(program, name);
}
glUseProgram(program);
glEnableVertexAttribArray(index);
-
- AppLog("\n jinstar -- EnableVertexAttribArray %d %d [error:%d]", program, index, glGetError());
- //TODO: Need to return glGetError()
}
void
glUseProgram(program);
glDisableVertexAttribArray(index);
-
- AppLog("\n jinstar -- EnableVertexAttribArray %d %d [error:%d]", program, index, glGetError());
}
{
if (__pRenderQueue[i].__pColors)
{
- glEnableVertexAttribArray(__pRenderQueue[i].__aColor);
glVertexAttribPointer(__pRenderQueue[i].__aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), __pRenderQueue[i].__pColors);
}
else
return (__commandResult == E_SUCCESS);
}
-bool
-_GlRenderManager::GetAttribLocation(_ShaderProgramImpl* pShaderProgram)
-{
- _AutoMutex commandTransactionLock(__commandTransaction);
- _AutoMutex commandLock(__commandLock);
-
- __commandId = COMMAND_GET_ATTRIBUTE_LOCATION;
- __commandArg.__pCommandShaderProgram = pShaderProgram;
- __commandRequest.SendSignal();
- __commandReply.WaitForSignal(&__commandLock);
-
- return (__commandResult == E_SUCCESS);
-}
-
-bool
-_GlRenderManager::GetUniformLocation(_ShaderProgramImpl* pShaderProgram)
-{
- _AutoMutex commandTransactionLock(__commandTransaction);
- _AutoMutex commandLock(__commandLock);
-
- __commandId = COMMAND_GET_UNIFORM_LOCATION;
- __commandArg.__pCommandShaderProgram = pShaderProgram;
- __commandRequest.SendSignal();
- __commandReply.WaitForSignal(&__commandLock);
-
- return (__commandResult == E_SUCCESS);
-}
-
-bool
-_GlRenderManager::EnableVertexAttribArray(_ShaderProgramImpl* pShaderProgram)
-{
- _AutoMutex commandTransactionLock(__commandTransaction);
- _AutoMutex commandLock(__commandLock);
-
- __commandId = COMMAND_ENABLE_VERTEX_ATTRIB_ARRAY;
- __commandArg.__pCommandShaderProgram = pShaderProgram;
- __commandRequest.SendSignal();
- __commandReply.WaitForSignal(&__commandLock);
-
- return (__commandResult == E_SUCCESS);
-}
-
-bool
-_GlRenderManager::DisableVertexAttribArray(_ShaderProgramImpl* pShaderProgram)
-{
- _AutoMutex commandTransactionLock(__commandTransaction);
- _AutoMutex commandLock(__commandLock);
-
- __commandId = COMMAND_DISABLE_VERTEX_ATTRIB_ARRAY;
- __commandArg.__pCommandShaderProgram = pShaderProgram;
- __commandRequest.SendSignal();
- __commandReply.WaitForSignal(&__commandLock);
-
- return (__commandResult == E_SUCCESS);
-}
-
//temp
unsigned int
_GlRenderManager::BuildShader(int type, const char* pShaderSource)
COMMAND_BUILD_SHADER,
COMMAND_DELETE_SHADER,
COMMAND_BUILD_SHADER_PROGRAM,
- COMMAND_DELETE_SHADER_PROGRAM,
- COMMAND_GET_UNIFORM_LOCATION,
- COMMAND_GET_ATTRIBUTE_LOCATION,
- COMMAND_ENABLE_VERTEX_ATTRIB_ARRAY,
- COMMAND_DISABLE_VERTEX_ATTRIB_ARRAY
+ COMMAND_DELETE_SHADER_PROGRAM
};
static _GlRenderManager* GetInstance(void)
bool DeleteShader(_ShaderImpl* pShader);
bool BuildShaderProgram(_ShaderProgramImpl* pShaderProgram);
bool DeleteShaderProgram(_ShaderProgramImpl* pShaderProgram);
- bool GetAttribLocation(_ShaderProgramImpl* pShaderProgram);
- bool GetUniformLocation(_ShaderProgramImpl* pShaderProgram);
-
- bool EnableVertexAttribArray(_ShaderProgramImpl* pShaderProgram);
- bool DisableVertexAttribArray(_ShaderProgramImpl* pShaderProgram);
unsigned int BuildShader(int type, const char* pShaderSource);
bool DeleteShader(GLuint shaderId);
_GlRenderManager::GetInstance()->BuildShader(this);
- if (__type == Shader::SHADER_VERTEX)
- AppLog("\n jinstar : vertex shader : %d", __shaderId);
- else
- AppLog("\n jinstar : fragment shader : %d", __shaderId);
-
SysTryReturnResult(NID_UI_ANIM, __shaderId > 0, E_SYSTEM, "Failed to build shader.");
return E_SUCCESS;
_GlRenderManager::GetInstance()->BuildShaderProgram(this);
- AppLog("\n jinstar : shader program : %d", __program);
-
SysTryReturnResult(NID_UI_ANIM, __program > 0, E_SYSTEM, "Failed to build shader program.");
- // temp
- __request.name = UniformMVP;
- _GlRenderManager::GetInstance()->GetUniformLocation(this);
- __locationId[UNIFORM_MVP] = __request.location;
-
- __request.name= UniformColor;
- _GlRenderManager::GetInstance()->GetUniformLocation(this);
- __locationId[UNIFORM_COLOR] = __request.location;
-
- __request.name = AttributePosition;
- _GlRenderManager::GetInstance()->GetAttribLocation(this);
- __locationId[ATTRIBUTE_POSITION] = __request.location;
-
- __request.name = AttributeTexCoord;
- _GlRenderManager::GetInstance()->GetAttribLocation(this);
- __locationId[ATTRIBUTE_TEXTURE_COORD] = __request.location;
-
- __request.name = AttributeColor;
- _GlRenderManager::GetInstance()->GetAttribLocation(this);
- __locationId[ATTRIBUTE_COLOR] = __request.location;
-
return E_SUCCESS;
}
Variant
_ShaderProgramImpl::GetUniform(const Tizen::Base::String& name) const
{
-
+ return Variant();
}
result
{
if (name == UniformMVP)
{
- AppLog("\n jinstar : [%d] u_mvp %d", __program, __locationId[UNIFORM_MVP]);
return __locationId[UNIFORM_MVP];
}
else if (name == UniformColor)
{
- AppLog("\n jinstar : [%d] u_color %d", __program, __locationId[ATTRIBUTE_COLOR]);
return __locationId[ATTRIBUTE_COLOR];
}
{
if (name == AttributePosition)
{
- AppLog("\n jinstar : [%d] a_position %d", __program, __locationId[ATTRIBUTE_POSITION]);
return __locationId[ATTRIBUTE_POSITION];
}
else if (name == AttributeTexCoord)
{
- AppLog("\n jinstar : [%d] a_texcoord %d", __program, __locationId[ATTRIBUTE_TEXTURE_COORD]);
return __locationId[ATTRIBUTE_TEXTURE_COORD];
}
else if (name == AttributeColor)
{
- AppLog("\n jinstar : [%d] a_color %d", __program, __locationId[ATTRIBUTE_COLOR]);
return __locationId[ATTRIBUTE_COLOR];
}
return 0;//GetLocation(ATTRIBUTE_TYPE, name);
}
-#if 0
-int
-_ShaderProgramImpl::GetLocation(PROGRAM_LOCATION_TYPE type, const Tizen::Base::String& name)
-{
- int location = __locations.GetLocation(name);
-
- if (location < 0)
- {
- __request.name = name;
-
- switch(type)
- {
- case UNIFORM_TYPE:
- location = _GlRenderManager::GetInstance()->GetUniformLocation(this);
- break;
-
- case ATTRIBUTE_TYPE:
- location = _GlRenderManager::GetInstance()->GetAttribLocation(this);
- break;
- }
-
- __locations.Add(name, location);
- }
-
- AppLog("\n jinstar : [%d] %s %d", __program, name.GetPointer(), location);
-
- return location;
-}
-#endif
-
-void
-_ShaderProgramImpl::EnableVertexAttribArray(int location)
-{
- SysTryReturnVoidResult(NID_UI_ANIM, location >= 0, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. location = %d", location);
-
- __request.location = location;
-
- _GlRenderManager::GetInstance()->EnableVertexAttribArray(this);
-}
-
-void
-_ShaderProgramImpl::DisableVertexAttibArray(int location)
-{
- SysTryReturnVoidResult(NID_UI_ANIM, location >= 0, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. location = %d", location);
-
- __request.location = location;
-
- _GlRenderManager::GetInstance()->DisableVertexAttribArray(this);
-}
-
-void
-_ShaderProgramImpl::SetUniform(int location, const Tizen::Ui::Variant& value)
-{
-
-}
-
-void
-_ShaderProgramImpl::SetVertexAttrib(int location, const Tizen::Ui::Variant& value)
-{
-
-}
-
_ShaderProgramImpl*
_ShaderProgramImpl::GetInstance(ShaderProgram& program)
{
int GetUniformLocation(const Tizen::Base::String& name);
int GetAttribLocation(const Tizen::Base::String& name);
- void EnableVertexAttribArray(int location);
- void DisableVertexAttibArray(int location);
-
- void SetUniform(int location, const Tizen::Ui::Variant& value);
- void SetVertexAttrib(int location, const Tizen::Ui::Variant& value);
-
static _ShaderProgramImpl* GetInstance(ShaderProgram& program);
static const _ShaderProgramImpl* GetInstance(const ShaderProgram& program);