|
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 #include "EGLInterface.h" |
|
32 #include <new> |
|
33 #include "glesInternal.h" |
|
34 #include "GLESContext.h" |
|
35 #include "SurfaceDescriptor.h" |
|
36 #include "GLESTexture.h" |
|
37 |
|
38 #include <stdlib.h> |
|
39 #include <string.h> |
|
40 |
|
41 namespace |
|
42 { |
|
43 EGLtoGLESInterface g_EGLtoGLESInterface; |
|
44 } |
|
45 |
|
46 GLES_API_CALL IEGLtoGLESInterface* getGLESInterface(void) |
|
47 { |
|
48 return &g_EGLtoGLESInterface; |
|
49 } |
|
50 |
|
51 void glesReleaseTexImage(void* surface, int name, int level) |
|
52 { |
|
53 EGLtoGLESInterface::GetEGLInterface()->ReleaseTexImage(surface, name, level); |
|
54 } |
|
55 |
|
56 EGLtoGLESInterface::EGLtoGLESInterface() : |
|
57 m_egl(NULL) |
|
58 { |
|
59 } |
|
60 |
|
61 void EGLtoGLESInterface::SetEGLInterface( IGLEStoEGLInterface* egl ) |
|
62 { |
|
63 m_egl = egl; |
|
64 } |
|
65 |
|
66 void* EGLtoGLESInterface::CreateContext(void* nativeContext) |
|
67 { |
|
68 GLESContext* newContext = NULL; |
|
69 |
|
70 newContext = GLES_NEW GLESContext(nativeContext); |
|
71 if(newContext == NULL) |
|
72 { |
|
73 return NULL; |
|
74 } |
|
75 m_contexts.insert(newContext); |
|
76 return newContext; |
|
77 } |
|
78 |
|
79 bool EGLtoGLESInterface::ReleaseContext(void* context) |
|
80 { |
|
81 GLES_ASSERT(context != NULL); |
|
82 |
|
83 GLESContext* ctx = static_cast<GLESContext*>(context); |
|
84 if(m_contexts.find(ctx) == m_contexts.end()) |
|
85 { |
|
86 return false; |
|
87 } |
|
88 |
|
89 delete ctx; |
|
90 m_contexts.erase(ctx); |
|
91 |
|
92 return true; |
|
93 } |
|
94 |
|
95 void* EGLtoGLESInterface::GetNativeContext(void* context) |
|
96 { |
|
97 GLES_ASSERT(context != NULL); |
|
98 |
|
99 GLESContext* ctx = static_cast<GLESContext*>(context); |
|
100 if(m_contexts.find(ctx) == m_contexts.end()) |
|
101 { |
|
102 return false; |
|
103 } |
|
104 |
|
105 return ctx->NativeContext(); |
|
106 } |
|
107 |
|
108 fpGLProc EGLtoGLESInterface::GetGLProcAddress( const char *procname ) |
|
109 { |
|
110 if(strcmp(procname, "glPointSizePointerOES") == 0) |
|
111 { |
|
112 return (fpGLProc)glPointSizePointerOES; |
|
113 } |
|
114 else |
|
115 { |
|
116 return NULL; |
|
117 } |
|
118 } |
|
119 |
|
120 static SurfaceDescriptor createSurfaceDescriptor(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) |
|
121 { |
|
122 SurfaceDescriptor desc; |
|
123 desc.m_colorDescriptor.m_redSize = redBits; |
|
124 desc.m_colorDescriptor.m_greenSize = greenBits; |
|
125 desc.m_colorDescriptor.m_blueSize = blueBits; |
|
126 desc.m_colorDescriptor.m_alphaSize = alphaBits; |
|
127 desc.m_colorDescriptor.m_luminanceSize = luminanceBits; |
|
128 desc.m_redShift = redShift; |
|
129 desc.m_greenShift = greenShift; |
|
130 desc.m_blueShift = blueShift; |
|
131 desc.m_alphaShift = alphaShift; |
|
132 desc.m_luminanceShift = luminanceShift; |
|
133 desc.m_colorDescriptor.m_format = format; |
|
134 desc.m_colorDescriptor.m_bpp = bpp; |
|
135 return desc; |
|
136 } |
|
137 |
|
138 typedef struct |
|
139 { |
|
140 SurfaceDescriptor desc; |
|
141 GLenum internal_format; |
|
142 GLenum data_format; |
|
143 GLenum data_type; |
|
144 } DescToEnumMapping; |
|
145 |
|
146 static bool isDescEqualToMapping(const SurfaceDescriptor& desc, const DescToEnumMapping& mapping) |
|
147 { |
|
148 if ((desc.m_colorDescriptor.m_redSize == mapping.desc.m_colorDescriptor.m_redSize) && |
|
149 (desc.m_colorDescriptor.m_greenSize == mapping.desc.m_colorDescriptor.m_greenSize) && |
|
150 (desc.m_colorDescriptor.m_blueSize == mapping.desc.m_colorDescriptor.m_blueSize) && |
|
151 (desc.m_colorDescriptor.m_alphaSize == mapping.desc.m_colorDescriptor.m_alphaSize) && |
|
152 (desc.m_colorDescriptor.m_luminanceSize == mapping.desc.m_colorDescriptor.m_luminanceSize) && |
|
153 (desc.m_redShift == mapping.desc.m_redShift) && |
|
154 (desc.m_greenShift == mapping.desc.m_greenShift) && |
|
155 (desc.m_blueShift == mapping.desc.m_blueShift) && |
|
156 (desc.m_alphaShift == mapping.desc.m_alphaShift) && |
|
157 (desc.m_luminanceShift == mapping.desc.m_luminanceShift) && |
|
158 (desc.m_colorDescriptor.m_format == mapping.desc.m_colorDescriptor.m_format) && |
|
159 (desc.m_colorDescriptor.m_bpp == mapping.desc.m_colorDescriptor.m_bpp)) |
|
160 return true; |
|
161 |
|
162 return false; |
|
163 } |
|
164 |
|
165 static void surfaceDescriptorToGLEnums(const SurfaceDescriptor& desc, GLenum& internal_format, GLenum& data_format, GLenum& data_type) |
|
166 { |
|
167 static const DescToEnumMapping map[] = { |
|
168 /* RGB{A,X} channel ordering */ |
|
169 // sRGBX_8888 |
|
170 {createSurfaceDescriptor(8, 24, 8, 16, 8, 8, 0, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
171 // sRGBA_8888 |
|
172 {createSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
173 // sRGBA_8888_PRE |
|
174 {createSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::sRGBA_PRE, 32), GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
175 // sRGB_565 |
|
176 {createSurfaceDescriptor(5, 11, 6, 5, 5, 0, 0, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, |
|
177 // sRGBA_5551 |
|
178 {createSurfaceDescriptor(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}, |
|
179 // sRGBA_4444 |
|
180 {createSurfaceDescriptor(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}, |
|
181 // sL_8 |
|
182 {createSurfaceDescriptor(0, 0, 0, 0, 0, 0, 0, 0, 8, 0, CColorDescriptor::sLA, 8), GL_SLUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
|
183 // lRGBX_8888 |
|
184 {createSurfaceDescriptor(8, 24, 8, 16, 8, 8, 0, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
185 // lRGBA_8888 |
|
186 {createSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
187 // lRGBA_8888_PRE |
|
188 {createSurfaceDescriptor(8, 24, 8, 16, 8, 8, 8, 0, 0, 0, CColorDescriptor::lRGBA_PRE, 32), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
|
189 // lL_8 |
|
190 {createSurfaceDescriptor(0, 0, 0, 0, 0, 0, 0, 0, 8, 0, CColorDescriptor::lLA, 8), GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
|
191 // A_8 |
|
192 {createSurfaceDescriptor(0, 0, 0, 0, 0, 0, 8, 0, 0, 0, CColorDescriptor::lRGBA, 8), GL_ALPHA8, GL_ALPHA, GL_UNSIGNED_BYTE}, |
|
193 // These should be converted to a compatible format by VG. |
|
194 /* |
|
195 // BW_1 |
|
196 {createSurfaceDescriptor(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, CColorDescriptor::lLA, 1), 0, 0, 0}, |
|
197 // A_1 |
|
198 {createSurfaceDescriptor(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, CColorDescriptor::lRGBA, 1), 0, 0, 0}, |
|
199 // A_4 |
|
200 {createSurfaceDescriptor(0, 0, 0, 0, 0, 0, 4, 0, 0, 0, CColorDescriptor::lRGBA, 4), 0, 0, 0}, |
|
201 */ |
|
202 |
|
203 /* {A,X}RGB channel ordering */ |
|
204 // sXRGB_8888 |
|
205 {createSurfaceDescriptor(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}, |
|
206 // sARGB_8888 |
|
207 {createSurfaceDescriptor(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}, |
|
208 // sARGB_8888_PRE |
|
209 {createSurfaceDescriptor(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}, |
|
210 // sARGB_1555 |
|
211 {createSurfaceDescriptor(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}, |
|
212 // sARGB_4444 |
|
213 {createSurfaceDescriptor(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}, |
|
214 // lXRGB_8888 |
|
215 {createSurfaceDescriptor(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}, |
|
216 // lARGB_8888 |
|
217 {createSurfaceDescriptor(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}, |
|
218 // lARGB_8888_PRE |
|
219 {createSurfaceDescriptor(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}, |
|
220 |
|
221 /* BGR{A,X} channel ordering */ |
|
222 // sBGRX_8888 |
|
223 {createSurfaceDescriptor(8, 8, 8, 16, 8, 24, 0, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
224 // sBGRA_8888 |
|
225 {createSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::sRGBA, 32), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
226 // sBGRA_8888_PRE |
|
227 {createSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::sRGBA_PRE, 32), GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
228 // sBGR_565 |
|
229 {createSurfaceDescriptor(5, 0, 6, 5, 5, 11, 0, 0, 0, 0, CColorDescriptor::sRGBA, 16), GL_SRGB8, GL_BGR, GL_UNSIGNED_SHORT_5_6_5}, |
|
230 // sBGRA_5551 |
|
231 {createSurfaceDescriptor(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}, |
|
232 // sBGRA_4444 |
|
233 {createSurfaceDescriptor(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}, |
|
234 // lBGRX_8888 |
|
235 {createSurfaceDescriptor(8, 8, 8, 16, 8, 24, 0, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGB8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
236 // lBGRA_8888 |
|
237 {createSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::lRGBA, 32), GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
238 // lBGRA_8888_PRE |
|
239 {createSurfaceDescriptor(8, 8, 8, 16, 8, 24, 8, 0, 0, 0, CColorDescriptor::lRGBA_PRE, 32), GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, |
|
240 |
|
241 /* {A,X}BGR channel ordering */ |
|
242 // sXBGR_8888 |
|
243 {createSurfaceDescriptor(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}, |
|
244 // sABGR_8888 |
|
245 {createSurfaceDescriptor(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}, |
|
246 // sABGR_8888_PRE |
|
247 {createSurfaceDescriptor(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}, |
|
248 // sABGR_1555 |
|
249 {createSurfaceDescriptor(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}, |
|
250 // sABGR_4444 |
|
251 {createSurfaceDescriptor(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}, |
|
252 // lXBGR_8888 |
|
253 {createSurfaceDescriptor(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}, |
|
254 // lABGR_8888 |
|
255 {createSurfaceDescriptor(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}, |
|
256 // lABGR_8888_PRE: |
|
257 {createSurfaceDescriptor(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}}; |
|
258 |
|
259 for (size_t i = 0; i < sizeof(map)/sizeof(map[0]); i++) |
|
260 { |
|
261 if (isDescEqualToMapping(desc, map[i])) |
|
262 { |
|
263 internal_format = map[i].internal_format; |
|
264 data_format = map[i].data_format; |
|
265 data_type = map[i].data_type; |
|
266 GLES_ASSERT(internal_format != 0 && data_format != 0 && data_type != 0); |
|
267 return; |
|
268 } |
|
269 } |
|
270 GLES_ASSERT(false); |
|
271 return; |
|
272 } |
|
273 |
|
274 int EGLtoGLESInterface::BindTexImage( void* surface, int level, bool generateMipmap, const SurfaceDescriptor* desc, void* buffer ) |
|
275 { |
|
276 GLES_ENTER_RET(NULL); |
|
277 |
|
278 GLuint ret = 0; |
|
279 |
|
280 // Store the current error and clear the error flag. |
|
281 ctx->GetHostError(); |
|
282 |
|
283 if(level < 0) |
|
284 { |
|
285 level = 0; |
|
286 } |
|
287 else if(level > (int)ctx->MaxTextureLevel()) |
|
288 { |
|
289 level = ctx->MaxTextureLevel(); |
|
290 } |
|
291 |
|
292 GLint origGenMipmapParam; |
|
293 ctx->DGL().glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &origGenMipmapParam); |
|
294 |
|
295 if(!generateMipmap) |
|
296 { |
|
297 // Disable automatic mipmap generation. |
|
298 ctx->DGL().glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); |
|
299 } |
|
300 |
|
301 // Clear all mipmap levels. |
|
302 for(unsigned int i = 0; i < ctx->MaxTextureLevel(); i++) |
|
303 { |
|
304 ctx->DGL().glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
|
305 } |
|
306 |
|
307 GLenum internalFormat, dataFormat, dataType; |
|
308 surfaceDescriptorToGLEnums(*desc, internalFormat, dataFormat, dataType); |
|
309 ctx->DGL().glTexImage2D(GL_TEXTURE_2D, level, internalFormat, desc->m_width, desc->m_height, 0, |
|
310 dataFormat, dataType, buffer); |
|
311 |
|
312 if(!generateMipmap) |
|
313 { |
|
314 // Restore original state. |
|
315 ctx->DGL().glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, origGenMipmapParam); |
|
316 } |
|
317 |
|
318 // Clear any possible error flag. |
|
319 if(ctx->DGL().glGetError() == GL_NO_ERROR) |
|
320 { |
|
321 GLESTexture* texture = ctx->Texture(ctx->TextureBinding()); |
|
322 GLES_ASSERT(texture != NULL); |
|
323 texture->SetLevel(level, GL_RGBA, desc->m_width, desc->m_height); |
|
324 |
|
325 if(generateMipmap && origGenMipmapParam && level == 0) |
|
326 { |
|
327 texture->GenerateMipmap(); |
|
328 } |
|
329 |
|
330 if(texture->Level(level)->boundSurface != NULL) |
|
331 { |
|
332 glesReleaseTexImage(texture->Level(level)->boundSurface, texture->Name(), level); |
|
333 } |
|
334 texture->Level(level)->boundSurface = surface; |
|
335 |
|
336 ret = texture->Name(); |
|
337 } |
|
338 |
|
339 GLES_LEAVE_NO_ERROR_CHECK_RET(ret); |
|
340 } |
|
341 |
|
342 bool EGLtoGLESInterface::ReleaseTexImage( int name, int level ) |
|
343 { |
|
344 GLES_ENTER_RET(false); |
|
345 |
|
346 ctx->GetHostError(); |
|
347 |
|
348 GLuint binding; |
|
349 ctx->DGL().glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&binding); |
|
350 ctx->DGL().glBindTexture(GL_TEXTURE_2D, (GLuint)name); |
|
351 ctx->DGL().glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
|
352 ctx->DGL().glBindTexture(GL_TEXTURE_2D, binding); |
|
353 |
|
354 GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); |
|
355 } |
|
356 |
|
357 bool EGLtoGLESInterface::CopyBuffers( void* buf, const SurfaceDescriptor* desc ) |
|
358 { |
|
359 GLES_ENTER_RET(false); |
|
360 |
|
361 // Store the current error and clear the error flag. |
|
362 ctx->GetHostError(); |
|
363 |
|
364 GLenum internal_format, data_format, data_type; |
|
365 surfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); |
|
366 |
|
367 GLint pack_alignment; |
|
368 ctx->DGL().glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); |
|
369 ctx->DGL().glPixelStorei(GL_PACK_ALIGNMENT, 1); |
|
370 ctx->DGL().glReadPixels(0, 0, desc->m_width, desc->m_height, data_format, data_type, buf); |
|
371 ctx->DGL().glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); |
|
372 |
|
373 GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); |
|
374 } |
|
375 |
|
376 bool EGLtoGLESInterface::UpdateBuffers( void* buf, const SurfaceDescriptor* desc ) |
|
377 { |
|
378 GLES_ENTER_RET(false); |
|
379 |
|
380 // Store the current error and clear the error flag. |
|
381 ctx->GetHostError(); |
|
382 |
|
383 GLenum internal_format, data_format, data_type; |
|
384 surfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); |
|
385 |
|
386 GLint unpack_alignment; |
|
387 ctx->DGL().glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); |
|
388 ctx->DGL().glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
|
389 ctx->DGL().glDrawPixels( desc->m_width, desc->m_height, data_format, data_type, buf ); |
|
390 ctx->DGL().glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); |
|
391 |
|
392 GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); |
|
393 } |
|
394 |
|
395 void EGLtoGLESInterface::Flush() |
|
396 { |
|
397 GLES_ENTER(); |
|
398 |
|
399 // Store the current error and clear the error flag. |
|
400 ctx->GetHostError(); |
|
401 |
|
402 ctx->DGL().glFlush(); |
|
403 |
|
404 ctx->DGL().glGetError(); |
|
405 |
|
406 GLES_LEAVE(); |
|
407 } |
|
408 |
|
409 void EGLtoGLESInterface::Finish() |
|
410 { |
|
411 GLES_ENTER(); |
|
412 |
|
413 // Store the current error and clear the error flag. |
|
414 ctx->GetHostError(); |
|
415 |
|
416 ctx->DGL().glFinish(); |
|
417 |
|
418 ctx->DGL().glGetError(); |
|
419 |
|
420 GLES_LEAVE(); |
|
421 } |
|
422 |
|
423 /*static*/ IGLEStoEGLInterface* EGLtoGLESInterface::GetEGLInterface() |
|
424 { |
|
425 return g_EGLtoGLESInterface.m_egl; |
|
426 } |