1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include <EGL/eglext.h>
9 #if defined(GLES2_CONFORM_SUPPORT_ONLY)
10 #include "gpu/gles2_conform_support/gtf/gtf_stubs.h"
12 #include "third_party/gles2_conform/GTF_ES/glsl/GTF/Source/eglNative.h"
15 EGLImageKHR
GTFCreateEGLImage(int width
, int height
,
16 GLenum format
, GLenum type
) {
17 PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr_
;
18 egl_create_image_khr_
= reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC
>
19 (eglGetProcAddress("eglCreateImageKHR"));
21 static const EGLint attrib
[] = {
22 EGL_IMAGE_PRESERVED_KHR
, EGL_TRUE
,
23 EGL_GL_TEXTURE_LEVEL_KHR
, 0,
27 if (format
!= GL_RGBA
&& format
!= GL_RGB
)
28 return static_cast<EGLImageKHR
>(NULL
);
30 if (type
!= GL_UNSIGNED_BYTE
)
31 return static_cast<EGLImageKHR
>(NULL
);
34 glGenTextures(1, &texture
);
35 glBindTexture(GL_TEXTURE_2D
, texture
);
36 glTexImage2D(GL_TEXTURE_2D
,
46 // Disable mip-maps because we do not require it.
47 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
48 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
50 if(glGetError() != GL_NO_ERROR
)
51 return static_cast<EGLImageKHR
>(NULL
);
53 EGLImageKHR egl_image
=
54 egl_create_image_khr_(eglGetCurrentDisplay(),
55 eglGetCurrentContext(),
56 EGL_GL_TEXTURE_2D_KHR
,
57 reinterpret_cast<EGLClientBuffer
>(texture
),
60 if (eglGetError() == EGL_SUCCESS
)
63 return static_cast<EGLImageKHR
>(NULL
);
66 void GTFDestroyEGLImage(EGLImageKHR image
) {
67 PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr_
;
68 egl_destroy_image_khr_
= reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC
>
69 (eglGetProcAddress("eglDestroyImageKHR"));
71 egl_destroy_image_khr_(eglGetCurrentDisplay(), image
);