|
1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and /or associated documentation files |
|
5 * (the "Materials "), to deal in the Materials without restriction, |
|
6 * including without limitation the rights to use, copy, modify, merge, |
|
7 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
8 * and to permit persons to whom the Materials are furnished to do so, |
|
9 * subject to the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
20 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 * |
|
22 * Initial Contributors: |
|
23 * Nokia Corporation - initial contribution. |
|
24 * |
|
25 * Contributors: |
|
26 * |
|
27 * Description: |
|
28 * |
|
29 */ |
|
30 |
|
31 #ifndef _GLINTERNAL_H_ |
|
32 #define _GLINTERNAL_H_ |
|
33 |
|
34 #include "glesOS.h" |
|
35 #include <GLES/gl.h> |
|
36 #include <new> |
|
37 |
|
38 #define X_TO_D(x) ((x) / 65536.0) |
|
39 #define X_TO_F(x) ((x) / 65536.0f) |
|
40 #define D_TO_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ |
|
41 (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ |
|
42 ((GLfixed) ((d) * 65536))) |
|
43 #define F_TO_X(f) D_TO_X(f) |
|
44 #define F_TO_D(f) ((double) (f)) |
|
45 #define I_TO_X(i) ((GLfixed) ((i) * 65536)) |
|
46 #define X_TO_I(x) ((x) / 65536) |
|
47 |
|
48 #include <assert.h> |
|
49 |
|
50 #if defined(_DEBUG) |
|
51 #define GLES_ASSERT assert |
|
52 #else // defined(_DEBUG) |
|
53 #define GLES_ASSERT |
|
54 #endif // !defined(_DEBUG) |
|
55 |
|
56 #define GLES_NEW new(std::nothrow) |
|
57 |
|
58 // Types not in OpenGL ES |
|
59 typedef double GLdouble; |
|
60 typedef double GLclampd; |
|
61 |
|
62 // Definitions not in OpenGL ES |
|
63 #define GL_POINT_SIZE_ARRAY 0x8B9C |
|
64 #define GL_POINT_SPRITE 0x8861 |
|
65 #define GL_COORD_REPLACE 0x8862 |
|
66 #define GL_BGR 0x80E0 |
|
67 #define GL_BGRA 0x80E1 |
|
68 #define GL_RGB8 0x8051 |
|
69 #define GL_RGBA8 0x8058 |
|
70 #ifndef GLES_NO_SRGB |
|
71 #define GL_SRGB8 0x8C41 |
|
72 #define GL_SRGB8_ALPHA8 0x8C43 |
|
73 #define GL_SLUMINANCE8 0x8C47 |
|
74 #else |
|
75 // No sRGB support in OpenGL 2.0. |
|
76 #define GL_SRGB8 GL_RGB8 |
|
77 #define GL_SRGB8_ALPHA8 GL_RGBA8 |
|
78 #define GL_SLUMINANCE8 GL_LUMINANCE8 |
|
79 #endif |
|
80 #define GL_LUMINANCE8 0x8040 |
|
81 #define GL_ALPHA8 0x803C |
|
82 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 |
|
83 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 |
|
84 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 |
|
85 |
|
86 #define GLES_API_CALL GL_API |
|
87 |
|
88 #define GLES_MIN(A, B) (A < B ? A : B) |
|
89 #define GLES_MAX(A, B) (A > B ? A : B) |
|
90 |
|
91 #define GLES_NO_RETVAL ; |
|
92 |
|
93 // Surface locking |
|
94 #define GLES_LOCK_SURFACE_RET(READ, DRAW, RETVAL) \ |
|
95 do \ |
|
96 { \ |
|
97 if(!EGLtoGLESInterface::GetEGLInterface()->LockGLESSurface(READ, DRAW)) \ |
|
98 { \ |
|
99 GLES_LEAVE_NO_ERROR_CHECK_RET(RETVAL); \ |
|
100 } \ |
|
101 } while(0) |
|
102 |
|
103 #define GLES_LOCK_SURFACE(READ, DRAW) GLES_LOCK_SURFACE_RET(READ, DRAW, GLES_NO_RETVAL) |
|
104 |
|
105 #define GLES_LOCK_DRAW_SURFACE_RET(RETVAL) GLES_LOCK_SURFACE_RET(false, true, RETVAL) |
|
106 #define GLES_LOCK_READ_SURFACE_RET(RETVAL) GLES_LOCK_SURFACE_RET(true, false, RETVAL) |
|
107 #define GLES_LOCK_DRAW_SURFACE() GLES_LOCK_SURFACE_RET(false, true, GLES_NO_RETVAL) |
|
108 #define GLES_LOCK_READ_SURFACE() GLES_LOCK_SURFACE_RET(true, false, GLES_NO_RETVAL) |
|
109 |
|
110 #define GLES_UNLOCK_SURFACE_RET(RETVAL) \ |
|
111 do \ |
|
112 { \ |
|
113 if(!EGLtoGLESInterface::GetEGLInterface()->UnlockGLESSurface()) \ |
|
114 { \ |
|
115 GLES_LEAVE_RET(RETVAL); \ |
|
116 } \ |
|
117 } while(0) |
|
118 |
|
119 #define GLES_UNLOCK_SURFACE() GLES_UNLOCK_SURFACE_RET(GLES_NO_RETVAL) |
|
120 |
|
121 inline bool glesIsPowerOfTwo(int x) |
|
122 { |
|
123 return (x != 0) && ((x & (x - 1)) == 0); |
|
124 } |
|
125 |
|
126 inline int glesLog2(unsigned int x) |
|
127 { |
|
128 int r = 0; |
|
129 while(x >>= 1) |
|
130 { |
|
131 r++; |
|
132 } |
|
133 return r; |
|
134 } |
|
135 |
|
136 #endif // _GLINTERNAL_H_ |