author | Matt Plumtree <matt.plumtree@nokia.com> |
Fri, 12 Nov 2010 17:56:05 +0000 | |
branch | bug235_bringup_0 |
changeset 76 | 24381b61de5c |
parent 55 | 09263774e342 |
permissions | -rw-r--r-- |
24 | 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 associated documentation files (the "Software"), |
|
5 |
* to deal in the Software without restriction, including without limitation |
|
6 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
7 |
* and/or sell copies of the Software, and to permit persons to whom the |
|
8 |
* Software is furnished to do so, subject to the following conditions: |
|
9 |
* |
|
10 |
* The above copyright notice and this permission notice shall be included |
|
11 |
* in all copies or substantial portions of the Software. |
|
12 |
* |
|
13 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
14 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
15 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
16 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
|
17 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
18 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
19 |
* |
|
20 |
* Initial Contributors: |
|
21 |
* Nokia Corporation - initial contribution. |
|
22 |
* |
|
23 |
* Contributors: |
|
24 |
* |
|
25 |
* Description: |
|
26 |
* |
|
27 |
*/ |
|
28 |
||
29 |
#include "degl.h" |
|
30 |
#include "context.h" |
|
31 |
#include "ColorDescriptor.h" |
|
32 |
#include "ImageTarget.h" |
|
33 |
||
34 |
void* deglGetHostProcAddress(char const* proc) |
|
35 |
{ |
|
36 |
return EGLtoGLES2Interface::GetEGLInterface()->GetHostProcAddress(proc); |
|
37 |
} |
|
38 |
||
39 |
DGLContext* deglGetCurrentContext(void) |
|
40 |
{ |
|
41 |
DGLContext* ctx = static_cast<DGLContext*>(EGLtoGLES2Interface::GetEGLInterface()->GetGLESContext()); |
|
42 |
return ctx; |
|
43 |
} |
|
44 |
||
45 |
int deglLockSurface(int read, int draw) |
|
46 |
{ |
|
47 |
return EGLtoGLES2Interface::GetEGLInterface()->LockGLESSurface(!!read, !!draw); |
|
48 |
} |
|
49 |
||
50 |
int deglUnlockSurface(void) |
|
51 |
{ |
|
52 |
return EGLtoGLES2Interface::GetEGLInterface()->UnlockGLESSurface(); |
|
53 |
} |
|
54 |
||
55 |
static EImageTarget dglGLenumToImageTarget(GLenum target) |
|
56 |
{ |
|
57 |
switch(target) |
|
58 |
{ |
|
59 |
case GL_TEXTURE_2D: |
|
60 |
return IMAGE_TARGET_TEXTURE_2D; |
|
61 |
case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
|
62 |
return IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_X; |
|
63 |
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
|
64 |
return IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_X; |
|
65 |
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
|
66 |
return IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_Y; |
|
67 |
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
|
68 |
return IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_Y; |
|
69 |
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
|
70 |
return IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_Z; |
|
71 |
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
|
72 |
return IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_Z; |
|
73 |
case GL_RENDERBUFFER: |
|
74 |
return IMAGE_TARGET_RENDERBUFFER; |
|
75 |
default: |
|
76 |
DGLES2_ASSERT(false); |
|
77 |
} |
|
78 |
||
79 |
// Not reached. |
|
80 |
return (EImageTarget)-1; |
|
81 |
} |
|
82 |
||
83 |
void deglRegisterImageTarget(GLeglImageOES image, GLenum target, GLuint name) |
|
84 |
{ |
|
85 |
EGLtoGLES2Interface::GetEGLInterface()->RegisterImageTarget(image, dglGLenumToImageTarget(target), (void*)name); |
|
86 |
} |
|
87 |
||
88 |
void deglUnregisterImageTarget(GLeglImageOES image, GLenum target, GLuint name) |
|
89 |
{ |
|
90 |
EGLtoGLES2Interface::GetEGLInterface()->UnregisterImageTarget(image, dglGLenumToImageTarget(target), (void*)name); |
|
91 |
} |
|
92 |
||
93 |
void deglUpdateImageSiblings(GLeglImageOES image, GLenum target, GLuint name) |
|
94 |
{ |
|
95 |
EGLtoGLES2Interface::GetEGLInterface()->UpdateImageSiblings(image, dglGLenumToImageTarget(target), (void*)name); |
|
96 |
} |
|
97 |
||
98 |
void deglReleaseTexImage(void* surface, int name, int level) |
|
99 |
{ |
|
100 |
EGLtoGLES2Interface::GetEGLInterface()->ReleaseTexImage(surface, name, level); |
|
101 |
} |
|
102 |
||
103 |
static SurfaceDescriptor dglCreateSurfaceDescriptor(int redBits, int redShift, int greenBits, int greenShift, int blueBits, int blueShift, int alphaBits, int alphaShift, int luminanceBits, int luminanceShift, CColorDescriptor::ColorFormat format, int bpp) |
|
104 |
{ |
|
105 |
SurfaceDescriptor desc; |
|
106 |
desc.m_colorDescriptor.m_redSize = redBits; |
|
107 |
desc.m_colorDescriptor.m_greenSize = greenBits; |
|
108 |
desc.m_colorDescriptor.m_blueSize = blueBits; |
|
109 |
desc.m_colorDescriptor.m_alphaSize = alphaBits; |
|
110 |
desc.m_colorDescriptor.m_luminanceSize = luminanceBits; |
|
111 |
desc.m_redShift = redShift; |
|
112 |
desc.m_greenShift = greenShift; |
|
113 |
desc.m_blueShift = blueShift; |
|
114 |
desc.m_alphaShift = alphaShift; |
|
115 |
desc.m_luminanceShift = luminanceShift; |
|
116 |
desc.m_colorDescriptor.m_format = format; |
|
117 |
desc.m_colorDescriptor.m_bpp = bpp; |
|
118 |
return desc; |
|
119 |
} |
|
120 |
||
121 |
typedef struct |
|
122 |
{ |
|
123 |
SurfaceDescriptor desc; |
|
124 |
GLenum internal_format; |
|
125 |
GLenum data_format; |
|
126 |
GLenum data_type; |
|
127 |
} DescToEnumMapping; |
|
128 |
||
129 |
static bool dglIsDescEqualToMapping(const SurfaceDescriptor& desc, const DescToEnumMapping& mapping) |
|
130 |
{ |
|
131 |
if ((desc.m_colorDescriptor.m_redSize == mapping.desc.m_colorDescriptor.m_redSize) && |
|
132 |
(desc.m_colorDescriptor.m_greenSize == mapping.desc.m_colorDescriptor.m_greenSize) && |
|
133 |
(desc.m_colorDescriptor.m_blueSize == mapping.desc.m_colorDescriptor.m_blueSize) && |
|
134 |
(desc.m_colorDescriptor.m_alphaSize == mapping.desc.m_colorDescriptor.m_alphaSize) && |
|
135 |
(desc.m_colorDescriptor.m_luminanceSize == mapping.desc.m_colorDescriptor.m_luminanceSize) && |
|
136 |
(desc.m_redShift == mapping.desc.m_redShift) && |
|
137 |
(desc.m_greenShift == mapping.desc.m_greenShift) && |
|
138 |
(desc.m_blueShift == mapping.desc.m_blueShift) && |
|
139 |
(desc.m_alphaShift == mapping.desc.m_alphaShift) && |
|
140 |
(desc.m_luminanceShift == mapping.desc.m_luminanceShift) && |
|
141 |
(desc.m_colorDescriptor.m_format == mapping.desc.m_colorDescriptor.m_format) && |
|
142 |
(desc.m_colorDescriptor.m_bpp == mapping.desc.m_colorDescriptor.m_bpp)) |
|
143 |
return true; |
|
144 |
||
145 |
return false; |
|
146 |
} |
|
147 |
||
148 |
static void dglSurfaceDescriptorToGLEnums(const SurfaceDescriptor& desc, GLenum& internal_format, GLenum& data_format, GLenum& data_type) |
|
149 |
{ |
|
150 |
static const DescToEnumMapping map[] = { |
|
151 |
/* RGB{A,X} channel ordering */ |
|
152 |
// sRGBX_8888 |
|
153 |
{dglCreateSurfaceDescriptor(8, 24, 8, 16, 8, 8, 0, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
154 |
// sRGBA_8888 |
|
155 |
{dglCreateSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
156 |
// sRGBA_8888_PRE |
|
157 |
{dglCreateSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::sRGBA_PRE, 32), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
158 |
// sRGB_565 |
|
159 |
{dglCreateSurfaceDescriptor(5, 11, 6, 5, 5, 0, 0, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, |
|
160 |
// sRGBA_5551 |
|
161 |
{dglCreateSurfaceDescriptor(5, 11, 5, 6, 5, 1, 1, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, |
|
162 |
// sRGBA_4444 |
|
163 |
{dglCreateSurfaceDescriptor(4, 12, 4, 8, 4, 4, 4, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4}, |
|
164 |
// sL_8 |
|
165 |
{dglCreateSurfaceDescriptor(0, 0, 0, 0, 0, 0, 0, 0, 8, 0, CColorDescriptor::sLA, 8), GL_SLUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
|
166 |
// lRGBX_8888 |
|
167 |
{dglCreateSurfaceDescriptor(8, 24, 8, 16, 8, 8, 0, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
168 |
// lRGBA_8888 |
|
169 |
{dglCreateSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
170 |
// lRGBA_8888_PRE |
|
171 |
{dglCreateSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::lRGBA_PRE, 32), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
172 |
// lL_8 |
|
173 |
{dglCreateSurfaceDescriptor(0, 0, 0, 0, 0, 0, 0, 0, 8, 0, CColorDescriptor::lLA, 8), GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
|
174 |
// A_8 |
|
175 |
{dglCreateSurfaceDescriptor(0, 0, 0, 0, 0, 0, 8, 0, 0, 0, CColorDescriptor::lRGBA, 8), GL_ALPHA8, GL_ALPHA, GL_UNSIGNED_BYTE}, |
|
176 |
// These should be converted to a compatible format by VG. |
|
177 |
/* |
|
178 |
// BW_1 |
|
179 |
{dglCreateSurfaceDescriptor(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, CColorDescriptor::lLA, 1), GL_NONE, GL_NONE, GL_NONE}, |
|
180 |
// A_1 |
|
181 |
{dglCreateSurfaceDescriptor(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, CColorDescriptor::lRGBA, 1), GL_NONE, GL_NONE, GL_NONE}, |
|
182 |
// A_4 |
|
183 |
{dglCreateSurfaceDescriptor(0, 0, 0, 0, 0, 0, 4, 0, 0, 0, CColorDescriptor::lRGBA, 4), GL_NONE, GL_NONE, GL_NONE}, |
|
184 |
*/ |
|
185 |
||
186 |
/* {A,X}RGB channel ordering */ |
|
187 |
// sXRGB_8888 |
|
188 |
{dglCreateSurfaceDescriptor(8, 16, 8, 8, 8, 0, 0, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
189 |
// sARGB_8888 |
|
190 |
{dglCreateSurfaceDescriptor(8, 16, 8, 8, 8, 0, 8, 24, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
191 |
// sARGB_8888_PRE |
|
192 |
{dglCreateSurfaceDescriptor(8, 16, 8, 8, 8, 0, 8, 24, 0, 0, CColorDescriptor::sRGBA_PRE, 32), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
193 |
// sARGB_1555 |
|
194 |
{dglCreateSurfaceDescriptor(5, 10, 5, 5, 5, 0, 1, 15, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, |
|
195 |
// sARGB_4444 |
|
196 |
{dglCreateSurfaceDescriptor(4, 8, 4, 4, 4, 0, 4, 12, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV}, |
|
197 |
// lXRGB_8888 |
|
198 |
{dglCreateSurfaceDescriptor(8, 16, 8, 8, 8, 0, 0, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGB8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
199 |
// lARGB_8888 |
|
200 |
{dglCreateSurfaceDescriptor(8, 16, 8, 8, 8, 0, 8, 24, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
201 |
// lARGB_8888_PRE |
|
202 |
{dglCreateSurfaceDescriptor(8, 16, 8, 8, 8, 0, 8, 24, 0, 0, CColorDescriptor::lRGBA_PRE, 32), GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
203 |
||
204 |
/* BGR{A,X} channel ordering */ |
|
205 |
// sBGRX_8888 |
|
206 |
{dglCreateSurfaceDescriptor(8, 8, 8, 16, 8, 24, 0, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
207 |
// sBGRA_8888 |
|
208 |
{dglCreateSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
209 |
// sBGRA_8888_PRE |
|
210 |
{dglCreateSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::sRGBA_PRE, 32), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
211 |
// sBGR_565 |
|
212 |
{dglCreateSurfaceDescriptor(5, 0, 6, 5, 5, 11, 0, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8, GL_BGR, GL_UNSIGNED_SHORT_5_6_5}, |
|
213 |
// sBGRA_5551 |
|
214 |
{dglCreateSurfaceDescriptor(5, 1, 5, 6, 5, 11, 1, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_SHORT_5_5_5_1}, |
|
215 |
// sBGRA_4444 |
|
216 |
{dglCreateSurfaceDescriptor(4, 4, 4, 8, 4, 12, 4, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4}, |
|
217 |
// lBGRX_8888 |
|
218 |
{dglCreateSurfaceDescriptor(8, 8, 8, 16, 8, 24, 0, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGB8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
219 |
// lBGRA_8888 |
|
220 |
{dglCreateSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
221 |
// lBGRA_8888_PRE |
|
222 |
{dglCreateSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::lRGBA_PRE, 32), GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
223 |
||
224 |
/* {A,X}BGR channel ordering */ |
|
225 |
// sXBGR_8888 |
|
226 |
{dglCreateSurfaceDescriptor(8, 0, 8, 8, 8, 16, 0, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
227 |
// sABGR_8888 |
|
228 |
{dglCreateSurfaceDescriptor(8, 0, 8, 8, 8, 16, 8, 24, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
229 |
// sABGR_8888_PRE |
|
230 |
{dglCreateSurfaceDescriptor(8, 0, 8, 8, 8, 16, 8, 24, 0, 0, CColorDescriptor::sRGBA_PRE, 32), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
231 |
// sABGR_1555 |
|
232 |
{dglCreateSurfaceDescriptor(5, 0, 5, 5, 5, 10, 1, 15, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, |
|
233 |
// sABGR_4444 |
|
234 |
{dglCreateSurfaceDescriptor(4, 0, 4, 4, 4, 8, 4, 12, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV}, |
|
235 |
// lXBGR_8888 |
|
236 |
{dglCreateSurfaceDescriptor(8, 0, 8, 8, 8, 16, 0, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGB8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
237 |
// lABGR_8888 |
|
238 |
{dglCreateSurfaceDescriptor(8, 0, 8, 8, 8, 16, 8, 24, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, |
|
239 |
// lABGR_8888_PRE: |
|
240 |
{dglCreateSurfaceDescriptor(8, 0, 8, 8, 8, 16, 8, 24, 0, 0, CColorDescriptor::lRGBA_PRE, 32), GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}}; |
|
241 |
||
242 |
for (size_t i = 0; i < sizeof(map)/sizeof(map[0]); i++) |
|
243 |
{ |
|
244 |
if (dglIsDescEqualToMapping(desc, map[i])) |
|
245 |
{ |
|
246 |
internal_format = map[i].internal_format; |
|
247 |
data_format = map[i].data_format; |
|
248 |
data_type = map[i].data_type; |
|
249 |
DGLES2_ASSERT(internal_format != GL_NONE && data_format != GL_NONE && data_type != GL_NONE); |
|
250 |
return; |
|
251 |
} |
|
252 |
} |
|
253 |
DGLES2_ASSERT(GL_FALSE); |
|
254 |
return; |
|
255 |
} |
|
256 |
||
257 |
void deglGetImageInfo(GLeglImageOES image, GLenum* internal_format, GLsizei* width, GLsizei* height, GLsizei* stride, GLenum* data_format, GLenum* data_type) |
|
258 |
{ |
|
259 |
DGLES2_ASSERT(image != NULL); |
|
260 |
DGLES2_ASSERT(internal_format != NULL); |
|
261 |
DGLES2_ASSERT(width != NULL); |
|
262 |
DGLES2_ASSERT(height != NULL); |
|
263 |
DGLES2_ASSERT(stride != NULL); |
|
264 |
DGLES2_ASSERT(data_format != NULL); |
|
265 |
DGLES2_ASSERT(data_type != NULL); |
|
266 |
||
267 |
SurfaceDescriptor desc; |
|
268 |
EGLtoGLES2Interface::GetEGLInterface()->GetDescForImage(image, desc); |
|
269 |
||
270 |
*width = desc.m_width; |
|
271 |
*height = desc.m_height; |
|
272 |
*stride = desc.m_stride; |
|
273 |
dglSurfaceDescriptorToGLEnums(desc, *internal_format, *data_format, *data_type); |
|
274 |
} |
|
275 |
||
276 |
void* deglGetImageData(GLeglImageOES image) |
|
277 |
{ |
|
278 |
DGLES2_ASSERT(image != NULL); |
|
279 |
return EGLtoGLES2Interface::GetEGLInterface()->GetDataForImage(image); |
|
280 |
} |
|
281 |
||
282 |
namespace |
|
283 |
{ |
|
284 |
EGLtoGLES2Interface g_EGLtoGLES2Interface; |
|
285 |
} |
|
286 |
||
287 |
IEGLtoGLES2Interface* getGLES2Interface(void) |
|
288 |
{ |
|
289 |
return &g_EGLtoGLES2Interface; |
|
290 |
} |
|
291 |
||
292 |
#include <new> |
|
293 |
||
294 |
EGLtoGLES2Interface::EGLtoGLES2Interface() : |
|
295 |
m_egl(NULL) |
|
296 |
{ |
|
297 |
} |
|
298 |
||
299 |
void EGLtoGLES2Interface::SetEGLInterface( IGLEStoEGLInterface* egl ) |
|
300 |
{ |
|
301 |
DGLES2_ASSERT(!m_egl); |
|
302 |
m_egl = egl; |
|
303 |
} |
|
304 |
||
305 |
void* EGLtoGLES2Interface::CreateContext(void* nativeContext) |
|
306 |
{ |
|
307 |
DGLContext* newContext = NULL; |
|
308 |
||
309 |
newContext = DGLContext_create(nativeContext); |
|
310 |
if(newContext == NULL) |
|
311 |
{ |
|
312 |
return NULL; |
|
313 |
} |
|
314 |
m_contexts.insert(newContext); |
|
315 |
return newContext; |
|
316 |
} |
|
317 |
||
318 |
bool EGLtoGLES2Interface::ReleaseContext(void* context) |
|
319 |
{ |
|
320 |
DGLES2_ASSERT(context != NULL); |
|
321 |
DGLContext* ctx = static_cast<DGLContext*>(context); |
|
322 |
if(m_contexts.find(ctx) == m_contexts.end()) |
|
323 |
{ |
|
324 |
return false; |
|
325 |
} |
|
326 |
||
327 |
DGLContext_destroy(ctx); |
|
328 |
m_contexts.erase(ctx); |
|
329 |
||
330 |
return true; |
|
331 |
} |
|
332 |
||
333 |
void* EGLtoGLES2Interface::GetNativeContext(void* context) |
|
334 |
{ |
|
335 |
DGLES2_ASSERT(context != NULL); |
|
336 |
DGLContext* ctx = static_cast<DGLContext*>(context); |
|
337 |
if(m_contexts.find(ctx) == m_contexts.end()) |
|
338 |
{ |
|
339 |
return false; |
|
340 |
} |
|
341 |
||
342 |
return ctx->native_context; |
|
343 |
} |
|
344 |
||
345 |
extern "C" |
|
346 |
{ |
|
347 |
GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); |
|
348 |
GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); |
|
349 |
} |
|
350 |
||
351 |
fpGLProc EGLtoGLES2Interface::GetGLProcAddress(const char *procname) |
|
352 |
{ |
|
353 |
if(strcmp(procname, "glEGLImageTargetTexture2DOES") == 0) |
|
354 |
{ |
|
355 |
return (fpGLProc)glEGLImageTargetTexture2DOES; |
|
356 |
} |
|
357 |
else if(strcmp(procname, "glEGLImageTargetRenderbufferStorageOES") == 0) |
|
358 |
{ |
|
359 |
return (fpGLProc)glEGLImageTargetRenderbufferStorageOES; |
|
360 |
} |
|
361 |
else |
|
362 |
{ |
|
363 |
return NULL; |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
int EGLtoGLES2Interface::BindTexImage( void* surface, int level, bool generate_mipmap, const SurfaceDescriptor* desc, void* buffer ) |
|
368 |
{ |
|
76
24381b61de5c
Host OpenGL ES 2.0 code now building without warning or error using GCC.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
55
diff
changeset
|
369 |
DGLES2_ENTER_RET(0); |
24 | 370 |
|
371 |
GLuint ret = 0; |
|
372 |
||
373 |
// Store the current error and clear the error flag. |
|
374 |
DGLContext_getHostError(ctx); |
|
375 |
||
376 |
if(level < 0) |
|
377 |
{ |
|
378 |
level = 0; |
|
379 |
} |
|
380 |
else if(level > ctx->max_texture_level) |
|
381 |
{ |
|
382 |
level = ctx->max_texture_level; |
|
383 |
} |
|
384 |
||
385 |
// Clear all mipmap levels. |
|
386 |
{ |
|
387 |
int i; |
|
388 |
for(i = 0; i < ctx->max_texture_level; i++) |
|
389 |
{ |
|
390 |
ctx->hgl.TexImage2D(GL_TEXTURE_2D, level, GL_RGBA, 0, 0, 0, |
|
391 |
GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
|
392 |
} |
|
393 |
} |
|
394 |
||
395 |
{ |
|
396 |
GLenum internal_format, data_format, data_type; |
|
397 |
dglSurfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); |
|
398 |
ctx->hgl.TexImage2D(GL_TEXTURE_2D, level, internal_format, desc->m_width, desc->m_height, 0, |
|
399 |
data_format, data_type, buffer); |
|
400 |
} |
|
401 |
||
402 |
if(generate_mipmap && level == 0) |
|
403 |
{ |
|
404 |
ctx->hgl.GenerateMipmapEXT(GL_TEXTURE_2D); |
|
405 |
} |
|
406 |
||
407 |
// Clear any possible error flag. |
|
408 |
if(ctx->hgl.GetError() == GL_NO_ERROR) |
|
409 |
{ |
|
410 |
DGLTexture* texture; |
|
411 |
GLeglImageOES image; |
|
412 |
||
413 |
texture = DGLContext_findTexture(ctx, ctx->texture_binding_2d); |
|
414 |
DGLES2_ASSERT(texture != NULL); |
|
415 |
DGLTexture_setLevel(texture, GL_TEXTURE_2D, level, GL_RGBA, desc->m_width, desc->m_height); |
|
416 |
||
417 |
if(generate_mipmap && level == 0) |
|
418 |
{ |
|
419 |
DGLTexture_generateMipmap(texture); |
|
420 |
} |
|
421 |
||
422 |
image = DGLTexture_getEGLImage(texture, GL_TEXTURE_2D); |
|
423 |
if(image != NULL) |
|
424 |
{ |
|
425 |
// Texture is respecified. It is no longer an EGLImage sibling. |
|
426 |
deglUnregisterImageTarget(image, GL_TEXTURE_2D, texture->obj.name); |
|
427 |
DGLTexture_setEGLImage(texture, GL_TEXTURE_2D, NULL); |
|
428 |
} |
|
429 |
||
430 |
{ |
|
431 |
DGLTextureLevel* level_obj = DGLTexture_getLevel(texture, GL_TEXTURE_2D, level); |
|
432 |
if(level_obj->bound_surface != NULL) |
|
433 |
{ |
|
434 |
// Texture is respecified. Release the bound EGLSurface. |
|
435 |
deglReleaseTexImage(level_obj->bound_surface, texture->obj.name, level); |
|
436 |
} |
|
437 |
level_obj->bound_surface = surface; |
|
438 |
} |
|
439 |
||
440 |
ret = texture->obj.name; |
|
441 |
} |
|
442 |
||
443 |
DGLES2_LEAVE_NO_ERROR_CHECK_RET(ret); |
|
444 |
} |
|
445 |
||
446 |
bool EGLtoGLES2Interface::ReleaseTexImage( int name, int level ) |
|
447 |
{ |
|
448 |
DGLES2_ENTER_RET(false); |
|
449 |
||
450 |
DGLContext_getHostError(ctx); |
|
451 |
||
452 |
GLuint binding; |
|
453 |
ctx->hgl.GetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&binding); |
|
454 |
ctx->hgl.BindTexture(GL_TEXTURE_2D, (GLuint)name); |
|
455 |
ctx->hgl.TexImage2D(GL_TEXTURE_2D, level, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
|
456 |
ctx->hgl.BindTexture(GL_TEXTURE_2D, binding); |
|
457 |
||
458 |
bool ret = false; |
|
459 |
||
460 |
if(ctx->hgl.GetError() == GL_NO_ERROR) |
|
461 |
{ |
|
462 |
DGLTexture* texture; |
|
463 |
DGLTextureLevel* level_obj; |
|
464 |
||
465 |
texture = DGLContext_findTexture(ctx, name); |
|
466 |
level_obj = DGLTexture_getLevel(texture, GL_TEXTURE_2D, level); |
|
467 |
level_obj->bound_surface = NULL; |
|
468 |
||
469 |
ret = true; |
|
470 |
} |
|
471 |
||
472 |
DGLES2_LEAVE_NO_ERROR_CHECK_RET(ret); |
|
473 |
} |
|
474 |
||
475 |
static GLenum dglImageTargetToGLenum(EImageTarget target) |
|
476 |
{ |
|
477 |
switch(target) |
|
478 |
{ |
|
479 |
case IMAGE_TARGET_TEXTURE_2D: |
|
480 |
return GL_TEXTURE_2D; |
|
481 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_X: |
|
482 |
return GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
|
483 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_X: |
|
484 |
return GL_TEXTURE_CUBE_MAP_NEGATIVE_X; |
|
485 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_Y: |
|
486 |
return GL_TEXTURE_CUBE_MAP_POSITIVE_Y; |
|
487 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
|
488 |
return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; |
|
489 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_Z: |
|
490 |
return GL_TEXTURE_CUBE_MAP_POSITIVE_Z; |
|
491 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
|
492 |
return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; |
|
493 |
default: |
|
494 |
DGLES2_ASSERT(false); |
|
495 |
} |
|
496 |
||
497 |
// Not reached. |
|
76
24381b61de5c
Host OpenGL ES 2.0 code now building without warning or error using GCC.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
55
diff
changeset
|
498 |
return (GLenum)-1; |
24 | 499 |
} |
500 |
||
501 |
static bool dglPrepareState(DGLContext& ctx, GLuint name, EImageTarget target, GLint level, GLenum& query_target, GLenum& bind_target, GLint& binding) |
|
502 |
{ |
|
503 |
if(name == 0) |
|
504 |
{ |
|
505 |
return false; |
|
506 |
} |
|
507 |
||
508 |
// Store the current error and clear the error flag. |
|
509 |
DGLContext_getHostError(&ctx); |
|
510 |
||
511 |
query_target = dglImageTargetToGLenum(target); |
|
512 |
switch(query_target) |
|
513 |
{ |
|
514 |
case GL_TEXTURE_2D: |
|
515 |
bind_target = GL_TEXTURE_2D; |
|
516 |
ctx.hgl.GetIntegerv(GL_TEXTURE_BINDING_2D, &binding); |
|
517 |
break; |
|
518 |
||
519 |
case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
|
520 |
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
|
521 |
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
|
522 |
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
|
523 |
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
|
524 |
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
|
525 |
bind_target = GL_TEXTURE_CUBE_MAP; |
|
526 |
ctx.hgl.GetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &binding); |
|
527 |
break; |
|
528 |
} |
|
529 |
||
530 |
const DGLTexture* texture = DGLContext_findTexture(&ctx, name); |
|
531 |
if(texture == NULL) |
|
532 |
{ |
|
533 |
return false; |
|
534 |
} |
|
535 |
||
536 |
if(!DGLTexture_isComplete(texture)) |
|
537 |
{ |
|
538 |
if(level != 0) |
|
539 |
{ |
|
540 |
return false; |
|
541 |
} |
|
542 |
else |
|
543 |
{ |
|
544 |
if(!DGLTexture_hasLevelZero(texture)) |
|
545 |
{ |
|
546 |
return false; |
|
547 |
} |
|
548 |
||
549 |
if(DGLTexture_hasLevelsOtherThanZero(texture)) |
|
550 |
{ |
|
551 |
return false; |
|
552 |
} |
|
553 |
} |
|
554 |
} |
|
555 |
||
556 |
ctx.hgl.BindTexture(bind_target, name); |
|
557 |
// Clear any possible error flag. |
|
558 |
if(ctx.hgl.GetError() == GL_INVALID_OPERATION) |
|
559 |
{ |
|
560 |
// Texture was not created with the requested target. |
|
561 |
return false; |
|
562 |
} |
|
563 |
||
564 |
return true; |
|
565 |
} |
|
566 |
||
567 |
static void dglResetState(DGLContext& ctx, GLenum target, GLint binding) |
|
568 |
{ |
|
569 |
// Reset state. |
|
570 |
ctx.hgl.BindTexture(target, binding); |
|
571 |
||
572 |
DGLES2_ASSERT(ctx.hgl.GetError() == GL_NO_ERROR); |
|
573 |
} |
|
574 |
||
575 |
EStatus EGLtoGLES2Interface::GetTextureInfo(void* context, EImageTarget target, void* texture, GLint texture_level, SurfaceDescriptor& surfDesc) |
|
576 |
{ |
|
577 |
DGLES2_ASSERT(context != NULL); |
|
578 |
||
579 |
DGLContext* ctx = (DGLContext*)context; |
|
580 |
GLuint name = (GLuint)texture; |
|
581 |
||
582 |
dglGetLock(); |
|
583 |
||
584 |
GLenum query_target; |
|
585 |
GLenum bind_target; |
|
586 |
GLint binding; |
|
587 |
if(!dglPrepareState(*ctx, name, target, texture_level, query_target, bind_target, binding)) |
|
588 |
{ |
|
589 |
dglReleaseLock(); |
|
590 |
return DGLES2_BAD_PARAMETER; |
|
591 |
} |
|
592 |
||
593 |
CColorDescriptor& colDesc = surfDesc.m_colorDescriptor; |
|
594 |
GLenum format; |
|
595 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_WIDTH, &surfDesc.m_width); |
|
596 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_HEIGHT, &surfDesc.m_height); |
|
597 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_RED_SIZE, &colDesc.m_redSize); |
|
598 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_GREEN_SIZE, &colDesc.m_greenSize); |
|
599 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_BLUE_SIZE, &colDesc.m_blueSize); |
|
600 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_ALPHA_SIZE, &colDesc.m_alphaSize); |
|
601 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_LUMINANCE_SIZE, &colDesc.m_luminanceSize); |
|
602 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_INTERNAL_FORMAT, (GLint*)&format); |
|
603 |
if(format == GL_RGB || format == GL_RGB8) |
|
604 |
{ |
|
605 |
// Convert RGB888 to RGBA8888 to make VG interop easier. |
|
606 |
format = GL_RGBA; |
|
607 |
} |
|
608 |
if(ctx->hgl.GetError() == GL_INVALID_VALUE) |
|
609 |
{ |
|
610 |
// Invalid level. |
|
611 |
dglReleaseLock(); |
|
612 |
return DGLES2_BAD_MATCH; |
|
613 |
} |
|
614 |
||
615 |
surfDesc.m_redShift = 0; |
|
616 |
surfDesc.m_greenShift = 0; |
|
617 |
surfDesc.m_blueShift = 0; |
|
618 |
surfDesc.m_luminanceShift = 0; |
|
619 |
surfDesc.m_alphaShift = 0; |
|
76
24381b61de5c
Host OpenGL ES 2.0 code now building without warning or error using GCC.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
55
diff
changeset
|
620 |
|
24 | 621 |
switch(format) |
622 |
{ |
|
623 |
#ifndef DGLES2_NO_SRGB |
|
624 |
case GL_SRGB8: |
|
625 |
surfDesc.m_redShift = 16; |
|
626 |
surfDesc.m_greenShift = 8; |
|
627 |
surfDesc.m_blueShift = 0; |
|
628 |
colDesc.m_format = CColorDescriptor::sRGBA; |
|
629 |
colDesc.m_bpp = 24; |
|
630 |
break; |
|
631 |
||
632 |
case GL_SRGB8_ALPHA8: |
|
633 |
surfDesc.m_redShift = 24; |
|
634 |
surfDesc.m_greenShift = 16; |
|
635 |
surfDesc.m_blueShift = 8; |
|
636 |
surfDesc.m_alphaShift = 0; |
|
637 |
colDesc.m_format = CColorDescriptor::sRGBA; |
|
638 |
colDesc.m_bpp = 32; |
|
639 |
break; |
|
640 |
||
641 |
case GL_SLUMINANCE8: |
|
642 |
surfDesc.m_luminanceShift = 0; |
|
643 |
colDesc.m_format = CColorDescriptor::sLA; |
|
644 |
colDesc.m_bpp = 8; |
|
645 |
break; |
|
646 |
#endif |
|
647 |
||
648 |
case GL_RGB: |
|
649 |
case GL_RGB8: |
|
650 |
surfDesc.m_redShift = 16; |
|
651 |
surfDesc.m_greenShift = 8; |
|
652 |
surfDesc.m_blueShift = 0; |
|
653 |
colDesc.m_format = CColorDescriptor::lRGBA; |
|
654 |
colDesc.m_bpp = 24; |
|
655 |
break; |
|
656 |
||
657 |
case GL_RGBA: |
|
658 |
case GL_RGBA8: |
|
659 |
surfDesc.m_redShift = 24; |
|
660 |
surfDesc.m_greenShift = 16; |
|
661 |
surfDesc.m_blueShift = 8; |
|
662 |
surfDesc.m_alphaShift = 0; |
|
663 |
colDesc.m_format = CColorDescriptor::lRGBA; |
|
664 |
colDesc.m_bpp = 32; |
|
665 |
break; |
|
666 |
||
667 |
case GL_LUMINANCE_ALPHA: |
|
668 |
surfDesc.m_luminanceShift = 8; |
|
669 |
surfDesc.m_alphaShift = 0; |
|
670 |
colDesc.m_format = CColorDescriptor::lLA; |
|
671 |
colDesc.m_bpp = 16; |
|
672 |
break; |
|
673 |
||
674 |
case GL_ALPHA: |
|
675 |
case GL_ALPHA8: |
|
676 |
surfDesc.m_alphaShift = 0; |
|
677 |
colDesc.m_format = CColorDescriptor::lRGBA; |
|
678 |
colDesc.m_bpp = 8; |
|
679 |
break; |
|
680 |
||
681 |
case GL_LUMINANCE: |
|
682 |
case GL_LUMINANCE8: |
|
683 |
surfDesc.m_luminanceShift = 0; |
|
684 |
colDesc.m_format = CColorDescriptor::lLA; |
|
685 |
colDesc.m_bpp = 8; |
|
686 |
break; |
|
687 |
||
688 |
default: |
|
689 |
DGLES2_ASSERT(GL_FALSE); |
|
690 |
} |
|
691 |
||
692 |
surfDesc.m_stride = colDesc.m_bpp / 8 * surfDesc.m_width; |
|
693 |
||
694 |
dglResetState(*ctx, bind_target, binding); |
|
695 |
dglReleaseLock(); |
|
696 |
return DGLES2_SUCCESS; |
|
697 |
} |
|
698 |
||
699 |
EStatus EGLtoGLES2Interface::GetTextureData( void* context, EImageTarget target, void* texture, EGLint texture_level, void* data ) |
|
700 |
{ |
|
701 |
DGLES2_ASSERT(context != NULL); |
|
702 |
||
703 |
DGLContext* ctx = (DGLContext*)context; |
|
704 |
GLuint name = (GLuint)texture; |
|
705 |
||
706 |
dglGetLock(); |
|
707 |
||
708 |
GLenum query_target; |
|
709 |
GLenum bind_target; |
|
710 |
GLint binding; |
|
711 |
if(!dglPrepareState(*ctx, name, target, texture_level, query_target, bind_target, binding)) |
|
712 |
{ |
|
713 |
dglReleaseLock(); |
|
714 |
return DGLES2_BAD_PARAMETER; |
|
715 |
} |
|
716 |
||
717 |
GLenum format; |
|
718 |
GLint pack_alignment; |
|
719 |
ctx->hgl.GetTexLevelParameteriv(query_target, texture_level, GL_TEXTURE_INTERNAL_FORMAT, (GLint*)&format); |
|
720 |
if(format == GL_RGB || format == GL_RGB8) |
|
721 |
{ |
|
722 |
// Convert RGB888 to RGBA8888 to make VG interop easier. |
|
723 |
format = GL_RGBA; |
|
724 |
} |
|
725 |
ctx->hgl.GetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); |
|
726 |
ctx->hgl.PixelStorei(GL_PACK_ALIGNMENT, 1); |
|
727 |
ctx->hgl.GetTexImage(query_target, texture_level, format, GL_UNSIGNED_BYTE, data); |
|
728 |
ctx->hgl.PixelStorei(GL_PACK_ALIGNMENT, pack_alignment); |
|
729 |
||
730 |
if(ctx->hgl.GetError() == GL_INVALID_VALUE) |
|
731 |
{ |
|
732 |
// Invalid level. |
|
733 |
dglReleaseLock(); |
|
734 |
return DGLES2_BAD_MATCH; |
|
735 |
} |
|
736 |
||
737 |
dglResetState(*ctx, bind_target, binding); |
|
738 |
dglReleaseLock(); |
|
739 |
return DGLES2_SUCCESS; |
|
740 |
} |
|
741 |
||
742 |
bool EGLtoGLES2Interface::CopyBuffers( void* buf, const SurfaceDescriptor* desc ) |
|
743 |
{ |
|
744 |
DGLES2_ENTER_RET(false); |
|
745 |
||
746 |
// Store the current error and clear the error flag. |
|
747 |
DGLContext_getHostError(ctx); |
|
748 |
||
749 |
{ |
|
750 |
GLint framebuffer_binding; |
|
751 |
GLint pack_alignment; |
|
752 |
GLenum internal_format, data_format, data_type; |
|
753 |
||
754 |
ctx->hgl.GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer_binding); |
|
755 |
ctx->hgl.GetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); |
|
756 |
||
757 |
dglSurfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); |
|
758 |
||
759 |
ctx->hgl.BindFramebufferEXT(GL_FRAMEBUFFER, 0); |
|
760 |
ctx->hgl.PixelStorei(GL_PACK_ALIGNMENT, 1); |
|
761 |
ctx->hgl.ReadPixels(0, 0, desc->m_width, desc->m_height, data_format, data_type, buf); |
|
762 |
||
763 |
// Restore state. |
|
764 |
ctx->hgl.PixelStorei(GL_PACK_ALIGNMENT, pack_alignment); |
|
765 |
ctx->hgl.BindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding); |
|
766 |
} |
|
767 |
||
768 |
DGLES2_LEAVE_NO_ERROR_CHECK_RET(ctx->hgl.GetError() == GL_NO_ERROR); |
|
769 |
} |
|
770 |
||
771 |
bool EGLtoGLES2Interface::UpdateBuffers( void* buf, const SurfaceDescriptor* desc ) |
|
772 |
{ |
|
773 |
DGLES2_ENTER_RET(false); |
|
774 |
||
775 |
// Store the current error and clear the error flag. |
|
776 |
DGLContext_getHostError(ctx); |
|
777 |
||
778 |
{ |
|
779 |
GLint framebuffer_binding; |
|
780 |
GLint unpack_alignment; |
|
781 |
GLenum internal_format, data_format, data_type; |
|
782 |
||
783 |
ctx->hgl.GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer_binding); |
|
784 |
ctx->hgl.GetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); |
|
785 |
||
786 |
dglSurfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); |
|
787 |
||
788 |
ctx->hgl.BindFramebufferEXT(GL_FRAMEBUFFER, 0); |
|
789 |
ctx->hgl.PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
|
790 |
ctx->hgl.DrawPixels( desc->m_width, desc->m_height, data_format, data_type, buf ); |
|
791 |
||
792 |
// Restore state. |
|
793 |
ctx->hgl.PixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); |
|
794 |
ctx->hgl.BindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding); |
|
795 |
} |
|
796 |
||
797 |
DGLES2_LEAVE_NO_ERROR_CHECK_RET(ctx->hgl.GetError() == GL_NO_ERROR); |
|
798 |
} |
|
799 |
||
800 |
bool EGLtoGLES2Interface::UpdateImageSibling( EImageTarget imageTarget, void* name ) |
|
801 |
{ |
|
802 |
DGLES2_ENTER_RET(false); |
|
803 |
DGLContext_getHostError(ctx); |
|
804 |
{ |
|
805 |
bool success = true; |
|
806 |
bool cubeMap = false; |
|
807 |
||
808 |
switch(imageTarget) |
|
809 |
{ |
|
810 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_X: |
|
811 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_X: |
|
812 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_Y: |
|
813 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
|
814 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_POSITIVE_Z: |
|
815 |
case IMAGE_TARGET_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
|
816 |
cubeMap = true; |
|
817 |
// fall through |
|
818 |
||
819 |
case IMAGE_TARGET_TEXTURE_2D: |
|
820 |
{ |
|
821 |
DGLTexture* texture; |
|
822 |
GLenum textureTarget; |
|
823 |
GLeglImageOES image; |
|
824 |
GLint binding; |
|
825 |
||
826 |
texture = DGLContext_findTexture(ctx, (GLuint)name); |
|
827 |
if(texture == NULL) |
|
828 |
{ |
|
829 |
success = false; |
|
830 |
break; |
|
831 |
} |
|
832 |
||
833 |
textureTarget = dglImageTargetToGLenum(imageTarget); |
|
834 |
image = DGLTexture_getEGLImage(texture, textureTarget); |
|
835 |
if(image == NULL) |
|
836 |
{ |
|
837 |
success = false; |
|
838 |
break; |
|
839 |
} |
|
840 |
||
841 |
ctx->hgl.GetIntegerv(cubeMap ? GL_TEXTURE_BINDING_CUBE_MAP : GL_TEXTURE_BINDING_2D, &binding); |
|
842 |
ctx->hgl.BindTexture(cubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, texture->obj.name); |
|
843 |
success = !!DGLContext_specifyTextureFromEGLImage(ctx, image, textureTarget); |
|
844 |
||
845 |
// Reset state. |
|
846 |
ctx->hgl.BindTexture(cubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, binding); |
|
847 |
||
848 |
if(!success) |
|
849 |
{ |
|
850 |
success = false; |
|
851 |
break; |
|
852 |
} |
|
853 |
||
854 |
break; |
|
855 |
} |
|
856 |
||
857 |
case IMAGE_TARGET_RENDERBUFFER: |
|
858 |
{ |
|
859 |
DGLRenderbuffer* buffer; |
|
860 |
GLint binding; |
|
861 |
||
862 |
buffer = DGLContext_findRenderbuffer(ctx, (GLuint)name); |
|
863 |
if(buffer == NULL) |
|
864 |
{ |
|
865 |
success = false; |
|
866 |
break; |
|
867 |
} |
|
868 |
||
869 |
if(buffer->egl_image == NULL) |
|
870 |
{ |
|
871 |
success = false; |
|
872 |
break; |
|
873 |
} |
|
874 |
||
875 |
ctx->hgl.GetIntegerv(GL_RENDERBUFFER_BINDING, &binding); |
|
876 |
ctx->hgl.BindRenderbufferEXT(GL_RENDERBUFFER, buffer->obj.name); |
|
877 |
success = !!DGLContext_specifyRenderbufferFromEGLImage(ctx, buffer->egl_image); |
|
878 |
||
879 |
// Reset state. |
|
880 |
ctx->hgl.BindRenderbufferEXT(GL_RENDERBUFFER, binding); |
|
881 |
||
882 |
if(!success) |
|
883 |
{ |
|
884 |
success = false; |
|
885 |
break; |
|
886 |
} |
|
887 |
||
888 |
break; |
|
889 |
} |
|
890 |
||
891 |
default: |
|
892 |
DGLES2_ASSERT(false); |
|
893 |
success = false; |
|
894 |
break; |
|
895 |
} |
|
896 |
||
897 |
if(ctx->hgl.GetError() != GL_NO_ERROR) |
|
898 |
{ |
|
899 |
success = false; |
|
900 |
} |
|
901 |
||
902 |
DGLES2_LEAVE_NO_ERROR_CHECK_RET(success); |
|
903 |
} |
|
904 |
} |
|
905 |
||
906 |
void EGLtoGLES2Interface::Flush() |
|
907 |
{ |
|
908 |
DGLES2_ENTER(); |
|
909 |
ctx->hgl.Flush(); |
|
910 |
DGLES2_LEAVE_NO_ERROR_CHECK(); |
|
911 |
} |
|
912 |
||
913 |
void EGLtoGLES2Interface::Finish() |
|
914 |
{ |
|
915 |
DGLES2_ENTER(); |
|
916 |
ctx->hgl.Finish(); |
|
917 |
DGLES2_LEAVE_NO_ERROR_CHECK(); |
|
918 |
} |
|
919 |
||
920 |
/*static*/ IGLEStoEGLInterface* EGLtoGLES2Interface::GetEGLInterface() |
|
921 |
{ |
|
922 |
return g_EGLtoGLES2Interface.m_egl; |
|
923 |
} |