#include "FUiAnim_DisplayManager.h"
#include "FUiAnim_VisualElementSurfaceManager.h"
-#ifndef BUILD_UI_CORE
+#include "FUiAnim_ShaderImpl.h"
+#include "FUiAnim_ShaderProgramImpl.h"
+
#ifndef VE_SIMULATOR
#include <X11/Xlib.h>
}
#endif
#endif
-#endif
using namespace Tizen::Graphics;
using namespace Tizen::Ui::Animations;
, __useBlend(false)
, __useStencil(false)
, __useDepthTest(false)
- , __texId(0)
+ , __textureId(0)
{
SysAssertf(nativeDisplay, "Invalid display");
_GlContext::~_GlContext(void)
{
-#ifndef BUILD_UI_CORE
-
#ifndef VE_USE_GL_MULTI_CONTEXT
if (__nativeDummyPixmap)
{
__display = EGL_NO_DISPLAY;
#endif
}
-#endif
PRINT("_GlContext:~_GlContext() \n");
}
}
#endif
-void
-_GlContext::UseShaderProgram(_GlShaderProgram* pShaderProgram)
-{
- if (__pCurrentShader == pShaderProgram)
- return;
-
- if (__pCurrentShader)
- {
- __pCurrentShader->OnProgramDereferenced();
- __pCurrentShader = null;
- }
-
- // TODO: Reference Counting !!!
- if (pShaderProgram)
- {
- __pCurrentShader = pShaderProgram;
- __pCurrentShader->OnProgramReferenced();
-
- glUseProgram(__pCurrentShader->GetProgram());
- }
- else
- {
- glUseProgram(0);
- }
-}
-
#ifdef VE_USE_GL_MULTI_CONTEXT
bool
_GlContext::MakeCurrent(void)
bool
_GlContext::CreateDefaultSurface(void)
{
-#ifndef BUILD_UI_CORE
if (__dummySurface != EGL_NO_SURFACE)
{
return true;
}
return true;
-#endif
}
#endif
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
-GLuint
-_GlContext::GenTexture(void) const
-{
- GLuint textureId = 0;
-
- glGenTextures(1, &textureId);
- SysAssertf(textureId, "failed to glGenTexture.");
-
- return textureId;
-}
-
bool
_GlContext::CreateTexture(TextureInfo* pTextureInfo)
{
glBindTexture(GL_TEXTURE_2D, textureId);
- __texId = textureId;
+ __textureId = textureId;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
else
#endif
{
- if (IsSupportedBGRA())
+ GLenum format, type;
+
+ switch ( pTextureInfo->bitsPerPixel )
{
+ case 8:
+ format = GL_ALPHA;
+ type = GL_UNSIGNED_BYTE;
+ break;
+
+ case 16:
+ format = GL_RGB;
+ type = GL_UNSIGNED_SHORT_5_6_5;
+ break;
+
+ case 32:
+ if (IsSupportedBGRA())
+ {
#if defined(_OSP_EMUL_)
- glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, pTextureInfo->width, pTextureInfo->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pTextureInfo->pPixels);
+ format = GL_BGRA;
#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, pTextureInfo->width, pTextureInfo->height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pTextureInfo->pPixels);
+ format = GL_BGRA_EXT;
#endif
+ }
+ else
+ {
+ format = GL_RGBA;
+ }
+ type = GL_UNSIGNED_BYTE;
+ break;
+
+ default:
+ format = GL_RGB;
+ type = GL_UNSIGNED_BYTE;
+ break;
}
- else
- {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pTextureInfo->width, pTextureInfo->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTextureInfo->pPixels);
- }
- //TODO: exception handling
+
+ glTexImage2D(GL_TEXTURE_2D, 0, format, pTextureInfo->width, pTextureInfo->height, 0, format, type, pTextureInfo->pPixels);
}
pTextureInfo->textureId = textureId;
return true;
}
+//TODO: why?? pSurfaceInfo
+void
+_GlContext::UploadTexture(GlVisualElementSurfaceInfo* pSurfaceInfo)
+{
+// if (pSurfaceInfo->type == SURFACE_TYPE_STATIC && pSurfaceInfo->updated) // TODO: enable
+ if (pSurfaceInfo->type == SURFACE_TYPE_STATIC)
+ {
+ if (IsSupportedBGRA())
+ {
+#if defined(_OSP_EMUL_)
+ glTexSubImage2D(GL_TEXTURE_2D, 0, pSurfaceInfo->x, pSurfaceInfo->y, pSurfaceInfo->width, pSurfaceInfo->height, GL_BGRA, GL_UNSIGNED_BYTE, pSurfaceInfo->pPixels);
+#else
+ glTexSubImage2D(GL_TEXTURE_2D, 0, pSurfaceInfo->x, pSurfaceInfo->y, pSurfaceInfo->width, pSurfaceInfo->height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pSurfaceInfo->pPixels);
+#endif
+ }
+ else
+ {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, pSurfaceInfo->x, pSurfaceInfo->y, pSurfaceInfo->width, pSurfaceInfo->height, GL_RGBA, GL_UNSIGNED_BYTE, pSurfaceInfo->pPixels);
+ }
+
+ pSurfaceInfo->updated = false;
+ }
+}
+
void
_GlContext::DeleteTexture(TextureInfo *pTextureInfo)
{
-#ifndef BUILD_UI_CORE
glDeleteTextures(1, &pTextureInfo->textureId);
// TODO: remove hashmap
delete pPixmapInfo;
}
#endif
-#endif
-}
-
-void
-_GlContext::UploadTexture(GlVisualElementSurfaceInfo* pSurfaceInfo)
-{
-// if (pSurfaceInfo->type == SURFACE_TYPE_STATIC && pSurfaceInfo->updated) // TODO: enable
- if (pSurfaceInfo->type == SURFACE_TYPE_STATIC)
- {
- if (IsSupportedBGRA())
- {
-#if defined(_OSP_EMUL_)
- glTexSubImage2D(GL_TEXTURE_2D, 0, pSurfaceInfo->x, pSurfaceInfo->y, pSurfaceInfo->width, pSurfaceInfo->height, GL_BGRA, GL_UNSIGNED_BYTE, pSurfaceInfo->pPixels);
-#else
- glTexSubImage2D(GL_TEXTURE_2D, 0, pSurfaceInfo->x, pSurfaceInfo->y, pSurfaceInfo->width, pSurfaceInfo->height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pSurfaceInfo->pPixels);
-#endif
- }
- else
- {
- glTexSubImage2D(GL_TEXTURE_2D, 0, pSurfaceInfo->x, pSurfaceInfo->y, pSurfaceInfo->width, pSurfaceInfo->height, GL_RGBA, GL_UNSIGNED_BYTE, pSurfaceInfo->pPixels);
- }
-
- pSurfaceInfo->updated = false;
- }
}
_GlContext::_PixmapInfo*
_GlContext::CreateNativePixmap(BufferInfo& bufferInfo)
{
-#ifndef BUILD_UI_CORE
#ifndef VE_SIMULATOR
_PixmapInfo* pPixmapInfo = null;
SysLog(NID_UI_ANIM, "CreateNativePixmap failed!!");
#endif
#endif
-#endif
return null;
}
}
void
-_GlContext::LoadTexture(void* pBits, GLenum target, int w, int h, int bpp)
+_GlContext::UseShaderProgram(_GlShaderProgram* pShaderProgram)
{
- int level = 0;
- GLenum texParamTarget = GL_TEXTURE_2D;
-
- switch ( target )
- {
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- texParamTarget = GL_TEXTURE_CUBE_MAP;
- break;
+ if (__pCurrentShader == pShaderProgram)
+ {
+ return;
+ }
+
+ if (__pCurrentShader)
+ {
+ __pCurrentShader->OnProgramDereferenced();
+ __pCurrentShader = null;
+ }
+
+ // TODO: Reference Counting !!!
+ if (pShaderProgram)
+ {
+ __pCurrentShader = pShaderProgram;
+ __pCurrentShader->OnProgramReferenced();
+
+ glUseProgram(__pCurrentShader->GetProgram());
+ }
+ else
+ {
+ glUseProgram(0);
+ }
+}
+
+void
+_GlContext::UseShaderProgram(ShaderProgram* pShaderProgram)
+{
+// if (__pCurrentShader == pShaderProgram)
+// {
+// return;
+// }
+
+ if (__pCurrentShader)
+ {
+ __pCurrentShader->OnProgramDereferenced();
+ __pCurrentShader = null;
+ }
+
+ // TODO: Reference Counting !!!
+ if (pShaderProgram)
+ {
+// __pCurrentShader = pShaderProgram;
+// __pCurrentShader->OnProgramReferenced();
+
+ unsigned int program = _ShaderProgramImpl::GetInstance(*pShaderProgram)->__program;
+ AppLog("\n jinstar -- use program %d", program);
+ glUseProgram(program);
+ }
+ else
+ {
+ glUseProgram(0);
+ }
+}
+GLuint
+_GlContext::BuildShader(GLuint type, const char* pShaderSource)
+{
+ switch(type)
+ {
+ case Shader::SHADER_VERTEX:
+ type = GL_VERTEX_SHADER;
+ break;
+ case Shader::SHADER_FRAGMENT:
+ type = GL_FRAGMENT_SHADER;
+ break;
default:
- texParamTarget = target;
+ break;
+// return 0;
};
- glTexParameteri(texParamTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(texParamTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(texParamTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(texParamTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER)
+ return 0;
- if (pBits)
+#ifndef VE_USE_GL_MULTI_CONTEXT
+ CHECK_GL_CONTEXT();
+#endif
+
+ GLuint shaderId = glCreateShader(type);
+ if (shaderId == 0)
{
- GLenum format, type;
+ return 0;
+ }
+
+ GLint status;
- switch ( bpp )
+ glShaderSource(shaderId, 1, &pShaderSource, NULL);
+ glCompileShader(shaderId);
+ glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status);
+ if (!status)
+ {
+ GLint infoLen = 0;
+ glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &infoLen);
+ if (infoLen > 1)
{
- case 16:
- format = GL_RGB;
- type = GL_UNSIGNED_SHORT_5_6_5;
- break;
+ char* infoLog = (char*)malloc(sizeof(char) * infoLen);
+ glGetShaderInfoLog(shaderId, infoLen, NULL, infoLog);
+ SysLog(NID_UI_ANIM, "Failed to compile shader - %s", infoLog);
+ free(infoLog);
+ }
- case 32:
- format = GL_RGBA;
- type = GL_UNSIGNED_BYTE;
- break;
+ glDeleteShader(shaderId);
+ return 0;
+ }
- default:
- format = GL_RGB;
- type = GL_UNSIGNED_BYTE;
- break;
+ //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;
+ }
+
+ GLuint programId = glCreateProgram();
+
+ glAttachShader(programId, vertexShader);
+ glAttachShader(programId, fragmentShader);
+
+ GLint linked;
+ glLinkProgram(programId);
+ glGetProgramiv(programId, GL_LINK_STATUS, &linked);
+ if (!linked)
+ {
+ GLint infoLen = 0;
+ glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &infoLen);
+ if (infoLen >1)
+ {
+ char* infoLog = (char*)malloc(sizeof(char) * infoLen);
+ glGetShaderInfoLog(programId, infoLen, NULL, infoLog);
+ SysLog(NID_UI_ANIM, "Failed to link shader program- %s", infoLog);
+ free(infoLog);
}
- glTexImage2D(target, level, format, w, h, 0, format, type, pBits);
+ glDeleteProgram(programId);
+ 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);
}
+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);
+}
+
+
+void
+_GlContext::EnableVertexAttribArray(GLuint program, int index)
+{
+ glUseProgram(program);
+
+ glEnableVertexAttribArray(index);
+
+ AppLog("\n jinstar -- EnableVertexAttribArray %d %d [error:%d]", program, index, glGetError());
+ //TODO: Need to return glGetError()
+}
+
+void
+_GlContext::DisableVertexAttribArray(GLuint program, int index)
+{
+ glUseProgram(program);
+
+ glDisableVertexAttribArray(index);
+
+ AppLog("\n jinstar -- EnableVertexAttribArray %d %d [error:%d]", program, index, glGetError());
+}
+
+
}}} // Tizen::Ui::Animations