1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief EGL image tests.
22 *//*--------------------------------------------------------------------*/
24 #include "teglImageFormatTests.hpp"
26 #include "deStringUtil.hpp"
27 #include "deSTLUtil.hpp"
29 #include "tcuTestLog.hpp"
30 #include "tcuSurface.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "tcuImageCompare.hpp"
34 #include "tcuCommandLine.hpp"
36 #include "egluNativeDisplay.hpp"
37 #include "egluNativeWindow.hpp"
38 #include "egluNativePixmap.hpp"
39 #include "egluConfigFilter.hpp"
40 #include "egluUnique.hpp"
41 #include "egluUtil.hpp"
43 #include "eglwLibrary.hpp"
44 #include "eglwEnums.hpp"
46 #include "gluCallLogWrapper.hpp"
47 #include "gluShaderProgram.hpp"
48 #include "gluStrUtil.hpp"
49 #include "gluTexture.hpp"
50 #include "gluPixelTransfer.hpp"
51 #include "gluObjectWrapper.hpp"
52 #include "gluTextureUtil.hpp"
54 #include "glwEnums.hpp"
55 #include "glwFunctions.hpp"
57 #include "teglImageUtil.hpp"
58 #include "teglAndroidUtil.hpp"
71 using glu::Framebuffer;
72 using glu::Renderbuffer;
75 using eglu::UniqueImage;
77 using tcu::ConstPixelBufferAccess;
90 glu::ProgramSources programSources (const string& vertexSource, const string& fragmentSource)
92 glu::ProgramSources sources;
94 sources << glu::VertexSource(vertexSource) << glu::FragmentSource(fragmentSource);
99 class Program : public glu::ShaderProgram
102 Program (const glw::Functions& gl, const char* vertexSource, const char* fragmentSource)
103 : glu::ShaderProgram(gl, programSources(vertexSource, fragmentSource)) {}
113 class IllegalRendererException : public std::exception
120 virtual ~Action (void) {}
121 virtual bool invoke (ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& refImg) const = 0;
122 virtual string getRequiredExtension (void) const = 0;
141 Operation (int apiIndex_, const Action& action_) : apiIndex(apiIndex_), action(&action_) {}
143 const Action* action;
146 vector<ApiContext> contexts;
147 vector<Operation> operations;
154 ImageApi (const Library& egl, int contextId, EGLDisplay display, EGLSurface surface);
155 virtual ~ImageApi (void) {}
158 const Library& m_egl;
160 EGLDisplay m_display;
161 EGLSurface m_surface;
164 ImageApi::ImageApi (const Library& egl, int contextId, EGLDisplay display, EGLSurface surface)
166 , m_contextId (contextId)
167 , m_display (display)
168 , m_surface (surface)
172 class GLES2ImageApi : public ImageApi, private glu::CallLogWrapper
175 class GLES2Action : public Action
178 bool invoke (ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const;
179 virtual bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const = 0;
182 class Create : public GLES2Action
185 Create (MovePtr<ImageSource> imgSource) : m_imgSource(imgSource) {}
186 string getRequiredExtension (void) const { return m_imgSource->getRequiredExtension(); }
187 bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const;
188 glw::GLenum getEffectiveFormat (void) const { return m_imgSource->getEffectiveFormat(); }
191 UniquePtr<ImageSource> m_imgSource;
194 class Render : public GLES2Action
197 string getRequiredExtension (void) const { return "GL_OES_EGL_image"; }
200 class RenderTexture2D : public Render { public: bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const; };
201 class RenderTextureCubemap : public Render { public: bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const; };
202 class RenderReadPixelsRenderbuffer : public Render { public: bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const; };
203 class RenderDepthbuffer : public Render { public: bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const; };
204 class RenderStencilbuffer : public Render { public: bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const; };
205 class RenderTryAll : public Render { public: bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const; };
207 class Modify : public GLES2Action
210 string getRequiredExtension (void) const { return "GL_OES_EGL_image"; }
213 class ModifyTexSubImage : public Modify
216 ModifyTexSubImage (GLenum format, GLenum type) : m_format(format), m_type(type) {}
217 bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const;
218 GLenum getFormat (void) const { return m_format; }
219 GLenum getType (void) const { return m_type; }
226 class ModifyRenderbuffer : public Modify
229 bool invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const;
232 virtual void initializeRbo (GLES2ImageApi& api, GLuint rbo, tcu::Texture2D& ref) const = 0;
235 class ModifyRenderbufferClearColor : public ModifyRenderbuffer
238 ModifyRenderbufferClearColor (tcu::Vec4 color) : m_color(color) {}
241 void initializeRbo (GLES2ImageApi& api, GLuint rbo, tcu::Texture2D& ref) const;
246 class ModifyRenderbufferClearDepth : public ModifyRenderbuffer
249 ModifyRenderbufferClearDepth (GLfloat depth) : m_depth(depth) {}
252 void initializeRbo (GLES2ImageApi& api, GLuint rbo, tcu::Texture2D& ref) const;
257 class ModifyRenderbufferClearStencil : public ModifyRenderbuffer
260 ModifyRenderbufferClearStencil (GLint stencil) : m_stencil(stencil) {}
263 void initializeRbo (GLES2ImageApi& api, GLuint rbo, tcu::Texture2D& ref) const;
268 GLES2ImageApi (const Library& egl, const glw::Functions& gl, int contextId, tcu::TestLog& log, EGLDisplay display, EGLSurface surface, EGLConfig config);
269 ~GLES2ImageApi (void);
272 EGLContext m_context;
273 const glw::Functions& m_gl;
275 MovePtr<UniqueImage> createImage (const ImageSource& source, const ClientBuffer& buffer) const;
278 GLES2ImageApi::GLES2ImageApi (const Library& egl, const glw::Functions& gl, int contextId, tcu::TestLog& log, EGLDisplay display, EGLSurface surface, EGLConfig config)
279 : ImageApi (egl, contextId, display, surface)
280 , glu::CallLogWrapper (gl, log)
281 , m_context (DE_NULL)
284 const EGLint attriblist[] =
286 EGL_CONTEXT_CLIENT_VERSION, 2,
290 EGLint configId = -1;
291 EGLU_CHECK_CALL(m_egl, getConfigAttrib(m_display, config, EGL_CONFIG_ID, &configId));
292 getLog() << tcu::TestLog::Message << "Creating gles2 context with config id: " << configId << " context: " << m_contextId << tcu::TestLog::EndMessage;
293 egl.bindAPI(EGL_OPENGL_ES_API);
294 m_context = m_egl.createContext(m_display, config, EGL_NO_CONTEXT, attriblist);
295 EGLU_CHECK_MSG(m_egl, "Failed to create GLES2 context");
297 egl.makeCurrent(display, m_surface, m_surface, m_context);
298 EGLU_CHECK_MSG(m_egl, "Failed to make context current");
301 GLES2ImageApi::~GLES2ImageApi (void)
303 m_egl.makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
304 m_egl.destroyContext(m_display, m_context);
307 bool GLES2ImageApi::GLES2Action::invoke (ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const
309 GLES2ImageApi& gles2Api = dynamic_cast<GLES2ImageApi&>(api);
311 gles2Api.m_egl.makeCurrent(gles2Api.m_display, gles2Api.m_surface, gles2Api.m_surface, gles2Api.m_context);
312 return invokeGLES2(gles2Api, image, ref);
316 bool GLES2ImageApi::Create::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& image, tcu::Texture2D& ref) const
318 de::UniquePtr<ClientBuffer> buffer (m_imgSource->createBuffer(api.m_gl, &ref));
319 image = api.createImage(*m_imgSource, *buffer);
323 MovePtr<UniqueImage> GLES2ImageApi::createImage (const ImageSource& source, const ClientBuffer& buffer) const
325 const EGLImageKHR image = source.createImage(m_egl, m_display, m_context, buffer.get());
326 return MovePtr<UniqueImage>(new UniqueImage(m_egl, m_display, image));
329 static void imageTargetTexture2D (const Library& egl, const glw::Functions& gl, GLeglImageOES img)
331 gl.eglImageTargetTexture2DOES(GL_TEXTURE_2D, img);
333 const GLenum error = gl.getError();
335 if (error == GL_INVALID_OPERATION)
336 TCU_THROW(NotSupportedError, "Creating texture2D from EGLImage type not supported");
338 GLU_EXPECT_NO_ERROR(error, "glEGLImageTargetTexture2DOES()");
339 EGLU_CHECK_MSG(egl, "glEGLImageTargetTexture2DOES()");
343 static void imageTargetRenderbuffer (const Library& egl, const glw::Functions& gl, GLeglImageOES img)
345 gl.eglImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, img);
347 const GLenum error = gl.getError();
349 if (error == GL_INVALID_OPERATION)
350 TCU_THROW(NotSupportedError, "Creating renderbuffer from EGLImage type not supported");
352 GLU_EXPECT_NO_ERROR(error, "glEGLImageTargetRenderbufferStorageOES()");
353 EGLU_CHECK_MSG(egl, "glEGLImageTargetRenderbufferStorageOES()");
357 static void framebufferRenderbuffer (const glw::Functions& gl, GLenum attachment, GLuint rbo)
359 GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, rbo));
360 TCU_CHECK_AND_THROW(NotSupportedError,
361 gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE,
362 ("EGLImage as " + string(glu::getFramebufferAttachmentName(attachment)) + " not supported").c_str());
365 static const float squareTriangleCoords[] =
376 bool GLES2ImageApi::RenderTexture2D::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
378 const glw::Functions& gl = api.m_gl;
379 tcu::TestLog& log = api.getLog();
382 // Branch only taken in TryAll case
383 if (reference.getFormat().order == tcu::TextureFormat::DS || reference.getFormat().order == tcu::TextureFormat::D)
384 throw IllegalRendererException(); // Skip, GLES2 does not support sampling depth textures
385 if (reference.getFormat().order == tcu::TextureFormat::S)
386 throw IllegalRendererException(); // Skip, GLES2 does not support sampling stencil textures
388 gl.clearColor(0.0, 0.0, 0.0, 0.0);
389 gl.viewport(0, 0, reference.getWidth(), reference.getHeight());
390 gl.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
391 gl.disable(GL_DEPTH_TEST);
393 log << tcu::TestLog::Message << "Rendering EGLImage as GL_TEXTURE_2D in context: " << api.m_contextId << tcu::TestLog::EndMessage;
394 TCU_CHECK(**img != EGL_NO_IMAGE_KHR);
396 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, *srcTex));
397 imageTargetTexture2D(api.m_egl, gl, **img);
399 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
400 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
401 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
402 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
404 const char* const vertexShader =
405 "attribute highp vec2 a_coord;\n"
406 "varying mediump vec2 v_texCoord;\n"
407 "void main(void) {\n"
408 "\tv_texCoord = vec2((a_coord.x + 1.0) * 0.5, (a_coord.y + 1.0) * 0.5);\n"
409 "\tgl_Position = vec4(a_coord, -0.1, 1.0);\n"
412 const char* const fragmentShader =
413 "varying mediump vec2 v_texCoord;\n"
414 "uniform sampler2D u_sampler;\n"
415 "void main(void) {\n"
416 "\tmediump vec4 texColor = texture2D(u_sampler, v_texCoord);\n"
417 "\tgl_FragColor = vec4(texColor);\n"
420 Program program(gl, vertexShader, fragmentShader);
421 TCU_CHECK(program.isOk());
423 GLuint glProgram = program.getProgram();
424 GLU_CHECK_GLW_CALL(gl, useProgram(glProgram));
426 GLuint coordLoc = gl.getAttribLocation(glProgram, "a_coord");
427 TCU_CHECK_MSG((int)coordLoc != -1, "Couldn't find attribute a_coord");
429 GLuint samplerLoc = gl.getUniformLocation(glProgram, "u_sampler");
430 TCU_CHECK_MSG((int)samplerLoc != (int)-1, "Couldn't find uniform u_sampler");
432 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, *srcTex));
433 GLU_CHECK_GLW_CALL(gl, uniform1i(samplerLoc, 0));
434 GLU_CHECK_GLW_CALL(gl, enableVertexAttribArray(coordLoc));
435 GLU_CHECK_GLW_CALL(gl, vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, squareTriangleCoords));
437 GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
438 GLU_CHECK_GLW_CALL(gl, disableVertexAttribArray(coordLoc));
439 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, 0));
441 tcu::Surface refSurface (reference.getWidth(), reference.getHeight());
442 tcu::Surface screen (reference.getWidth(), reference.getHeight());
443 GLU_CHECK_GLW_CALL(gl, readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr()));
445 tcu::copy(refSurface.getAccess(), reference.getLevel(0));
447 float threshold = 0.05f;
448 bool match = tcu::fuzzyCompare(log, "ComparisonResult", "Image comparison result", refSurface, screen, threshold, tcu::COMPARE_LOG_RESULT);
453 bool GLES2ImageApi::RenderDepthbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
455 const glw::Functions& gl = api.m_gl;
456 tcu::TestLog& log = api.getLog();
457 Framebuffer framebuffer (gl);
458 Renderbuffer renderbufferColor (gl);
459 Renderbuffer renderbufferDepth (gl);
460 const tcu::RGBA compareThreshold (32, 32, 32, 32); // layer colors are far apart, large thresholds are ok
462 // Branch only taken in TryAll case
463 if (reference.getFormat().order != tcu::TextureFormat::DS && reference.getFormat().order != tcu::TextureFormat::D)
464 throw IllegalRendererException(); // Skip, interpreting non-depth data as depth data is not meaningful
466 log << tcu::TestLog::Message << "Rendering with depth buffer" << tcu::TestLog::EndMessage;
468 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
470 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferColor));
471 GLU_CHECK_GLW_CALL(gl, renderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, reference.getWidth(), reference.getHeight()));
472 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, *renderbufferColor);
474 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferDepth));
475 imageTargetRenderbuffer(api.m_egl, gl, **img);
476 framebufferRenderbuffer(gl, GL_DEPTH_ATTACHMENT, *renderbufferDepth);
477 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
479 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
482 const char* vertexShader =
483 "attribute highp vec2 a_coord;\n"
484 "uniform highp float u_depth;\n"
485 "void main(void) {\n"
486 "\tgl_Position = vec4(a_coord, u_depth, 1.0);\n"
489 const char* fragmentShader =
490 "uniform mediump vec4 u_color;\n"
491 "void main(void) {\n"
492 "\tgl_FragColor = u_color;\n"
495 Program program(gl, vertexShader, fragmentShader);
496 TCU_CHECK(program.isOk());
498 GLuint glProgram = program.getProgram();
499 GLU_CHECK_GLW_CALL(gl, useProgram(glProgram));
501 GLuint coordLoc = gl.getAttribLocation(glProgram, "a_coord");
502 TCU_CHECK_MSG((int)coordLoc != -1, "Couldn't find attribute a_coord");
504 GLuint colorLoc = gl.getUniformLocation(glProgram, "u_color");
505 TCU_CHECK_MSG((int)colorLoc != (int)-1, "Couldn't find uniform u_color");
507 GLuint depthLoc = gl.getUniformLocation(glProgram, "u_depth");
508 TCU_CHECK_MSG((int)depthLoc != (int)-1, "Couldn't find uniform u_depth");
510 GLU_CHECK_GLW_CALL(gl, clearColor(0.5f, 1.0f, 0.5f, 1.0f));
511 GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
513 tcu::Vec4 depthLevelColors[] = {
514 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
515 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
516 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
517 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
518 tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f),
520 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
521 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
522 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f),
523 tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f),
524 tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f)
527 GLU_CHECK_GLW_CALL(gl, enableVertexAttribArray(coordLoc));
528 GLU_CHECK_GLW_CALL(gl, vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, squareTriangleCoords));
530 GLU_CHECK_GLW_CALL(gl, enable(GL_DEPTH_TEST));
531 GLU_CHECK_GLW_CALL(gl, depthFunc(GL_LESS));
532 GLU_CHECK_GLW_CALL(gl, depthMask(GL_FALSE));
534 for (int level = 0; level < DE_LENGTH_OF_ARRAY(depthLevelColors); level++)
536 const tcu::Vec4 color = depthLevelColors[level];
537 const float clipDepth = ((float)(level + 1) * 0.1f) * 2.0f - 1.0f; // depth in clip coords
539 GLU_CHECK_GLW_CALL(gl, uniform4f(colorLoc, color.x(), color.y(), color.z(), color.w()));
540 GLU_CHECK_GLW_CALL(gl, uniform1f(depthLoc, clipDepth));
541 GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
544 GLU_CHECK_GLW_CALL(gl, depthMask(GL_TRUE));
545 GLU_CHECK_GLW_CALL(gl, disable(GL_DEPTH_TEST));
546 GLU_CHECK_GLW_CALL(gl, disableVertexAttribArray(coordLoc));
548 const ConstPixelBufferAccess& refAccess = reference.getLevel(0);
549 tcu::Surface screen (reference.getWidth(), reference.getHeight());
550 tcu::Surface referenceScreen (reference.getWidth(), reference.getHeight());
552 gl.readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr());
554 for (int y = 0; y < reference.getHeight(); y++)
556 for (int x = 0; x < reference.getWidth(); x++)
558 tcu::Vec4 result = tcu::Vec4(0.5f, 1.0f, 0.5f, 1.0f);
560 for (int level = 0; level < DE_LENGTH_OF_ARRAY(depthLevelColors); level++)
562 if ((float)(level + 1) * 0.1f < refAccess.getPixDepth(x, y))
563 result = depthLevelColors[level];
566 referenceScreen.getAccess().setPixel(result, x, y);
570 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
571 GLU_CHECK_GLW_CALL(gl, finish());
573 return tcu::pixelThresholdCompare(log, "Depth buffer rendering result", "Result from rendering with depth buffer", referenceScreen, screen, compareThreshold, tcu::COMPARE_LOG_RESULT);
576 bool GLES2ImageApi::RenderStencilbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
578 // Branch only taken in TryAll case
579 if (reference.getFormat().order != tcu::TextureFormat::DS && reference.getFormat().order != tcu::TextureFormat::S)
580 throw IllegalRendererException(); // Skip, interpreting non-stencil data as stencil data is not meaningful
582 const glw::Functions& gl = api.m_gl;
583 tcu::TestLog& log = api.getLog();
584 Framebuffer framebuffer (gl);
585 Renderbuffer renderbufferColor (gl);
586 Renderbuffer renderbufferStencil (gl);
587 const tcu::RGBA compareThreshold (32, 32, 32, 32); // layer colors are far apart, large thresholds are ok
588 const deUint32 numStencilBits = tcu::getTextureFormatBitDepth(tcu::getEffectiveDepthStencilTextureFormat(reference.getLevel(0).getFormat(), tcu::Sampler::MODE_STENCIL)).x();
589 const deUint32 maxStencil = deBitMask32(0, numStencilBits);
591 log << tcu::TestLog::Message << "Rendering with stencil buffer" << tcu::TestLog::EndMessage;
593 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
595 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferColor));
596 GLU_CHECK_GLW_CALL(gl, renderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, reference.getWidth(), reference.getHeight()));
597 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, *renderbufferColor);
599 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferStencil));
600 imageTargetRenderbuffer(api.m_egl, gl, **img);
601 framebufferRenderbuffer(gl, GL_STENCIL_ATTACHMENT, *renderbufferStencil);
602 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
604 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
607 const char* vertexShader =
608 "attribute highp vec2 a_coord;\n"
609 "void main(void) {\n"
610 "\tgl_Position = vec4(a_coord, 0.0, 1.0);\n"
613 const char* fragmentShader =
614 "uniform mediump vec4 u_color;\n"
615 "void main(void) {\n"
616 "\tgl_FragColor = u_color;\n"
619 Program program(gl, vertexShader, fragmentShader);
620 TCU_CHECK(program.isOk());
622 GLuint glProgram = program.getProgram();
623 GLU_CHECK_GLW_CALL(gl, useProgram(glProgram));
625 GLuint coordLoc = gl.getAttribLocation(glProgram, "a_coord");
626 TCU_CHECK_MSG((int)coordLoc != -1, "Couldn't find attribute a_coord");
628 GLuint colorLoc = gl.getUniformLocation(glProgram, "u_color");
629 TCU_CHECK_MSG((int)colorLoc != (int)-1, "Couldn't find uniform u_color");
631 GLU_CHECK_GLW_CALL(gl, clearColor(0.5f, 1.0f, 0.5f, 1.0f));
632 GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
634 tcu::Vec4 stencilLevelColors[] = {
635 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
636 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
637 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
638 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
639 tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f),
641 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
642 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
643 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f),
644 tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f),
645 tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f)
648 GLU_CHECK_GLW_CALL(gl, enableVertexAttribArray(coordLoc));
649 GLU_CHECK_GLW_CALL(gl, vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, squareTriangleCoords));
651 GLU_CHECK_GLW_CALL(gl, enable(GL_STENCIL_TEST));
652 GLU_CHECK_GLW_CALL(gl, stencilOp(GL_KEEP, GL_KEEP, GL_KEEP));
654 for (int level = 0; level < DE_LENGTH_OF_ARRAY(stencilLevelColors); level++)
656 const tcu::Vec4 color = stencilLevelColors[level];
657 const int stencil = (int)(((float)(level + 1) * 0.1f) * (float)maxStencil);
659 GLU_CHECK_GLW_CALL(gl, stencilFunc(GL_LESS, stencil, 0xFFFFFFFFu));
660 GLU_CHECK_GLW_CALL(gl, uniform4f(colorLoc, color.x(), color.y(), color.z(), color.w()));
661 GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
664 GLU_CHECK_GLW_CALL(gl, disable(GL_STENCIL_TEST));
665 GLU_CHECK_GLW_CALL(gl, disableVertexAttribArray(coordLoc));
667 const ConstPixelBufferAccess& refAccess = reference.getLevel(0);
668 tcu::Surface screen (reference.getWidth(), reference.getHeight());
669 tcu::Surface referenceScreen (reference.getWidth(), reference.getHeight());
671 gl.readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr());
673 for (int y = 0; y < reference.getHeight(); y++)
674 for (int x = 0; x < reference.getWidth(); x++)
676 tcu::Vec4 result = tcu::Vec4(0.5f, 1.0f, 0.5f, 1.0f);
678 for (int level = 0; level < DE_LENGTH_OF_ARRAY(stencilLevelColors); level++)
680 const int levelStencil = (int)(((float)(level + 1) * 0.1f) * (float)maxStencil);
681 if (levelStencil < refAccess.getPixStencil(x, y))
682 result = stencilLevelColors[level];
685 referenceScreen.getAccess().setPixel(result, x, y);
688 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
689 GLU_CHECK_GLW_CALL(gl, finish());
691 return tcu::pixelThresholdCompare(log, "StencilResult", "Result from rendering with stencil buffer", referenceScreen, screen, compareThreshold, tcu::COMPARE_LOG_RESULT);
694 bool GLES2ImageApi::RenderReadPixelsRenderbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
696 const glw::Functions& gl = api.m_gl;
697 const tcu::IVec4 bitDepth = tcu::getTextureFormatMantissaBitDepth(reference.getFormat());
698 const tcu::IVec4 threshold (2 * (tcu::IVec4(1) << (tcu::IVec4(8) - bitDepth)));
699 const tcu::RGBA threshold8 ((deUint8)(de::clamp(threshold[0], 0, 255)), (deUint8)(de::clamp(threshold[1], 0, 255)), (deUint8)(de::clamp(threshold[2], 0, 255)), (deUint8)(de::clamp(threshold[3], 0, 255)));
700 tcu::TestLog& log = api.getLog();
701 Framebuffer framebuffer (gl);
702 Renderbuffer renderbuffer (gl);
703 tcu::Surface screen (reference.getWidth(), reference.getHeight());
704 tcu::Surface refSurface (reference.getWidth(), reference.getHeight());
706 // Branch only taken in TryAll case
707 if (reference.getFormat().order == tcu::TextureFormat::DS || reference.getFormat().order == tcu::TextureFormat::D)
708 throw IllegalRendererException(); // Skip, GLES2 does not support ReadPixels for depth attachments
709 if (reference.getFormat().order == tcu::TextureFormat::S)
710 throw IllegalRendererException(); // Skip, GLES2 does not support ReadPixels for stencil attachments
712 log << tcu::TestLog::Message << "Reading with ReadPixels from renderbuffer" << tcu::TestLog::EndMessage;
714 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
715 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbuffer));
716 imageTargetRenderbuffer(api.m_egl, gl, **img);
717 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, *renderbuffer);
719 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
721 gl.readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr());
723 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
724 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
725 GLU_CHECK_GLW_CALL(gl, finish());
727 tcu::copy(refSurface.getAccess(), reference.getLevel(0));
729 return tcu::pixelThresholdCompare(log, "Renderbuffer read", "Result from reading renderbuffer", refSurface, screen, threshold8, tcu::COMPARE_LOG_RESULT);
733 bool GLES2ImageApi::RenderTryAll::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
735 bool foundSupported = false;
736 tcu::TestLog& log = api.getLog();
737 GLES2ImageApi::RenderTexture2D renderTex2D;
738 GLES2ImageApi::RenderReadPixelsRenderbuffer renderReadPixels;
739 GLES2ImageApi::RenderDepthbuffer renderDepth;
740 GLES2ImageApi::RenderStencilbuffer renderStencil;
741 Action* actions[] = { &renderTex2D, &renderReadPixels, &renderDepth, &renderStencil };
743 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(actions); ++ndx)
747 if (!actions[ndx]->invoke(api, img, reference))
750 foundSupported = true;
752 catch (const tcu::NotSupportedError& error)
754 log << tcu::TestLog::Message << error.what() << tcu::TestLog::EndMessage;
756 catch (const IllegalRendererException&)
758 // not valid renderer
763 throw tcu::NotSupportedError("Rendering not supported", "", __FILE__, __LINE__);
768 bool GLES2ImageApi::ModifyTexSubImage::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
770 const glw::Functions& gl = api.m_gl;
771 tcu::TestLog& log = api.getLog();
772 glu::Texture srcTex (gl);
773 const int xOffset = 8;
774 const int yOffset = 16;
775 const int xSize = de::clamp(16, 0, reference.getWidth() - xOffset);
776 const int ySize = de::clamp(16, 0, reference.getHeight() - yOffset);
777 tcu::Texture2D src (glu::mapGLTransferFormat(m_format, m_type), xSize, ySize);
779 log << tcu::TestLog::Message << "Modifying EGLImage with gl.texSubImage2D" << tcu::TestLog::EndMessage;
782 tcu::fillWithComponentGradients(src.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
784 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, *srcTex));
785 imageTargetTexture2D(api.m_egl, gl, **img);
786 GLU_CHECK_GLW_CALL(gl, texSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, src.getWidth(), src.getHeight(), m_format, m_type, src.getLevel(0).getDataPtr()));
787 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, 0));
788 GLU_CHECK_GLW_CALL(gl, finish());
790 tcu::copy(tcu::getSubregion(reference.getLevel(0), xOffset, yOffset, 0, xSize, ySize, 1), src.getLevel(0));
795 bool GLES2ImageApi::ModifyRenderbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
797 const glw::Functions& gl = api.m_gl;
798 tcu::TestLog& log = api.getLog();
799 glu::Framebuffer framebuffer (gl);
800 glu::Renderbuffer renderbuffer (gl);
802 log << tcu::TestLog::Message << "Modifying EGLImage with glClear to renderbuffer" << tcu::TestLog::EndMessage;
804 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
805 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbuffer));
807 imageTargetRenderbuffer(api.m_egl, gl, **img);
809 initializeRbo(api, *renderbuffer, reference);
811 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
812 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
814 GLU_CHECK_GLW_CALL(gl, finish());
819 void GLES2ImageApi::ModifyRenderbufferClearColor::initializeRbo (GLES2ImageApi& api, GLuint renderbuffer, tcu::Texture2D& reference) const
821 const glw::Functions& gl = api.m_gl;
823 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, renderbuffer);
825 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
826 GLU_CHECK_GLW_CALL(gl, clearColor(m_color.x(), m_color.y(), m_color.z(), m_color.w()));
827 GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
829 tcu::clear(reference.getLevel(0), m_color);
832 void GLES2ImageApi::ModifyRenderbufferClearDepth::initializeRbo (GLES2ImageApi& api, GLuint renderbuffer, tcu::Texture2D& reference) const
834 const glw::Functions& gl = api.m_gl;
836 framebufferRenderbuffer(gl, GL_DEPTH_ATTACHMENT, renderbuffer);
838 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
839 GLU_CHECK_GLW_CALL(gl, clearDepthf(m_depth));
840 GLU_CHECK_GLW_CALL(gl, clear(GL_DEPTH_BUFFER_BIT));
842 tcu::clearDepth(reference.getLevel(0), m_depth);
845 void GLES2ImageApi::ModifyRenderbufferClearStencil::initializeRbo (GLES2ImageApi& api, GLuint renderbuffer, tcu::Texture2D& reference) const
847 const glw::Functions& gl = api.m_gl;
849 framebufferRenderbuffer(gl, GL_STENCIL_ATTACHMENT, renderbuffer);
851 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
852 GLU_CHECK_GLW_CALL(gl, clearStencil(m_stencil));
853 GLU_CHECK_GLW_CALL(gl, clear(GL_STENCIL_BUFFER_BIT));
855 tcu::clearStencil(reference.getLevel(0), m_stencil);
858 class ImageFormatCase : public TestCase, private glu::CallLogWrapper
861 ImageFormatCase (EglTestContext& eglTestCtx, const TestSpec& spec);
862 ~ImageFormatCase (void);
866 IterateResult iterate (void);
867 void checkExtensions (void);
870 EGLConfig getConfig (void);
872 const TestSpec m_spec;
874 vector<ImageApi*> m_apiContexts;
876 EGLDisplay m_display;
877 eglu::NativeWindow* m_window;
878 EGLSurface m_surface;
881 MovePtr<UniqueImage>m_img;
882 tcu::Texture2D m_refImg;
886 EGLConfig ImageFormatCase::getConfig (void)
888 const EGLint attribList[] =
890 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
891 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
900 return eglu::chooseSingleConfig(m_eglTestCtx.getLibrary(), m_display, attribList);
903 ImageFormatCase::ImageFormatCase (EglTestContext& eglTestCtx, const TestSpec& spec)
904 : TestCase (eglTestCtx, spec.name.c_str(), spec.desc.c_str())
905 , glu::CallLogWrapper (m_gl, eglTestCtx.getTestContext().getLog())
907 , m_display (EGL_NO_DISPLAY)
909 , m_surface (EGL_NO_SURFACE)
912 , m_refImg (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1)
916 ImageFormatCase::~ImageFormatCase (void)
921 void ImageFormatCase::checkExtensions (void)
923 const Library& egl = m_eglTestCtx.getLibrary();
924 const EGLDisplay dpy = m_display;
926 const vector<string> glExts = de::splitString((const char*) m_gl.getString(GL_EXTENSIONS));
927 const vector<string> eglExts = eglu::getDisplayExtensions(egl, dpy);
929 exts.insert(glExts.begin(), glExts.end());
930 exts.insert(eglExts.begin(), eglExts.end());
932 if (eglu::getVersion(egl, dpy) >= eglu::Version(1, 5))
934 // EGL 1.5 has built-in support for EGLImage and GL sources
935 exts.insert("EGL_KHR_image_base");
936 exts.insert("EGL_KHR_gl_texture_2D_image");
937 exts.insert("EGL_KHR_gl_texture_cubemap_image");
938 exts.insert("EGL_KHR_gl_renderbuffer_image");
941 if (!de::contains(exts, "EGL_KHR_image_base") && !de::contains(exts, "EGL_KHR_image"))
943 getLog() << tcu::TestLog::Message
944 << "EGL version is under 1.5 and neither EGL_KHR_image nor EGL_KHR_image_base is supported."
945 << "One should be supported."
946 << tcu::TestLog::EndMessage;
947 TCU_THROW(NotSupportedError, "Extension not supported: EGL_KHR_image_base");
950 for (int operationNdx = 0; operationNdx < (int)m_spec.operations.size(); operationNdx++)
952 const TestSpec::Operation& op = m_spec.operations[operationNdx];
953 const string ext = op.action->getRequiredExtension();
955 if (!de::contains(exts, ext))
956 TCU_THROW_EXPR(NotSupportedError, "Extension not supported", ext.c_str());
960 void ImageFormatCase::init (void)
962 const Library& egl = m_eglTestCtx.getLibrary();
963 const eglu::NativeWindowFactory& windowFactory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
967 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
968 m_config = getConfig();
969 m_window = windowFactory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_display, m_config, DE_NULL, eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
970 m_surface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_window, m_display, m_config, DE_NULL);
973 const char* extensions[] = { "GL_OES_EGL_image" };
974 m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0), DE_LENGTH_OF_ARRAY(extensions), &extensions[0]);
977 for (int contextNdx = 0; contextNdx < (int)m_spec.contexts.size(); contextNdx++)
979 ImageApi* api = DE_NULL;
980 switch (m_spec.contexts[contextNdx])
982 case TestSpec::API_GLES2:
984 api = new GLES2ImageApi(egl, m_gl, contextNdx, getLog(), m_display, m_surface, m_config);
992 m_apiContexts.push_back(api);
1003 void ImageFormatCase::deinit (void)
1005 const Library& egl = m_eglTestCtx.getLibrary();
1007 for (int contexNdx = 0 ; contexNdx < (int)m_apiContexts.size(); contexNdx++)
1008 delete m_apiContexts[contexNdx];
1010 m_apiContexts.clear();
1012 if (m_surface != EGL_NO_SURFACE)
1014 egl.destroySurface(m_display, m_surface);
1015 m_surface = EGL_NO_SURFACE;
1021 if (m_display != EGL_NO_DISPLAY)
1023 egl.terminate(m_display);
1024 m_display = EGL_NO_DISPLAY;
1028 TestCase::IterateResult ImageFormatCase::iterate (void)
1030 const TestSpec::Operation& op = m_spec.operations[m_curIter++];
1031 ImageApi& api = *m_apiContexts[op.apiIndex];
1032 const bool isOk = op.action->invoke(api, m_img, m_refImg);
1034 if (isOk && m_curIter < (int)m_spec.operations.size())
1037 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1039 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1044 struct LabeledAction
1047 MovePtr<Action> action;
1050 // A simple vector mockup that we need because MovePtr isn't copy-constructible.
1051 struct LabeledActions
1053 LabeledActions (void) : m_numActions(0){}
1054 LabeledAction& operator[] (int ndx) { DE_ASSERT(0 <= ndx && ndx < m_numActions); return m_actions[ndx]; }
1055 void add (const string& label, MovePtr<Action> action);
1056 int size (void) const { return m_numActions; }
1058 LabeledAction m_actions[32];
1062 void LabeledActions::add (const string& label, MovePtr<Action> action)
1064 DE_ASSERT(m_numActions < DE_LENGTH_OF_ARRAY(m_actions));
1065 m_actions[m_numActions].label = label;
1066 m_actions[m_numActions].action = action;
1070 class ImageTests : public TestCaseGroup
1073 ImageTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1074 : TestCaseGroup(eglTestCtx, name.c_str(), desc.c_str()) {}
1076 void addCreateTexture (const string& name, EGLenum source, GLenum internalFormat, GLenum format, GLenum type);
1077 void addCreateRenderbuffer (const string& name, GLenum format);
1078 void addCreateAndroidNative (const string& name, GLenum format);
1079 void addCreateTexture2DActions (const string& prefix);
1080 void addCreateTextureCubemapActions (const string& suffix, GLenum internalFormat, GLenum format, GLenum type);
1081 void addCreateRenderbufferActions (void);
1082 void addCreateAndroidNativeActions (void);
1084 LabeledActions m_createActions;
1087 void ImageTests::addCreateTexture (const string& name, EGLenum source, GLenum internalFormat, GLenum format, GLenum type)
1089 m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createTextureImageSource(source, internalFormat, format, type))));
1092 void ImageTests::addCreateRenderbuffer (const string& name, GLenum format)
1094 m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createRenderbufferImageSource(format))));
1097 void ImageTests::addCreateAndroidNative (const string& name, GLenum format)
1099 m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createAndroidNativeImageSource(format))));
1102 void ImageTests::addCreateTexture2DActions (const string& prefix)
1104 addCreateTexture(prefix + "rgb8", EGL_GL_TEXTURE_2D_KHR, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
1105 addCreateTexture(prefix + "rgb565", EGL_GL_TEXTURE_2D_KHR, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
1106 addCreateTexture(prefix + "rgba8", EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1107 addCreateTexture(prefix + "rgb5_a1", EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
1108 addCreateTexture(prefix + "rgba4", EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
1111 void ImageTests::addCreateTextureCubemapActions (const string& suffix, GLenum internalFormat, GLenum format, GLenum type)
1113 addCreateTexture("cubemap_positive_x" + suffix, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR, internalFormat, format, type);
1114 addCreateTexture("cubemap_positive_y" + suffix, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR, internalFormat, format, type);
1115 addCreateTexture("cubemap_positive_z" + suffix, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR, internalFormat, format, type);
1116 addCreateTexture("cubemap_negative_x" + suffix, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR, internalFormat, format, type);
1117 addCreateTexture("cubemap_negative_y" + suffix, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR, internalFormat, format, type);
1118 addCreateTexture("cubemap_negative_z" + suffix, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR, internalFormat, format, type);
1121 void ImageTests::addCreateRenderbufferActions (void)
1123 addCreateRenderbuffer("renderbuffer_rgba4", GL_RGBA4);
1124 addCreateRenderbuffer("renderbuffer_rgb5_a1", GL_RGB5_A1);
1125 addCreateRenderbuffer("renderbuffer_rgb565", GL_RGB565);
1126 addCreateRenderbuffer("renderbuffer_depth16", GL_DEPTH_COMPONENT16);
1127 addCreateRenderbuffer("renderbuffer_stencil", GL_STENCIL_INDEX8);
1130 void ImageTests::addCreateAndroidNativeActions (void)
1132 addCreateAndroidNative("android_native_rgb565", GL_RGB565);
1133 addCreateAndroidNative("android_native_rgb8", GL_RGB8);
1134 addCreateAndroidNative("android_native_rgba4", GL_RGBA4);
1135 addCreateAndroidNative("android_native_rgb5_a1", GL_RGB5_A1);
1136 addCreateAndroidNative("android_native_rgba8", GL_RGBA8);
1139 class RenderTests : public ImageTests
1142 RenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1143 : ImageTests (eglTestCtx, name, desc) {}
1145 void addRenderActions (void);
1146 LabeledActions m_renderActions;
1149 void RenderTests::addRenderActions (void)
1151 m_renderActions.add("texture", MovePtr<Action>(new GLES2ImageApi::RenderTexture2D()));
1152 m_renderActions.add("read_pixels", MovePtr<Action>(new GLES2ImageApi::RenderReadPixelsRenderbuffer()));
1153 m_renderActions.add("depth_buffer", MovePtr<Action>(new GLES2ImageApi::RenderDepthbuffer()));
1154 m_renderActions.add("stencil_buffer", MovePtr<Action>(new GLES2ImageApi::RenderStencilbuffer()));
1157 class SimpleCreationTests : public RenderTests
1160 SimpleCreationTests (EglTestContext& eglTestCtx, const string& name, const string& desc) : RenderTests(eglTestCtx, name, desc) {}
1164 bool isDepthFormat (GLenum format)
1177 case GL_DEPTH_COMPONENT16:
1180 case GL_STENCIL_INDEX8:
1189 bool isStencilFormat (GLenum format)
1202 case GL_DEPTH_COMPONENT16:
1205 case GL_STENCIL_INDEX8:
1214 bool isCompatibleCreateAndRenderActions (const Action& create, const Action& render)
1216 if (const GLES2ImageApi::Create* gles2Create = dynamic_cast<const GLES2ImageApi::Create*>(&create))
1218 const GLenum createFormat = gles2Create->getEffectiveFormat();
1220 if (dynamic_cast<const GLES2ImageApi::RenderTexture2D*>(&render))
1222 // GLES2 does not have depth or stencil textures
1223 if (isDepthFormat(createFormat) || isStencilFormat(createFormat))
1227 if (dynamic_cast<const GLES2ImageApi::RenderReadPixelsRenderbuffer*>(&render))
1229 // GLES2 does not support readPixels for depth or stencil
1230 if (isDepthFormat(createFormat) || isStencilFormat(createFormat))
1234 if (dynamic_cast<const GLES2ImageApi::RenderDepthbuffer*>(&render))
1236 // Copying non-depth data to depth renderbuffer and expecting meaningful
1237 // results just doesn't make any sense.
1238 if (!isDepthFormat(createFormat))
1242 if (dynamic_cast<const GLES2ImageApi::RenderStencilbuffer*>(&render))
1244 // Copying non-stencil data to stencil renderbuffer and expecting meaningful
1245 // results just doesn't make any sense.
1246 if (!isStencilFormat(createFormat))
1258 void SimpleCreationTests::init (void)
1260 addCreateTexture2DActions("texture_");
1261 addCreateTextureCubemapActions("_rgba", GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1262 addCreateTextureCubemapActions("_rgb", GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
1263 addCreateRenderbufferActions();
1264 addCreateAndroidNativeActions();
1267 for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
1269 const LabeledAction& createAction = m_createActions[createNdx];
1271 for (int renderNdx = 0; renderNdx < m_renderActions.size(); renderNdx++)
1273 const LabeledAction& renderAction = m_renderActions[renderNdx];
1276 if (!isCompatibleCreateAndRenderActions(*createAction.action, *renderAction.action))
1279 spec.name = std::string("gles2_") + createAction.label + "_" + renderAction.label;
1280 spec.desc = spec.name;
1281 spec.contexts.push_back(TestSpec::API_GLES2);
1282 spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
1283 spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
1285 addChild(new ImageFormatCase(m_eglTestCtx, spec));
1290 TestCaseGroup* createSimpleCreationTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1292 return new SimpleCreationTests(eglTestCtx, name, desc);
1295 bool isCompatibleFormats (GLenum createFormat, GLenum modifyFormat, GLenum modifyType)
1297 switch (modifyFormat)
1302 case GL_UNSIGNED_BYTE:
1303 return createFormat == GL_RGB
1304 || createFormat == GL_RGB8
1305 || createFormat == GL_RGB565
1306 || createFormat == GL_SRGB8;
1309 return createFormat == GL_RGB8_SNORM;
1311 case GL_UNSIGNED_SHORT_5_6_5:
1312 return createFormat == GL_RGB
1313 || createFormat == GL_RGB565;
1315 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1316 return createFormat == GL_R11F_G11F_B10F;
1318 case GL_UNSIGNED_INT_5_9_9_9_REV:
1319 return createFormat == GL_RGB9_E5;
1322 return createFormat == GL_RGB16F
1323 || createFormat == GL_R11F_G11F_B10F
1324 || createFormat == GL_RGB9_E5;
1327 return createFormat == GL_RGB16F
1328 || createFormat == GL_RGB32F
1329 || createFormat == GL_R11F_G11F_B10F
1330 || createFormat == GL_RGB9_E5;
1333 DE_FATAL("Unknown modify type");
1340 case GL_UNSIGNED_BYTE:
1341 return createFormat == GL_RGBA8
1342 || createFormat == GL_RGB5_A1
1343 || createFormat == GL_RGBA4
1344 || createFormat == GL_SRGB8_ALPHA8
1345 || createFormat == GL_RGBA;
1347 case GL_UNSIGNED_SHORT_4_4_4_4:
1348 return createFormat == GL_RGBA4
1349 || createFormat == GL_RGBA;
1351 case GL_UNSIGNED_SHORT_5_5_5_1:
1352 return createFormat == GL_RGB5_A1
1353 || createFormat == GL_RGBA;
1355 case GL_UNSIGNED_INT_2_10_10_10_REV:
1356 return createFormat == GL_RGB10_A2
1357 || createFormat == GL_RGB5_A1;
1360 return createFormat == GL_RGBA16F;
1363 return createFormat == GL_RGBA16F
1364 || createFormat == GL_RGBA32F;
1367 DE_FATAL("Unknown modify type");
1372 DE_FATAL("Unknown modify format");
1377 bool isCompatibleCreateAndModifyActions (const Action& create, const Action& modify)
1379 if (const GLES2ImageApi::Create* gles2Create = dynamic_cast<const GLES2ImageApi::Create*>(&create))
1381 const GLenum createFormat = gles2Create->getEffectiveFormat();
1383 if (const GLES2ImageApi::ModifyTexSubImage* gles2TexSubImageModify = dynamic_cast<const GLES2ImageApi::ModifyTexSubImage*>(&modify))
1385 const GLenum modifyFormat = gles2TexSubImageModify->getFormat();
1386 const GLenum modifyType = gles2TexSubImageModify->getType();
1388 return isCompatibleFormats(createFormat, modifyFormat, modifyType);
1391 if (dynamic_cast<const GLES2ImageApi::ModifyRenderbufferClearColor*>(&modify))
1393 // reintepreting color as non-color is not meaningful
1394 if (isDepthFormat(createFormat) || isStencilFormat(createFormat))
1398 if (dynamic_cast<const GLES2ImageApi::ModifyRenderbufferClearDepth*>(&modify))
1400 // reintepreting depth as non-depth is not meaningful
1401 if (!isDepthFormat(createFormat))
1405 if (dynamic_cast<const GLES2ImageApi::ModifyRenderbufferClearStencil*>(&modify))
1407 // reintepreting stencil as non-stencil is not meaningful
1408 if (!isStencilFormat(createFormat))
1420 class MultiContextRenderTests : public RenderTests
1423 MultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc);
1425 void addClearActions (void);
1427 LabeledActions m_clearActions;
1430 MultiContextRenderTests::MultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1431 : RenderTests (eglTestCtx, name, desc)
1435 void MultiContextRenderTests::addClearActions (void)
1437 m_clearActions.add("renderbuffer_clear_color", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.8f, 0.2f, 0.9f, 1.0f))));
1438 m_clearActions.add("renderbuffer_clear_depth", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.75f)));
1439 m_clearActions.add("renderbuffer_clear_stencil", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(97)));
1442 void MultiContextRenderTests::init (void)
1444 addCreateTexture2DActions("texture_");
1445 addCreateTextureCubemapActions("_rgba8", GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1446 addCreateTextureCubemapActions("_rgb8", GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
1447 addCreateRenderbufferActions();
1448 addCreateAndroidNativeActions();
1452 for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
1453 for (int renderNdx = 0; renderNdx < m_renderActions.size(); renderNdx++)
1454 for (int clearNdx = 0; clearNdx < m_clearActions.size(); clearNdx++)
1456 const LabeledAction& createAction = m_createActions[createNdx];
1457 const LabeledAction& renderAction = m_renderActions[renderNdx];
1458 const LabeledAction& clearAction = m_clearActions[clearNdx];
1461 if (!isCompatibleCreateAndRenderActions(*createAction.action, *renderAction.action))
1463 if (!isCompatibleCreateAndModifyActions(*createAction.action, *clearAction.action))
1466 spec.name = std::string("gles2_") + createAction.label + "_" + renderAction.label;
1467 spec.desc = spec.name;
1469 spec.contexts.push_back(TestSpec::API_GLES2);
1470 spec.contexts.push_back(TestSpec::API_GLES2);
1472 spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
1473 spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
1474 spec.operations.push_back(TestSpec::Operation(0, *clearAction.action));
1475 spec.operations.push_back(TestSpec::Operation(1, *createAction.action));
1476 spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
1477 spec.operations.push_back(TestSpec::Operation(1, *renderAction.action));
1479 addChild(new ImageFormatCase(m_eglTestCtx, spec));
1483 TestCaseGroup* createMultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1485 return new MultiContextRenderTests(eglTestCtx, name, desc);
1488 class ModifyTests : public ImageTests
1491 ModifyTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1492 : ImageTests(eglTestCtx, name, desc) {}
1497 void addModifyActions(void);
1499 LabeledActions m_modifyActions;
1500 GLES2ImageApi::RenderTryAll m_renderAction;
1503 void ModifyTests::addModifyActions (void)
1505 m_modifyActions.add("tex_subimage_rgb8", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB, GL_UNSIGNED_BYTE)));
1506 m_modifyActions.add("tex_subimage_rgb565", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB, GL_UNSIGNED_SHORT_5_6_5)));
1507 m_modifyActions.add("tex_subimage_rgba8", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA, GL_UNSIGNED_BYTE)));
1508 m_modifyActions.add("tex_subimage_rgb5_a1", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1)));
1509 m_modifyActions.add("tex_subimage_rgba4", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4)));
1511 m_modifyActions.add("renderbuffer_clear_color", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.3f, 0.5f, 0.3f, 1.0f))));
1512 m_modifyActions.add("renderbuffer_clear_depth", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.7f)));
1513 m_modifyActions.add("renderbuffer_clear_stencil", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(78)));
1516 void ModifyTests::init (void)
1518 addCreateTexture2DActions("tex_");
1519 addCreateRenderbufferActions();
1520 addCreateAndroidNativeActions();
1523 for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
1525 LabeledAction& createAction = m_createActions[createNdx];
1527 for (int modifyNdx = 0; modifyNdx < m_modifyActions.size(); modifyNdx++)
1529 LabeledAction& modifyAction = m_modifyActions[modifyNdx];
1531 if (!isCompatibleCreateAndModifyActions(*createAction.action, *modifyAction.action))
1535 spec.name = createAction.label + "_" + modifyAction.label;
1536 spec.desc = "gles2_tex_sub_image";
1538 spec.contexts.push_back(TestSpec::API_GLES2);
1540 spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
1541 spec.operations.push_back(TestSpec::Operation(0, m_renderAction));
1542 spec.operations.push_back(TestSpec::Operation(0, *modifyAction.action));
1543 spec.operations.push_back(TestSpec::Operation(0, m_renderAction));
1545 addChild(new ImageFormatCase(m_eglTestCtx, spec));
1550 TestCaseGroup* createModifyTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1552 return new ModifyTests(eglTestCtx, name, desc);