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));
320 GLU_CHECK_GLW_CALL(api.m_gl, finish());
322 image = api.createImage(*m_imgSource, *buffer);
326 MovePtr<UniqueImage> GLES2ImageApi::createImage (const ImageSource& source, const ClientBuffer& buffer) const
328 const EGLImageKHR image = source.createImage(m_egl, m_display, m_context, buffer.get());
329 return MovePtr<UniqueImage>(new UniqueImage(m_egl, m_display, image));
332 static void imageTargetTexture2D (const Library& egl, const glw::Functions& gl, GLeglImageOES img)
334 gl.eglImageTargetTexture2DOES(GL_TEXTURE_2D, img);
336 const GLenum error = gl.getError();
338 if (error == GL_INVALID_OPERATION)
339 TCU_THROW(NotSupportedError, "Creating texture2D from EGLImage type not supported");
341 GLU_EXPECT_NO_ERROR(error, "glEGLImageTargetTexture2DOES()");
342 EGLU_CHECK_MSG(egl, "glEGLImageTargetTexture2DOES()");
346 static void imageTargetRenderbuffer (const Library& egl, const glw::Functions& gl, GLeglImageOES img)
348 gl.eglImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, img);
350 const GLenum error = gl.getError();
352 if (error == GL_INVALID_OPERATION)
353 TCU_THROW(NotSupportedError, "Creating renderbuffer from EGLImage type not supported");
355 GLU_EXPECT_NO_ERROR(error, "glEGLImageTargetRenderbufferStorageOES()");
356 EGLU_CHECK_MSG(egl, "glEGLImageTargetRenderbufferStorageOES()");
360 static void framebufferRenderbuffer (const glw::Functions& gl, GLenum attachment, GLuint rbo)
362 GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, rbo));
363 TCU_CHECK_AND_THROW(NotSupportedError,
364 gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE,
365 ("EGLImage as " + string(glu::getFramebufferAttachmentName(attachment)) + " not supported").c_str());
368 static const float squareTriangleCoords[] =
379 bool GLES2ImageApi::RenderTexture2D::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
381 const glw::Functions& gl = api.m_gl;
382 tcu::TestLog& log = api.getLog();
385 // Branch only taken in TryAll case
386 if (reference.getFormat().order == tcu::TextureFormat::DS || reference.getFormat().order == tcu::TextureFormat::D)
387 throw IllegalRendererException(); // Skip, GLES2 does not support sampling depth textures
388 if (reference.getFormat().order == tcu::TextureFormat::S)
389 throw IllegalRendererException(); // Skip, GLES2 does not support sampling stencil textures
391 gl.clearColor(0.0, 0.0, 0.0, 0.0);
392 gl.viewport(0, 0, reference.getWidth(), reference.getHeight());
393 gl.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
394 gl.disable(GL_DEPTH_TEST);
396 log << tcu::TestLog::Message << "Rendering EGLImage as GL_TEXTURE_2D in context: " << api.m_contextId << tcu::TestLog::EndMessage;
397 TCU_CHECK(**img != EGL_NO_IMAGE_KHR);
399 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, *srcTex));
400 imageTargetTexture2D(api.m_egl, gl, **img);
402 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
403 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
404 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
405 GLU_CHECK_GLW_CALL(gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
407 const char* const vertexShader =
408 "attribute highp vec2 a_coord;\n"
409 "varying mediump vec2 v_texCoord;\n"
410 "void main(void) {\n"
411 "\tv_texCoord = vec2((a_coord.x + 1.0) * 0.5, (a_coord.y + 1.0) * 0.5);\n"
412 "\tgl_Position = vec4(a_coord, -0.1, 1.0);\n"
415 const char* const fragmentShader =
416 "varying mediump vec2 v_texCoord;\n"
417 "uniform sampler2D u_sampler;\n"
418 "void main(void) {\n"
419 "\tmediump vec4 texColor = texture2D(u_sampler, v_texCoord);\n"
420 "\tgl_FragColor = vec4(texColor);\n"
423 Program program(gl, vertexShader, fragmentShader);
424 TCU_CHECK(program.isOk());
426 GLuint glProgram = program.getProgram();
427 GLU_CHECK_GLW_CALL(gl, useProgram(glProgram));
429 GLuint coordLoc = gl.getAttribLocation(glProgram, "a_coord");
430 TCU_CHECK_MSG((int)coordLoc != -1, "Couldn't find attribute a_coord");
432 GLuint samplerLoc = gl.getUniformLocation(glProgram, "u_sampler");
433 TCU_CHECK_MSG((int)samplerLoc != (int)-1, "Couldn't find uniform u_sampler");
435 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, *srcTex));
436 GLU_CHECK_GLW_CALL(gl, uniform1i(samplerLoc, 0));
437 GLU_CHECK_GLW_CALL(gl, enableVertexAttribArray(coordLoc));
438 GLU_CHECK_GLW_CALL(gl, vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, squareTriangleCoords));
440 GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
441 GLU_CHECK_GLW_CALL(gl, disableVertexAttribArray(coordLoc));
442 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, 0));
444 tcu::Surface refSurface (reference.getWidth(), reference.getHeight());
445 tcu::Surface screen (reference.getWidth(), reference.getHeight());
446 GLU_CHECK_GLW_CALL(gl, readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr()));
448 tcu::copy(refSurface.getAccess(), reference.getLevel(0));
450 float threshold = 0.05f;
451 bool match = tcu::fuzzyCompare(log, "ComparisonResult", "Image comparison result", refSurface, screen, threshold, tcu::COMPARE_LOG_RESULT);
456 bool GLES2ImageApi::RenderDepthbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
458 const glw::Functions& gl = api.m_gl;
459 tcu::TestLog& log = api.getLog();
460 Framebuffer framebuffer (gl);
461 Renderbuffer renderbufferColor (gl);
462 Renderbuffer renderbufferDepth (gl);
463 const tcu::RGBA compareThreshold (32, 32, 32, 32); // layer colors are far apart, large thresholds are ok
465 // Branch only taken in TryAll case
466 if (reference.getFormat().order != tcu::TextureFormat::DS && reference.getFormat().order != tcu::TextureFormat::D)
467 throw IllegalRendererException(); // Skip, interpreting non-depth data as depth data is not meaningful
469 log << tcu::TestLog::Message << "Rendering with depth buffer" << tcu::TestLog::EndMessage;
471 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
473 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferColor));
474 GLU_CHECK_GLW_CALL(gl, renderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, reference.getWidth(), reference.getHeight()));
475 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, *renderbufferColor);
477 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferDepth));
478 imageTargetRenderbuffer(api.m_egl, gl, **img);
479 framebufferRenderbuffer(gl, GL_DEPTH_ATTACHMENT, *renderbufferDepth);
480 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
482 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
485 const char* vertexShader =
486 "attribute highp vec2 a_coord;\n"
487 "uniform highp float u_depth;\n"
488 "void main(void) {\n"
489 "\tgl_Position = vec4(a_coord, u_depth, 1.0);\n"
492 const char* fragmentShader =
493 "uniform mediump vec4 u_color;\n"
494 "void main(void) {\n"
495 "\tgl_FragColor = u_color;\n"
498 Program program(gl, vertexShader, fragmentShader);
499 TCU_CHECK(program.isOk());
501 GLuint glProgram = program.getProgram();
502 GLU_CHECK_GLW_CALL(gl, useProgram(glProgram));
504 GLuint coordLoc = gl.getAttribLocation(glProgram, "a_coord");
505 TCU_CHECK_MSG((int)coordLoc != -1, "Couldn't find attribute a_coord");
507 GLuint colorLoc = gl.getUniformLocation(glProgram, "u_color");
508 TCU_CHECK_MSG((int)colorLoc != (int)-1, "Couldn't find uniform u_color");
510 GLuint depthLoc = gl.getUniformLocation(glProgram, "u_depth");
511 TCU_CHECK_MSG((int)depthLoc != (int)-1, "Couldn't find uniform u_depth");
513 GLU_CHECK_GLW_CALL(gl, clearColor(0.5f, 1.0f, 0.5f, 1.0f));
514 GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
516 tcu::Vec4 depthLevelColors[] = {
517 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
518 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
519 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
520 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
521 tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f),
523 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
524 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
525 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f),
526 tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f),
527 tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f)
530 GLU_CHECK_GLW_CALL(gl, enableVertexAttribArray(coordLoc));
531 GLU_CHECK_GLW_CALL(gl, vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, squareTriangleCoords));
533 GLU_CHECK_GLW_CALL(gl, enable(GL_DEPTH_TEST));
534 GLU_CHECK_GLW_CALL(gl, depthFunc(GL_LESS));
535 GLU_CHECK_GLW_CALL(gl, depthMask(GL_FALSE));
537 for (int level = 0; level < DE_LENGTH_OF_ARRAY(depthLevelColors); level++)
539 const tcu::Vec4 color = depthLevelColors[level];
540 const float clipDepth = ((float)(level + 1) * 0.1f) * 2.0f - 1.0f; // depth in clip coords
542 GLU_CHECK_GLW_CALL(gl, uniform4f(colorLoc, color.x(), color.y(), color.z(), color.w()));
543 GLU_CHECK_GLW_CALL(gl, uniform1f(depthLoc, clipDepth));
544 GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
547 GLU_CHECK_GLW_CALL(gl, depthMask(GL_TRUE));
548 GLU_CHECK_GLW_CALL(gl, disable(GL_DEPTH_TEST));
549 GLU_CHECK_GLW_CALL(gl, disableVertexAttribArray(coordLoc));
551 const ConstPixelBufferAccess& refAccess = reference.getLevel(0);
552 tcu::Surface screen (reference.getWidth(), reference.getHeight());
553 tcu::Surface referenceScreen (reference.getWidth(), reference.getHeight());
555 gl.readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr());
557 for (int y = 0; y < reference.getHeight(); y++)
559 for (int x = 0; x < reference.getWidth(); x++)
561 tcu::Vec4 result = tcu::Vec4(0.5f, 1.0f, 0.5f, 1.0f);
563 for (int level = 0; level < DE_LENGTH_OF_ARRAY(depthLevelColors); level++)
565 if ((float)(level + 1) * 0.1f < refAccess.getPixDepth(x, y))
566 result = depthLevelColors[level];
569 referenceScreen.getAccess().setPixel(result, x, y);
573 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
574 GLU_CHECK_GLW_CALL(gl, finish());
576 return tcu::pixelThresholdCompare(log, "Depth buffer rendering result", "Result from rendering with depth buffer", referenceScreen, screen, compareThreshold, tcu::COMPARE_LOG_RESULT);
579 bool GLES2ImageApi::RenderStencilbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
581 // Branch only taken in TryAll case
582 if (reference.getFormat().order != tcu::TextureFormat::DS && reference.getFormat().order != tcu::TextureFormat::S)
583 throw IllegalRendererException(); // Skip, interpreting non-stencil data as stencil data is not meaningful
585 const glw::Functions& gl = api.m_gl;
586 tcu::TestLog& log = api.getLog();
587 Framebuffer framebuffer (gl);
588 Renderbuffer renderbufferColor (gl);
589 Renderbuffer renderbufferStencil (gl);
590 const tcu::RGBA compareThreshold (32, 32, 32, 32); // layer colors are far apart, large thresholds are ok
591 const deUint32 numStencilBits = tcu::getTextureFormatBitDepth(tcu::getEffectiveDepthStencilTextureFormat(reference.getLevel(0).getFormat(), tcu::Sampler::MODE_STENCIL)).x();
592 const deUint32 maxStencil = deBitMask32(0, numStencilBits);
594 log << tcu::TestLog::Message << "Rendering with stencil buffer" << tcu::TestLog::EndMessage;
596 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
598 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferColor));
599 GLU_CHECK_GLW_CALL(gl, renderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, reference.getWidth(), reference.getHeight()));
600 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, *renderbufferColor);
602 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferStencil));
603 imageTargetRenderbuffer(api.m_egl, gl, **img);
604 framebufferRenderbuffer(gl, GL_STENCIL_ATTACHMENT, *renderbufferStencil);
605 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
607 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
610 const char* vertexShader =
611 "attribute highp vec2 a_coord;\n"
612 "void main(void) {\n"
613 "\tgl_Position = vec4(a_coord, 0.0, 1.0);\n"
616 const char* fragmentShader =
617 "uniform mediump vec4 u_color;\n"
618 "void main(void) {\n"
619 "\tgl_FragColor = u_color;\n"
622 Program program(gl, vertexShader, fragmentShader);
623 TCU_CHECK(program.isOk());
625 GLuint glProgram = program.getProgram();
626 GLU_CHECK_GLW_CALL(gl, useProgram(glProgram));
628 GLuint coordLoc = gl.getAttribLocation(glProgram, "a_coord");
629 TCU_CHECK_MSG((int)coordLoc != -1, "Couldn't find attribute a_coord");
631 GLuint colorLoc = gl.getUniformLocation(glProgram, "u_color");
632 TCU_CHECK_MSG((int)colorLoc != (int)-1, "Couldn't find uniform u_color");
634 GLU_CHECK_GLW_CALL(gl, clearColor(0.5f, 1.0f, 0.5f, 1.0f));
635 GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
637 tcu::Vec4 stencilLevelColors[] = {
638 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
639 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
640 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
641 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
642 tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f),
644 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
645 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
646 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f),
647 tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f),
648 tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f)
651 GLU_CHECK_GLW_CALL(gl, enableVertexAttribArray(coordLoc));
652 GLU_CHECK_GLW_CALL(gl, vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, squareTriangleCoords));
654 GLU_CHECK_GLW_CALL(gl, enable(GL_STENCIL_TEST));
655 GLU_CHECK_GLW_CALL(gl, stencilOp(GL_KEEP, GL_KEEP, GL_KEEP));
657 for (int level = 0; level < DE_LENGTH_OF_ARRAY(stencilLevelColors); level++)
659 const tcu::Vec4 color = stencilLevelColors[level];
660 const int stencil = (int)(((float)(level + 1) * 0.1f) * (float)maxStencil);
662 GLU_CHECK_GLW_CALL(gl, stencilFunc(GL_LESS, stencil, 0xFFFFFFFFu));
663 GLU_CHECK_GLW_CALL(gl, uniform4f(colorLoc, color.x(), color.y(), color.z(), color.w()));
664 GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
667 GLU_CHECK_GLW_CALL(gl, disable(GL_STENCIL_TEST));
668 GLU_CHECK_GLW_CALL(gl, disableVertexAttribArray(coordLoc));
670 const ConstPixelBufferAccess& refAccess = reference.getLevel(0);
671 tcu::Surface screen (reference.getWidth(), reference.getHeight());
672 tcu::Surface referenceScreen (reference.getWidth(), reference.getHeight());
674 gl.readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr());
676 for (int y = 0; y < reference.getHeight(); y++)
677 for (int x = 0; x < reference.getWidth(); x++)
679 tcu::Vec4 result = tcu::Vec4(0.5f, 1.0f, 0.5f, 1.0f);
681 for (int level = 0; level < DE_LENGTH_OF_ARRAY(stencilLevelColors); level++)
683 const int levelStencil = (int)(((float)(level + 1) * 0.1f) * (float)maxStencil);
684 if (levelStencil < refAccess.getPixStencil(x, y))
685 result = stencilLevelColors[level];
688 referenceScreen.getAccess().setPixel(result, x, y);
691 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
692 GLU_CHECK_GLW_CALL(gl, finish());
694 return tcu::pixelThresholdCompare(log, "StencilResult", "Result from rendering with stencil buffer", referenceScreen, screen, compareThreshold, tcu::COMPARE_LOG_RESULT);
697 bool GLES2ImageApi::RenderReadPixelsRenderbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
699 const glw::Functions& gl = api.m_gl;
700 const tcu::IVec4 bitDepth = tcu::getTextureFormatMantissaBitDepth(reference.getFormat());
701 const tcu::IVec4 threshold (2 * (tcu::IVec4(1) << (tcu::IVec4(8) - bitDepth)));
702 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)));
703 tcu::TestLog& log = api.getLog();
704 Framebuffer framebuffer (gl);
705 Renderbuffer renderbuffer (gl);
706 tcu::Surface screen (reference.getWidth(), reference.getHeight());
707 tcu::Surface refSurface (reference.getWidth(), reference.getHeight());
709 // Branch only taken in TryAll case
710 if (reference.getFormat().order == tcu::TextureFormat::DS || reference.getFormat().order == tcu::TextureFormat::D)
711 throw IllegalRendererException(); // Skip, GLES2 does not support ReadPixels for depth attachments
712 if (reference.getFormat().order == tcu::TextureFormat::S)
713 throw IllegalRendererException(); // Skip, GLES2 does not support ReadPixels for stencil attachments
715 log << tcu::TestLog::Message << "Reading with ReadPixels from renderbuffer" << tcu::TestLog::EndMessage;
717 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
718 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbuffer));
719 imageTargetRenderbuffer(api.m_egl, gl, **img);
720 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, *renderbuffer);
722 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
724 gl.readPixels(0, 0, screen.getWidth(), screen.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, screen.getAccess().getDataPtr());
726 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
727 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
728 GLU_CHECK_GLW_CALL(gl, finish());
730 tcu::copy(refSurface.getAccess(), reference.getLevel(0));
732 return tcu::pixelThresholdCompare(log, "Renderbuffer read", "Result from reading renderbuffer", refSurface, screen, threshold8, tcu::COMPARE_LOG_RESULT);
736 bool GLES2ImageApi::RenderTryAll::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
738 bool foundSupported = false;
739 tcu::TestLog& log = api.getLog();
740 GLES2ImageApi::RenderTexture2D renderTex2D;
741 GLES2ImageApi::RenderReadPixelsRenderbuffer renderReadPixels;
742 GLES2ImageApi::RenderDepthbuffer renderDepth;
743 GLES2ImageApi::RenderStencilbuffer renderStencil;
744 Action* actions[] = { &renderTex2D, &renderReadPixels, &renderDepth, &renderStencil };
746 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(actions); ++ndx)
750 if (!actions[ndx]->invoke(api, img, reference))
753 foundSupported = true;
755 catch (const tcu::NotSupportedError& error)
757 log << tcu::TestLog::Message << error.what() << tcu::TestLog::EndMessage;
759 catch (const IllegalRendererException&)
761 // not valid renderer
766 throw tcu::NotSupportedError("Rendering not supported", "", __FILE__, __LINE__);
771 bool GLES2ImageApi::ModifyTexSubImage::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
773 const glw::Functions& gl = api.m_gl;
774 tcu::TestLog& log = api.getLog();
775 glu::Texture srcTex (gl);
776 const int xOffset = 8;
777 const int yOffset = 16;
778 const int xSize = de::clamp(16, 0, reference.getWidth() - xOffset);
779 const int ySize = de::clamp(16, 0, reference.getHeight() - yOffset);
780 tcu::Texture2D src (glu::mapGLTransferFormat(m_format, m_type), xSize, ySize);
782 log << tcu::TestLog::Message << "Modifying EGLImage with gl.texSubImage2D" << tcu::TestLog::EndMessage;
785 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));
787 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, *srcTex));
788 imageTargetTexture2D(api.m_egl, gl, **img);
789 GLU_CHECK_GLW_CALL(gl, texSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, src.getWidth(), src.getHeight(), m_format, m_type, src.getLevel(0).getDataPtr()));
790 GLU_CHECK_GLW_CALL(gl, bindTexture(GL_TEXTURE_2D, 0));
791 GLU_CHECK_GLW_CALL(gl, finish());
793 tcu::copy(tcu::getSubregion(reference.getLevel(0), xOffset, yOffset, 0, xSize, ySize, 1), src.getLevel(0));
798 bool GLES2ImageApi::ModifyRenderbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
800 const glw::Functions& gl = api.m_gl;
801 tcu::TestLog& log = api.getLog();
802 glu::Framebuffer framebuffer (gl);
803 glu::Renderbuffer renderbuffer (gl);
805 log << tcu::TestLog::Message << "Modifying EGLImage with glClear to renderbuffer" << tcu::TestLog::EndMessage;
807 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
808 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbuffer));
810 imageTargetRenderbuffer(api.m_egl, gl, **img);
812 initializeRbo(api, *renderbuffer, reference);
814 GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
815 GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, 0));
817 GLU_CHECK_GLW_CALL(gl, finish());
822 void GLES2ImageApi::ModifyRenderbufferClearColor::initializeRbo (GLES2ImageApi& api, GLuint renderbuffer, tcu::Texture2D& reference) const
824 const glw::Functions& gl = api.m_gl;
826 framebufferRenderbuffer(gl, GL_COLOR_ATTACHMENT0, renderbuffer);
828 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
829 GLU_CHECK_GLW_CALL(gl, clearColor(m_color.x(), m_color.y(), m_color.z(), m_color.w()));
830 GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
832 tcu::clear(reference.getLevel(0), m_color);
835 void GLES2ImageApi::ModifyRenderbufferClearDepth::initializeRbo (GLES2ImageApi& api, GLuint renderbuffer, tcu::Texture2D& reference) const
837 const glw::Functions& gl = api.m_gl;
839 framebufferRenderbuffer(gl, GL_DEPTH_ATTACHMENT, renderbuffer);
841 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
842 GLU_CHECK_GLW_CALL(gl, clearDepthf(m_depth));
843 GLU_CHECK_GLW_CALL(gl, clear(GL_DEPTH_BUFFER_BIT));
845 tcu::clearDepth(reference.getLevel(0), m_depth);
848 void GLES2ImageApi::ModifyRenderbufferClearStencil::initializeRbo (GLES2ImageApi& api, GLuint renderbuffer, tcu::Texture2D& reference) const
850 const glw::Functions& gl = api.m_gl;
852 framebufferRenderbuffer(gl, GL_STENCIL_ATTACHMENT, renderbuffer);
854 GLU_CHECK_GLW_CALL(gl, viewport(0, 0, reference.getWidth(), reference.getHeight()));
855 GLU_CHECK_GLW_CALL(gl, clearStencil(m_stencil));
856 GLU_CHECK_GLW_CALL(gl, clear(GL_STENCIL_BUFFER_BIT));
858 tcu::clearStencil(reference.getLevel(0), m_stencil);
861 class ImageFormatCase : public TestCase, private glu::CallLogWrapper
864 ImageFormatCase (EglTestContext& eglTestCtx, const TestSpec& spec);
865 ~ImageFormatCase (void);
869 IterateResult iterate (void);
870 void checkExtensions (void);
873 EGLConfig getConfig (void);
875 const TestSpec m_spec;
877 vector<ImageApi*> m_apiContexts;
879 EGLDisplay m_display;
880 eglu::NativeWindow* m_window;
881 EGLSurface m_surface;
884 MovePtr<UniqueImage>m_img;
885 tcu::Texture2D m_refImg;
889 EGLConfig ImageFormatCase::getConfig (void)
891 const EGLint attribList[] =
893 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
894 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
903 return eglu::chooseSingleConfig(m_eglTestCtx.getLibrary(), m_display, attribList);
906 ImageFormatCase::ImageFormatCase (EglTestContext& eglTestCtx, const TestSpec& spec)
907 : TestCase (eglTestCtx, spec.name.c_str(), spec.desc.c_str())
908 , glu::CallLogWrapper (m_gl, eglTestCtx.getTestContext().getLog())
910 , m_display (EGL_NO_DISPLAY)
912 , m_surface (EGL_NO_SURFACE)
915 , m_refImg (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1)
919 ImageFormatCase::~ImageFormatCase (void)
924 void ImageFormatCase::checkExtensions (void)
926 const Library& egl = m_eglTestCtx.getLibrary();
927 const EGLDisplay dpy = m_display;
929 const vector<string> glExts = de::splitString((const char*) m_gl.getString(GL_EXTENSIONS));
930 const vector<string> eglExts = eglu::getDisplayExtensions(egl, dpy);
932 exts.insert(glExts.begin(), glExts.end());
933 exts.insert(eglExts.begin(), eglExts.end());
935 if (eglu::getVersion(egl, dpy) >= eglu::Version(1, 5))
937 // EGL 1.5 has built-in support for EGLImage and GL sources
938 exts.insert("EGL_KHR_image_base");
939 exts.insert("EGL_KHR_gl_texture_2D_image");
940 exts.insert("EGL_KHR_gl_texture_cubemap_image");
941 exts.insert("EGL_KHR_gl_renderbuffer_image");
944 if (!de::contains(exts, "EGL_KHR_image_base") && !de::contains(exts, "EGL_KHR_image"))
946 getLog() << tcu::TestLog::Message
947 << "EGL version is under 1.5 and neither EGL_KHR_image nor EGL_KHR_image_base is supported."
948 << "One should be supported."
949 << tcu::TestLog::EndMessage;
950 TCU_THROW(NotSupportedError, "Extension not supported: EGL_KHR_image_base");
953 for (int operationNdx = 0; operationNdx < (int)m_spec.operations.size(); operationNdx++)
955 const TestSpec::Operation& op = m_spec.operations[operationNdx];
956 const string ext = op.action->getRequiredExtension();
958 if (!de::contains(exts, ext))
959 TCU_THROW_EXPR(NotSupportedError, "Extension not supported", ext.c_str());
963 void ImageFormatCase::init (void)
965 const Library& egl = m_eglTestCtx.getLibrary();
966 const eglu::NativeWindowFactory& windowFactory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
970 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
971 m_config = getConfig();
972 m_window = windowFactory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_display, m_config, DE_NULL, eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
973 m_surface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_window, m_display, m_config, DE_NULL);
976 const char* extensions[] = { "GL_OES_EGL_image" };
977 m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0), DE_LENGTH_OF_ARRAY(extensions), &extensions[0]);
980 for (int contextNdx = 0; contextNdx < (int)m_spec.contexts.size(); contextNdx++)
982 ImageApi* api = DE_NULL;
983 switch (m_spec.contexts[contextNdx])
985 case TestSpec::API_GLES2:
987 api = new GLES2ImageApi(egl, m_gl, contextNdx, getLog(), m_display, m_surface, m_config);
995 m_apiContexts.push_back(api);
1006 void ImageFormatCase::deinit (void)
1008 const Library& egl = m_eglTestCtx.getLibrary();
1010 for (int contexNdx = 0 ; contexNdx < (int)m_apiContexts.size(); contexNdx++)
1011 delete m_apiContexts[contexNdx];
1013 m_apiContexts.clear();
1015 if (m_surface != EGL_NO_SURFACE)
1017 egl.destroySurface(m_display, m_surface);
1018 m_surface = EGL_NO_SURFACE;
1024 if (m_display != EGL_NO_DISPLAY)
1026 egl.terminate(m_display);
1027 m_display = EGL_NO_DISPLAY;
1031 TestCase::IterateResult ImageFormatCase::iterate (void)
1033 const TestSpec::Operation& op = m_spec.operations[m_curIter++];
1034 ImageApi& api = *m_apiContexts[op.apiIndex];
1035 const bool isOk = op.action->invoke(api, m_img, m_refImg);
1037 if (isOk && m_curIter < (int)m_spec.operations.size())
1040 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1042 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1047 struct LabeledAction
1050 MovePtr<Action> action;
1053 // A simple vector mockup that we need because MovePtr isn't copy-constructible.
1054 struct LabeledActions
1056 LabeledActions (void) : m_numActions(0){}
1057 LabeledAction& operator[] (int ndx) { DE_ASSERT(0 <= ndx && ndx < m_numActions); return m_actions[ndx]; }
1058 void add (const string& label, MovePtr<Action> action);
1059 int size (void) const { return m_numActions; }
1061 LabeledAction m_actions[32];
1065 void LabeledActions::add (const string& label, MovePtr<Action> action)
1067 DE_ASSERT(m_numActions < DE_LENGTH_OF_ARRAY(m_actions));
1068 m_actions[m_numActions].label = label;
1069 m_actions[m_numActions].action = action;
1073 class ImageTests : public TestCaseGroup
1076 ImageTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1077 : TestCaseGroup(eglTestCtx, name.c_str(), desc.c_str()) {}
1079 void addCreateTexture (const string& name, EGLenum source, GLenum internalFormat, GLenum format, GLenum type);
1080 void addCreateRenderbuffer (const string& name, GLenum format);
1081 void addCreateAndroidNative (const string& name, GLenum format);
1082 void addCreateTexture2DActions (const string& prefix);
1083 void addCreateTextureCubemapActions (const string& suffix, GLenum internalFormat, GLenum format, GLenum type);
1084 void addCreateRenderbufferActions (void);
1085 void addCreateAndroidNativeActions (void);
1087 LabeledActions m_createActions;
1090 void ImageTests::addCreateTexture (const string& name, EGLenum source, GLenum internalFormat, GLenum format, GLenum type)
1092 m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createTextureImageSource(source, internalFormat, format, type))));
1095 void ImageTests::addCreateRenderbuffer (const string& name, GLenum format)
1097 m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createRenderbufferImageSource(format))));
1100 void ImageTests::addCreateAndroidNative (const string& name, GLenum format)
1102 m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createAndroidNativeImageSource(format))));
1105 void ImageTests::addCreateTexture2DActions (const string& prefix)
1107 addCreateTexture(prefix + "rgb8", EGL_GL_TEXTURE_2D_KHR, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
1108 addCreateTexture(prefix + "rgb565", EGL_GL_TEXTURE_2D_KHR, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
1109 addCreateTexture(prefix + "rgba8", EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1110 addCreateTexture(prefix + "rgb5_a1", EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
1111 addCreateTexture(prefix + "rgba4", EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
1114 void ImageTests::addCreateTextureCubemapActions (const string& suffix, GLenum internalFormat, GLenum format, GLenum type)
1116 addCreateTexture("cubemap_positive_x" + suffix, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR, internalFormat, format, type);
1117 addCreateTexture("cubemap_positive_y" + suffix, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR, internalFormat, format, type);
1118 addCreateTexture("cubemap_positive_z" + suffix, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR, internalFormat, format, type);
1119 addCreateTexture("cubemap_negative_x" + suffix, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR, internalFormat, format, type);
1120 addCreateTexture("cubemap_negative_y" + suffix, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR, internalFormat, format, type);
1121 addCreateTexture("cubemap_negative_z" + suffix, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR, internalFormat, format, type);
1124 void ImageTests::addCreateRenderbufferActions (void)
1126 addCreateRenderbuffer("renderbuffer_rgba4", GL_RGBA4);
1127 addCreateRenderbuffer("renderbuffer_rgb5_a1", GL_RGB5_A1);
1128 addCreateRenderbuffer("renderbuffer_rgb565", GL_RGB565);
1129 addCreateRenderbuffer("renderbuffer_depth16", GL_DEPTH_COMPONENT16);
1130 addCreateRenderbuffer("renderbuffer_stencil", GL_STENCIL_INDEX8);
1133 void ImageTests::addCreateAndroidNativeActions (void)
1135 addCreateAndroidNative("android_native_rgb565", GL_RGB565);
1136 addCreateAndroidNative("android_native_rgb8", GL_RGB8);
1137 addCreateAndroidNative("android_native_rgba4", GL_RGBA4);
1138 addCreateAndroidNative("android_native_rgb5_a1", GL_RGB5_A1);
1139 addCreateAndroidNative("android_native_rgba8", GL_RGBA8);
1142 class RenderTests : public ImageTests
1145 RenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1146 : ImageTests (eglTestCtx, name, desc) {}
1148 void addRenderActions (void);
1149 LabeledActions m_renderActions;
1152 void RenderTests::addRenderActions (void)
1154 m_renderActions.add("texture", MovePtr<Action>(new GLES2ImageApi::RenderTexture2D()));
1155 m_renderActions.add("read_pixels", MovePtr<Action>(new GLES2ImageApi::RenderReadPixelsRenderbuffer()));
1156 m_renderActions.add("depth_buffer", MovePtr<Action>(new GLES2ImageApi::RenderDepthbuffer()));
1157 m_renderActions.add("stencil_buffer", MovePtr<Action>(new GLES2ImageApi::RenderStencilbuffer()));
1160 class SimpleCreationTests : public RenderTests
1163 SimpleCreationTests (EglTestContext& eglTestCtx, const string& name, const string& desc) : RenderTests(eglTestCtx, name, desc) {}
1167 bool isDepthFormat (GLenum format)
1180 case GL_DEPTH_COMPONENT16:
1183 case GL_STENCIL_INDEX8:
1192 bool isStencilFormat (GLenum format)
1205 case GL_DEPTH_COMPONENT16:
1208 case GL_STENCIL_INDEX8:
1217 bool isCompatibleCreateAndRenderActions (const Action& create, const Action& render)
1219 if (const GLES2ImageApi::Create* gles2Create = dynamic_cast<const GLES2ImageApi::Create*>(&create))
1221 const GLenum createFormat = gles2Create->getEffectiveFormat();
1223 if (dynamic_cast<const GLES2ImageApi::RenderTexture2D*>(&render))
1225 // GLES2 does not have depth or stencil textures
1226 if (isDepthFormat(createFormat) || isStencilFormat(createFormat))
1230 if (dynamic_cast<const GLES2ImageApi::RenderReadPixelsRenderbuffer*>(&render))
1232 // GLES2 does not support readPixels for depth or stencil
1233 if (isDepthFormat(createFormat) || isStencilFormat(createFormat))
1237 if (dynamic_cast<const GLES2ImageApi::RenderDepthbuffer*>(&render))
1239 // Copying non-depth data to depth renderbuffer and expecting meaningful
1240 // results just doesn't make any sense.
1241 if (!isDepthFormat(createFormat))
1245 if (dynamic_cast<const GLES2ImageApi::RenderStencilbuffer*>(&render))
1247 // Copying non-stencil data to stencil renderbuffer and expecting meaningful
1248 // results just doesn't make any sense.
1249 if (!isStencilFormat(createFormat))
1261 void SimpleCreationTests::init (void)
1263 addCreateTexture2DActions("texture_");
1264 addCreateTextureCubemapActions("_rgba", GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1265 addCreateTextureCubemapActions("_rgb", GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
1266 addCreateRenderbufferActions();
1267 addCreateAndroidNativeActions();
1270 for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
1272 const LabeledAction& createAction = m_createActions[createNdx];
1274 for (int renderNdx = 0; renderNdx < m_renderActions.size(); renderNdx++)
1276 const LabeledAction& renderAction = m_renderActions[renderNdx];
1279 if (!isCompatibleCreateAndRenderActions(*createAction.action, *renderAction.action))
1282 spec.name = std::string("gles2_") + createAction.label + "_" + renderAction.label;
1283 spec.desc = spec.name;
1284 spec.contexts.push_back(TestSpec::API_GLES2);
1285 spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
1286 spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
1288 addChild(new ImageFormatCase(m_eglTestCtx, spec));
1293 TestCaseGroup* createSimpleCreationTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1295 return new SimpleCreationTests(eglTestCtx, name, desc);
1298 bool isCompatibleFormats (GLenum createFormat, GLenum modifyFormat, GLenum modifyType)
1300 switch (modifyFormat)
1305 case GL_UNSIGNED_BYTE:
1306 return createFormat == GL_RGB
1307 || createFormat == GL_RGB8
1308 || createFormat == GL_RGB565
1309 || createFormat == GL_SRGB8;
1312 return createFormat == GL_RGB8_SNORM;
1314 case GL_UNSIGNED_SHORT_5_6_5:
1315 return createFormat == GL_RGB
1316 || createFormat == GL_RGB565;
1318 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1319 return createFormat == GL_R11F_G11F_B10F;
1321 case GL_UNSIGNED_INT_5_9_9_9_REV:
1322 return createFormat == GL_RGB9_E5;
1325 return createFormat == GL_RGB16F
1326 || createFormat == GL_R11F_G11F_B10F
1327 || createFormat == GL_RGB9_E5;
1330 return createFormat == GL_RGB16F
1331 || createFormat == GL_RGB32F
1332 || createFormat == GL_R11F_G11F_B10F
1333 || createFormat == GL_RGB9_E5;
1336 DE_FATAL("Unknown modify type");
1343 case GL_UNSIGNED_BYTE:
1344 return createFormat == GL_RGBA8
1345 || createFormat == GL_RGB5_A1
1346 || createFormat == GL_RGBA4
1347 || createFormat == GL_SRGB8_ALPHA8
1348 || createFormat == GL_RGBA;
1350 case GL_UNSIGNED_SHORT_4_4_4_4:
1351 return createFormat == GL_RGBA4
1352 || createFormat == GL_RGBA;
1354 case GL_UNSIGNED_SHORT_5_5_5_1:
1355 return createFormat == GL_RGB5_A1
1356 || createFormat == GL_RGBA;
1358 case GL_UNSIGNED_INT_2_10_10_10_REV:
1359 return createFormat == GL_RGB10_A2
1360 || createFormat == GL_RGB5_A1;
1363 return createFormat == GL_RGBA16F;
1366 return createFormat == GL_RGBA16F
1367 || createFormat == GL_RGBA32F;
1370 DE_FATAL("Unknown modify type");
1375 DE_FATAL("Unknown modify format");
1380 bool isCompatibleCreateAndModifyActions (const Action& create, const Action& modify)
1382 if (const GLES2ImageApi::Create* gles2Create = dynamic_cast<const GLES2ImageApi::Create*>(&create))
1384 const GLenum createFormat = gles2Create->getEffectiveFormat();
1386 if (const GLES2ImageApi::ModifyTexSubImage* gles2TexSubImageModify = dynamic_cast<const GLES2ImageApi::ModifyTexSubImage*>(&modify))
1388 const GLenum modifyFormat = gles2TexSubImageModify->getFormat();
1389 const GLenum modifyType = gles2TexSubImageModify->getType();
1391 return isCompatibleFormats(createFormat, modifyFormat, modifyType);
1394 if (dynamic_cast<const GLES2ImageApi::ModifyRenderbufferClearColor*>(&modify))
1396 // reintepreting color as non-color is not meaningful
1397 if (isDepthFormat(createFormat) || isStencilFormat(createFormat))
1401 if (dynamic_cast<const GLES2ImageApi::ModifyRenderbufferClearDepth*>(&modify))
1403 // reintepreting depth as non-depth is not meaningful
1404 if (!isDepthFormat(createFormat))
1408 if (dynamic_cast<const GLES2ImageApi::ModifyRenderbufferClearStencil*>(&modify))
1410 // reintepreting stencil as non-stencil is not meaningful
1411 if (!isStencilFormat(createFormat))
1423 class MultiContextRenderTests : public RenderTests
1426 MultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc);
1428 void addClearActions (void);
1430 LabeledActions m_clearActions;
1433 MultiContextRenderTests::MultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1434 : RenderTests (eglTestCtx, name, desc)
1438 void MultiContextRenderTests::addClearActions (void)
1440 m_clearActions.add("renderbuffer_clear_color", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.8f, 0.2f, 0.9f, 1.0f))));
1441 m_clearActions.add("renderbuffer_clear_depth", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.75f)));
1442 m_clearActions.add("renderbuffer_clear_stencil", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(97)));
1445 void MultiContextRenderTests::init (void)
1447 addCreateTexture2DActions("texture_");
1448 addCreateTextureCubemapActions("_rgba8", GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1449 addCreateTextureCubemapActions("_rgb8", GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
1450 addCreateRenderbufferActions();
1451 addCreateAndroidNativeActions();
1455 for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
1456 for (int renderNdx = 0; renderNdx < m_renderActions.size(); renderNdx++)
1457 for (int clearNdx = 0; clearNdx < m_clearActions.size(); clearNdx++)
1459 const LabeledAction& createAction = m_createActions[createNdx];
1460 const LabeledAction& renderAction = m_renderActions[renderNdx];
1461 const LabeledAction& clearAction = m_clearActions[clearNdx];
1464 if (!isCompatibleCreateAndRenderActions(*createAction.action, *renderAction.action))
1466 if (!isCompatibleCreateAndModifyActions(*createAction.action, *clearAction.action))
1469 spec.name = std::string("gles2_") + createAction.label + "_" + renderAction.label;
1470 spec.desc = spec.name;
1472 spec.contexts.push_back(TestSpec::API_GLES2);
1473 spec.contexts.push_back(TestSpec::API_GLES2);
1475 spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
1476 spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
1477 spec.operations.push_back(TestSpec::Operation(0, *clearAction.action));
1478 spec.operations.push_back(TestSpec::Operation(1, *createAction.action));
1479 spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
1480 spec.operations.push_back(TestSpec::Operation(1, *renderAction.action));
1482 addChild(new ImageFormatCase(m_eglTestCtx, spec));
1486 TestCaseGroup* createMultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1488 return new MultiContextRenderTests(eglTestCtx, name, desc);
1491 class ModifyTests : public ImageTests
1494 ModifyTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1495 : ImageTests(eglTestCtx, name, desc) {}
1500 void addModifyActions(void);
1502 LabeledActions m_modifyActions;
1503 GLES2ImageApi::RenderTryAll m_renderAction;
1506 void ModifyTests::addModifyActions (void)
1508 m_modifyActions.add("tex_subimage_rgb8", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB, GL_UNSIGNED_BYTE)));
1509 m_modifyActions.add("tex_subimage_rgb565", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB, GL_UNSIGNED_SHORT_5_6_5)));
1510 m_modifyActions.add("tex_subimage_rgba8", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA, GL_UNSIGNED_BYTE)));
1511 m_modifyActions.add("tex_subimage_rgb5_a1", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1)));
1512 m_modifyActions.add("tex_subimage_rgba4", MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4)));
1514 m_modifyActions.add("renderbuffer_clear_color", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.3f, 0.5f, 0.3f, 1.0f))));
1515 m_modifyActions.add("renderbuffer_clear_depth", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.7f)));
1516 m_modifyActions.add("renderbuffer_clear_stencil", MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(78)));
1519 void ModifyTests::init (void)
1521 addCreateTexture2DActions("tex_");
1522 addCreateRenderbufferActions();
1523 addCreateAndroidNativeActions();
1526 for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
1528 LabeledAction& createAction = m_createActions[createNdx];
1530 for (int modifyNdx = 0; modifyNdx < m_modifyActions.size(); modifyNdx++)
1532 LabeledAction& modifyAction = m_modifyActions[modifyNdx];
1534 if (!isCompatibleCreateAndModifyActions(*createAction.action, *modifyAction.action))
1538 spec.name = createAction.label + "_" + modifyAction.label;
1539 spec.desc = "gles2_tex_sub_image";
1541 spec.contexts.push_back(TestSpec::API_GLES2);
1543 spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
1544 spec.operations.push_back(TestSpec::Operation(0, m_renderAction));
1545 spec.operations.push_back(TestSpec::Operation(0, *modifyAction.action));
1546 spec.operations.push_back(TestSpec::Operation(0, m_renderAction));
1548 addChild(new ImageFormatCase(m_eglTestCtx, spec));
1553 TestCaseGroup* createModifyTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
1555 return new ModifyTests(eglTestCtx, name, desc);