[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / gl-call-debug.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // HEADER
19 #include <dali/internal/render/gl-resources/gl-call-debug.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/integration-api/gl-abstraction.h>
25 #include <dali/integration-api/gl-defines.h>
26
27 namespace
28 {
29 /**
30  * GL error strings
31  */
32 struct errorStrings
33 {
34   const Dali::GLenum errorCode;
35   const char* errorString;
36 };
37 errorStrings errors[] =
38 {
39    { GL_NO_ERROR,           "GL_NO_ERROR" },
40    { GL_INVALID_ENUM,       "GL_INVALID_ENUM" },
41    { GL_INVALID_VALUE,      "GL_INVALID_VALUE" },
42    { GL_INVALID_OPERATION,  "GL_INVALID_OPERATION" },
43    { GL_OUT_OF_MEMORY,      "GL_OUT_OF_MEMORY" }
44 };
45
46 const char* ErrorToString( Dali::GLenum errorCode )
47 {
48   for( unsigned int i = 0; i < sizeof(errors) / sizeof(errors[0]); ++i)
49   {
50     if (errorCode == errors[i].errorCode)
51     {
52       return errors[i].errorString;
53     }
54   }
55   return "Unknown Open GLES error";
56 }
57
58 }
59
60 namespace Dali
61 {
62
63 namespace Internal
64 {
65
66 #ifdef DEBUG_ENABLED
67 /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
68 Debug::Filter* gGlLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_CONTEXT");
69 #endif // DEBUG_ENABLED
70
71 void CheckGlError( Integration::GlAbstraction& glAbstraction, const char* operation )
72 {
73   bool foundError = false;
74   while( GLint error = glAbstraction.GetError() )
75   {
76     DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n",  error, ErrorToString( error ), operation );
77     foundError = true;
78   }
79   DALI_ASSERT_ALWAYS( !foundError && "GL ERROR" ); // if errors are being checked we should assert
80 }
81
82 }
83
84 }