update GlesCanvasTexture sample
authorSukwon Suh <sukwon.suh@samsung.com>
Tue, 11 Jun 2013 02:25:53 +0000 (11:25 +0900)
committerSukwon Suh <sukwon.suh@samsung.com>
Tue, 11 Jun 2013 03:00:44 +0000 (12:00 +0900)
Change-Id: I034568c004fc2b9dc6d5af78d860178b370e6cb0
Signed-off-by: Sukwon Suh <sukwon.suh@samsung.com>
project/inc/GlesCanvasTexture.h
project/src/GlesCanvasTexture.cpp

index 8240628..c190ca7 100644 (file)
@@ -114,7 +114,6 @@ private:
 
        Tizen::Graphics::Opengl::GLuint         __textureId;
        Tizen::Graphics::Opengl::CanvasTexture* __pCanvasTexture;
-       Tizen::Graphics::Canvas*                __pCanvas;
        Tizen::Graphics::Font*                  __pFont;
        bool                                    __needUpdateTexture;
 
index 65cee3f..1c92332 100644 (file)
@@ -151,10 +151,10 @@ const GLshort INDICES[] =
 const int numIndices = 12;
 
 GlesCanvasTexture::GlesCanvasTexture(void)
-       : __eglDisplay(EGL_DEFAULT_DISPLAY)
+       : __eglDisplay(EGL_NO_DISPLAY)
        , __eglSurface(EGL_NO_SURFACE)
        , __eglConfig(null)
-       , __eglContext(EGL_NO_DISPLAY)
+       , __eglContext(EGL_NO_CONTEXT)
        , __programObject(0)
        , __indexPosition(0)
        , __indexTexture(0)
@@ -165,7 +165,6 @@ GlesCanvasTexture::GlesCanvasTexture(void)
        , __pForm(null)
        , __textureId(0)
        , __pCanvasTexture(null)
-       , __pCanvas(null)
        , __pFont(null)
        , __needUpdateTexture(false)
        , __drawCount(0)
@@ -350,9 +349,9 @@ GlesCanvasTexture::InitEGL(void)
 
        EGLint eglConfigList[] =
        {
-               EGL_RED_SIZE,   5,
-               EGL_GREEN_SIZE, 6,
-               EGL_BLUE_SIZE,  5,
+               EGL_RED_SIZE,   8,
+               EGL_GREEN_SIZE, 8,
+               EGL_BLUE_SIZE,  8,
                EGL_ALPHA_SIZE, 0,
                EGL_DEPTH_SIZE, 8,
                EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
@@ -368,11 +367,6 @@ GlesCanvasTexture::InitEGL(void)
 
        eglBindAPI(EGL_OPENGL_ES_API);
 
-       if (__eglDisplay)
-       {
-               DestroyGL();
-       }
-
        __eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
        TryCatch(__eglDisplay != EGL_NO_DISPLAY, , "eglGetDisplay() failed.");
 
@@ -488,6 +482,7 @@ GlesCanvasTexture::InitCanvasTexture(void)
 {
        result r = E_SUCCESS;
        Rectangle rect = __pForm->GetBounds();
+       Canvas* pCanvas = null;
 
        glGenTextures(1, &__textureId);
        glBindTexture(GL_TEXTURE_2D, __textureId);
@@ -502,9 +497,9 @@ GlesCanvasTexture::InitCanvasTexture(void)
        r = __pCanvasTexture->Construct(__textureId, rect.width, rect.height);
        TryCatch(!IsFailed(r),  , "__pCanvasTexture->Construct() failed.");
 
-       __pCanvas = __pCanvasTexture->GetCanvasN();
+       pCanvas = __pCanvasTexture->GetCanvasN();
        r = GetLastResult();
-       TryCatch(__pCanvas != null && !IsFailed(r),  , "__pCanvasTexture->GetCanvasN() failed. %s", GetErrorMessage(r));
+       TryCatch(pCanvas != null && !IsFailed(r),  , "__pCanvasTexture->GetCanvasN() failed. %s", GetErrorMessage(r));
 
        __pFont = new (std::nothrow) Font;
        TryCatch(__pFont != null, , "Allocation of __pFont failed.");
@@ -512,15 +507,17 @@ GlesCanvasTexture::InitCanvasTexture(void)
        r = __pFont->Construct(FONT_STYLE_BOLD, rect.width / 10);
        TryCatch(!IsFailed(r),  , "__pFont.Construct() failed. %s", GetErrorMessage(r));
 
-       __pCanvas->SetFont(*__pFont);
-       __pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
-       __pCanvas->Clear();
+       pCanvas->SetFont(*__pFont);
+       pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
+       pCanvas->Clear();
        DrawText(L"Touch the screen");
-       __pCanvas->Show();
+       pCanvas->Show();
+       delete pCanvas;
 
        return true;
 
 CATCH:
+       delete pCanvas;
        DestroyCanvasTexture();
 
        return false;
@@ -565,7 +562,6 @@ GlesCanvasTexture::DestroyCanvasTexture(void)
                glDeleteTextures(1, &__textureId);
        }
 
-       delete __pCanvas;
        delete __pCanvasTexture;
        delete __pFont;
 }
@@ -627,7 +623,15 @@ GlesCanvasTexture::Draw(void)
        if (__needUpdateTexture)
        {
                __needUpdateTexture = false;
-               __pCanvas->Show();
+               if (__pCanvasTexture != null)
+               {
+                       Canvas* pCanvas = __pCanvasTexture->GetCanvasN();
+                       if (pCanvas != null)
+                       {
+                               pCanvas->Show();
+                               delete pCanvas;
+                       }
+               }
                __drawCount = 0;
        }
 
@@ -762,27 +766,43 @@ GlesCanvasTexture::Rotate(FloatMatrix4* pResult, float angle, float x, float y,
 void
 GlesCanvasTexture::DrawText(Tizen::Base::String string)
 {
-       Rectangle rect = __pCanvas->GetBounds();
-       Dimension dimension;
-       __pCanvas->SetFont(*__pFont);
-       __pFont->GetTextExtent(string, string.GetLength(), dimension);
-       __pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
-       __pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK));
-       __pCanvas->DrawText(Point((rect.width - dimension.width) / 2 + 3, rect.height / 2 + 3), string, Color::GetColor(COLOR_ID_BLACK));
-       __pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
-       __pCanvas->DrawText(Point((rect.width - dimension.width) / 2 , rect.height / 2), string, Color::GetColor(COLOR_ID_BLACK));
+       if (__pCanvasTexture != null)
+       {
+               Canvas* pCanvas = __pCanvasTexture->GetCanvasN();
+               if (pCanvas != null)
+               {
+                       Rectangle rect = pCanvas->GetBounds();
+                       Dimension dimension;
+                       pCanvas->SetFont(*__pFont);
+                       __pFont->GetTextExtent(string, string.GetLength(), dimension);
+                       pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
+                       pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK));
+                       pCanvas->DrawText(Point((rect.width - dimension.width) / 2 + 3, rect.height / 2 + 3), string, Color::GetColor(COLOR_ID_BLACK));
+                       pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
+                       pCanvas->DrawText(Point((rect.width - dimension.width) / 2 , rect.height / 2), string, Color::GetColor(COLOR_ID_BLACK));
+                       delete pCanvas;
+               }
+       }
 }
 
 void
 GlesCanvasTexture::DrawEllipse(Point position, Color color)
 {
-       if (__pCanvas != null && __drawCount < MAX_DRAW_COUNT)
+       if (__drawCount < MAX_DRAW_COUNT)
        {
-               int size = 10 + Math::Rand() % 40;
-               Rectangle rect(position.x - size, position.y -size, size * 2, size * 2);
-               __pCanvas->FillEllipse(color, rect);
-               DrawText(L"Touch the screen");
-               __needUpdateTexture = true;
-               __drawCount++;
+               if (__pCanvasTexture != null)
+               {
+                       Canvas* pCanvas = __pCanvasTexture->GetCanvasN();
+                       if (pCanvas != null)
+                       {
+                               int size = 10 + Math::Rand() % 40;
+                               Rectangle rect(position.x - size, position.y -size, size * 2, size * 2);
+                               pCanvas->FillEllipse(color, rect);
+                               DrawText(L"Touch the screen");
+                               __needUpdateTexture = true;
+                               __drawCount++;
+                               delete pCanvas;
+                       }
+               }
        }
 }