xref: /aosp_15_r20/external/deqp/modules/egl/teglGLES2SharingTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program EGL Module
3*35238bceSAndroid Build Coastguard Worker  * ---------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief EGL gles2 sharing tests
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "teglGLES2SharingTests.hpp"
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "teglGLES2SharingThreadedTests.hpp"
27*35238bceSAndroid Build Coastguard Worker 
28*35238bceSAndroid Build Coastguard Worker #include "egluNativeWindow.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "egluUnique.hpp"
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
34*35238bceSAndroid Build Coastguard Worker 
35*35238bceSAndroid Build Coastguard Worker #include "tcuCommandLine.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
46*35238bceSAndroid Build Coastguard Worker #include "deMemory.h"
47*35238bceSAndroid Build Coastguard Worker #include "deString.h"
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
50*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
51*35238bceSAndroid Build Coastguard Worker 
52*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
53*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker #include <memory>
56*35238bceSAndroid Build Coastguard Worker #include <sstream>
57*35238bceSAndroid Build Coastguard Worker #include <vector>
58*35238bceSAndroid Build Coastguard Worker 
59*35238bceSAndroid Build Coastguard Worker using std::vector;
60*35238bceSAndroid Build Coastguard Worker 
61*35238bceSAndroid Build Coastguard Worker namespace deqp
62*35238bceSAndroid Build Coastguard Worker {
63*35238bceSAndroid Build Coastguard Worker namespace egl
64*35238bceSAndroid Build Coastguard Worker {
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker using namespace glw;
67*35238bceSAndroid Build Coastguard Worker using namespace eglw;
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker class GLES2SharingTest : public TestCase
70*35238bceSAndroid Build Coastguard Worker {
71*35238bceSAndroid Build Coastguard Worker public:
72*35238bceSAndroid Build Coastguard Worker     enum ResourceType
73*35238bceSAndroid Build Coastguard Worker     {
74*35238bceSAndroid Build Coastguard Worker         BUFFER = 0,
75*35238bceSAndroid Build Coastguard Worker         TEXTURE,
76*35238bceSAndroid Build Coastguard Worker         RENDERBUFFER,
77*35238bceSAndroid Build Coastguard Worker         SHADER_PROGRAM
78*35238bceSAndroid Build Coastguard Worker     };
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     struct TestSpec
81*35238bceSAndroid Build Coastguard Worker     {
82*35238bceSAndroid Build Coastguard Worker         ResourceType type;
83*35238bceSAndroid Build Coastguard Worker         bool destroyContextBFirst;
84*35238bceSAndroid Build Coastguard Worker         bool useResource;
85*35238bceSAndroid Build Coastguard Worker         bool destroyOnContexB;
86*35238bceSAndroid Build Coastguard Worker         bool initializeData;
87*35238bceSAndroid Build Coastguard Worker         bool renderOnContexA;
88*35238bceSAndroid Build Coastguard Worker         bool renderOnContexB;
89*35238bceSAndroid Build Coastguard Worker         bool verifyOnContexA;
90*35238bceSAndroid Build Coastguard Worker         bool verifyOnContexB;
91*35238bceSAndroid Build Coastguard Worker     };
92*35238bceSAndroid Build Coastguard Worker 
93*35238bceSAndroid Build Coastguard Worker     GLES2SharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc, const TestSpec &spec);
94*35238bceSAndroid Build Coastguard Worker 
95*35238bceSAndroid Build Coastguard Worker     void init(void);
96*35238bceSAndroid Build Coastguard Worker 
97*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
98*35238bceSAndroid Build Coastguard Worker 
99*35238bceSAndroid Build Coastguard Worker private:
100*35238bceSAndroid Build Coastguard Worker     TestSpec m_spec;
101*35238bceSAndroid Build Coastguard Worker 
102*35238bceSAndroid Build Coastguard Worker     EGLContext createContext(EGLDisplay display, EGLContext share, EGLConfig config);
103*35238bceSAndroid Build Coastguard Worker     void makeCurrent(EGLDisplay display, EGLContext context, EGLSurface surface);
104*35238bceSAndroid Build Coastguard Worker 
105*35238bceSAndroid Build Coastguard Worker protected:
106*35238bceSAndroid Build Coastguard Worker     de::Random m_random;
107*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &m_log;
108*35238bceSAndroid Build Coastguard Worker     glw::Functions m_gl;
109*35238bceSAndroid Build Coastguard Worker 
createResource(void)110*35238bceSAndroid Build Coastguard Worker     virtual void createResource(void)
111*35238bceSAndroid Build Coastguard Worker     {
112*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
113*35238bceSAndroid Build Coastguard Worker     }
destroyResource(void)114*35238bceSAndroid Build Coastguard Worker     virtual void destroyResource(void)
115*35238bceSAndroid Build Coastguard Worker     {
116*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
117*35238bceSAndroid Build Coastguard Worker     }
renderResource(tcu::Surface * screen,tcu::Surface * reference)118*35238bceSAndroid Build Coastguard Worker     virtual void renderResource(tcu::Surface *screen, tcu::Surface *reference)
119*35238bceSAndroid Build Coastguard Worker     {
120*35238bceSAndroid Build Coastguard Worker         DE_UNREF(screen);
121*35238bceSAndroid Build Coastguard Worker         DE_UNREF(reference);
122*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
123*35238bceSAndroid Build Coastguard Worker     }
124*35238bceSAndroid Build Coastguard Worker };
125*35238bceSAndroid Build Coastguard Worker 
GLES2SharingTest(EglTestContext & eglTestCtx,const char * name,const char * desc,const TestSpec & spec)126*35238bceSAndroid Build Coastguard Worker GLES2SharingTest::GLES2SharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc, const TestSpec &spec)
127*35238bceSAndroid Build Coastguard Worker     : TestCase(eglTestCtx, name, desc)
128*35238bceSAndroid Build Coastguard Worker     , m_spec(spec)
129*35238bceSAndroid Build Coastguard Worker     , m_random(deStringHash(name))
130*35238bceSAndroid Build Coastguard Worker     , m_log(eglTestCtx.getTestContext().getLog())
131*35238bceSAndroid Build Coastguard Worker {
132*35238bceSAndroid Build Coastguard Worker }
133*35238bceSAndroid Build Coastguard Worker 
init(void)134*35238bceSAndroid Build Coastguard Worker void GLES2SharingTest::init(void)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker     m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0));
137*35238bceSAndroid Build Coastguard Worker }
138*35238bceSAndroid Build Coastguard Worker 
createContext(EGLDisplay display,EGLContext share,EGLConfig config)139*35238bceSAndroid Build Coastguard Worker EGLContext GLES2SharingTest::createContext(EGLDisplay display, EGLContext share, EGLConfig config)
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker     const Library &egl        = m_eglTestCtx.getLibrary();
142*35238bceSAndroid Build Coastguard Worker     EGLContext context        = EGL_NO_CONTEXT;
143*35238bceSAndroid Build Coastguard Worker     const EGLint attriblist[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
144*35238bceSAndroid Build Coastguard Worker 
145*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker     context = egl.createContext(display, config, share, attriblist);
148*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_MSG(egl, "Failed to create GLES2 context");
149*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(context != EGL_NO_CONTEXT);
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker     return context;
152*35238bceSAndroid Build Coastguard Worker }
153*35238bceSAndroid Build Coastguard Worker 
makeCurrent(EGLDisplay display,EGLContext context,EGLSurface surface)154*35238bceSAndroid Build Coastguard Worker void GLES2SharingTest::makeCurrent(EGLDisplay display, EGLContext context, EGLSurface surface)
155*35238bceSAndroid Build Coastguard Worker {
156*35238bceSAndroid Build Coastguard Worker     const Library &egl = m_eglTestCtx.getLibrary();
157*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, context));
158*35238bceSAndroid Build Coastguard Worker }
159*35238bceSAndroid Build Coastguard Worker 
iterate(void)160*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult GLES2SharingTest::iterate(void)
161*35238bceSAndroid Build Coastguard Worker {
162*35238bceSAndroid Build Coastguard Worker     const Library &egl = m_eglTestCtx.getLibrary();
163*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log  = m_testCtx.getLog();
164*35238bceSAndroid Build Coastguard Worker     eglu::UniqueDisplay display(egl, eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay()));
165*35238bceSAndroid Build Coastguard Worker     const eglu::NativeWindowFactory &windowFactory =
166*35238bceSAndroid Build Coastguard Worker         eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
167*35238bceSAndroid Build Coastguard Worker     EGLConfig config;
168*35238bceSAndroid Build Coastguard Worker     bool isOk           = true;
169*35238bceSAndroid Build Coastguard Worker     EGLContext contextA = EGL_NO_CONTEXT;
170*35238bceSAndroid Build Coastguard Worker     EGLContext contextB = EGL_NO_CONTEXT;
171*35238bceSAndroid Build Coastguard Worker 
172*35238bceSAndroid Build Coastguard Worker     {
173*35238bceSAndroid Build Coastguard Worker         const EGLint attribList[] = {
174*35238bceSAndroid Build Coastguard Worker             EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_ALPHA_SIZE, 1, EGL_NONE};
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker         config = eglu::chooseSingleConfig(egl, *display, attribList);
177*35238bceSAndroid Build Coastguard Worker     }
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker     try
180*35238bceSAndroid Build Coastguard Worker     {
181*35238bceSAndroid Build Coastguard Worker         de::UniquePtr<eglu::NativeWindow> window(windowFactory.createWindow(
182*35238bceSAndroid Build Coastguard Worker             &m_eglTestCtx.getNativeDisplay(), *display, config, DE_NULL,
183*35238bceSAndroid Build Coastguard Worker             eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
184*35238bceSAndroid Build Coastguard Worker         eglu::UniqueSurface surface(
185*35238bceSAndroid Build Coastguard Worker             egl, *display,
186*35238bceSAndroid Build Coastguard Worker             eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, *display, config, DE_NULL));
187*35238bceSAndroid Build Coastguard Worker 
188*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << "Create context A (share_context = EGL_NO_CONTEXT)"
189*35238bceSAndroid Build Coastguard Worker               << tcu::TestLog::EndMessage;
190*35238bceSAndroid Build Coastguard Worker         contextA = createContext(*display, EGL_NO_CONTEXT, config);
191*35238bceSAndroid Build Coastguard Worker 
192*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << "Create context B (share_context = context A)" << tcu::TestLog::EndMessage;
193*35238bceSAndroid Build Coastguard Worker         contextB = createContext(*display, contextA, config);
194*35238bceSAndroid Build Coastguard Worker 
195*35238bceSAndroid Build Coastguard Worker         if (m_spec.useResource)
196*35238bceSAndroid Build Coastguard Worker         {
197*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << "Make current context A" << tcu::TestLog::EndMessage;
198*35238bceSAndroid Build Coastguard Worker             makeCurrent(*display, contextA, *surface);
199*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << "Creating resource" << tcu::TestLog::EndMessage;
200*35238bceSAndroid Build Coastguard Worker             createResource();
201*35238bceSAndroid Build Coastguard Worker 
202*35238bceSAndroid Build Coastguard Worker             int width  = 240;
203*35238bceSAndroid Build Coastguard Worker             int height = 240;
204*35238bceSAndroid Build Coastguard Worker 
205*35238bceSAndroid Build Coastguard Worker             if (m_spec.renderOnContexA)
206*35238bceSAndroid Build Coastguard Worker             {
207*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Render resource" << tcu::TestLog::EndMessage;
208*35238bceSAndroid Build Coastguard Worker                 if (m_spec.verifyOnContexA)
209*35238bceSAndroid Build Coastguard Worker                 {
210*35238bceSAndroid Build Coastguard Worker                     tcu::Surface screen(width, height);
211*35238bceSAndroid Build Coastguard Worker                     tcu::Surface ref(width, height);
212*35238bceSAndroid Build Coastguard Worker                     renderResource(&screen, &ref);
213*35238bceSAndroid Build Coastguard Worker 
214*35238bceSAndroid Build Coastguard Worker                     if (!fuzzyCompare(log, "Rendered image", "Rendering result comparision", ref, screen, 0.05f,
215*35238bceSAndroid Build Coastguard Worker                                       tcu::COMPARE_LOG_RESULT))
216*35238bceSAndroid Build Coastguard Worker                         isOk = false;
217*35238bceSAndroid Build Coastguard Worker                 }
218*35238bceSAndroid Build Coastguard Worker                 else
219*35238bceSAndroid Build Coastguard Worker                 {
220*35238bceSAndroid Build Coastguard Worker                     renderResource(DE_NULL, DE_NULL);
221*35238bceSAndroid Build Coastguard Worker                 }
222*35238bceSAndroid Build Coastguard Worker             }
223*35238bceSAndroid Build Coastguard Worker 
224*35238bceSAndroid Build Coastguard Worker             if (m_spec.renderOnContexB)
225*35238bceSAndroid Build Coastguard Worker             {
226*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Make current context B" << tcu::TestLog::EndMessage;
227*35238bceSAndroid Build Coastguard Worker                 makeCurrent(*display, contextB, *surface);
228*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Render resource" << tcu::TestLog::EndMessage;
229*35238bceSAndroid Build Coastguard Worker                 if (m_spec.verifyOnContexB)
230*35238bceSAndroid Build Coastguard Worker                 {
231*35238bceSAndroid Build Coastguard Worker                     tcu::Surface screen(width, height);
232*35238bceSAndroid Build Coastguard Worker                     tcu::Surface ref(width, height);
233*35238bceSAndroid Build Coastguard Worker                     renderResource(&screen, &ref);
234*35238bceSAndroid Build Coastguard Worker 
235*35238bceSAndroid Build Coastguard Worker                     if (!fuzzyCompare(log, "Rendered image", "Rendering result comparision", ref, screen, 0.05f,
236*35238bceSAndroid Build Coastguard Worker                                       tcu::COMPARE_LOG_RESULT))
237*35238bceSAndroid Build Coastguard Worker                         isOk = false;
238*35238bceSAndroid Build Coastguard Worker                 }
239*35238bceSAndroid Build Coastguard Worker                 else
240*35238bceSAndroid Build Coastguard Worker                 {
241*35238bceSAndroid Build Coastguard Worker                     renderResource(DE_NULL, DE_NULL);
242*35238bceSAndroid Build Coastguard Worker                 }
243*35238bceSAndroid Build Coastguard Worker             }
244*35238bceSAndroid Build Coastguard Worker 
245*35238bceSAndroid Build Coastguard Worker             if (m_spec.destroyOnContexB)
246*35238bceSAndroid Build Coastguard Worker             {
247*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Make current context B" << tcu::TestLog::EndMessage;
248*35238bceSAndroid Build Coastguard Worker                 makeCurrent(*display, contextB, *surface);
249*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Destroy resource" << tcu::TestLog::EndMessage;
250*35238bceSAndroid Build Coastguard Worker                 destroyResource();
251*35238bceSAndroid Build Coastguard Worker             }
252*35238bceSAndroid Build Coastguard Worker             else
253*35238bceSAndroid Build Coastguard Worker             {
254*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Make current context A" << tcu::TestLog::EndMessage;
255*35238bceSAndroid Build Coastguard Worker                 makeCurrent(*display, contextA, *surface);
256*35238bceSAndroid Build Coastguard Worker                 m_log << tcu::TestLog::Message << "Destroy resource" << tcu::TestLog::EndMessage;
257*35238bceSAndroid Build Coastguard Worker                 destroyResource();
258*35238bceSAndroid Build Coastguard Worker             }
259*35238bceSAndroid Build Coastguard Worker         }
260*35238bceSAndroid Build Coastguard Worker 
261*35238bceSAndroid Build Coastguard Worker         makeCurrent(*display, EGL_NO_CONTEXT, EGL_NO_SURFACE);
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker         if (m_spec.destroyContextBFirst)
264*35238bceSAndroid Build Coastguard Worker         {
265*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << "Destroy context B" << tcu::TestLog::EndMessage;
266*35238bceSAndroid Build Coastguard Worker             egl.destroyContext(*display, contextB);
267*35238bceSAndroid Build Coastguard Worker             contextB = EGL_NO_CONTEXT;
268*35238bceSAndroid Build Coastguard Worker 
269*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << "Destroy context A" << tcu::TestLog::EndMessage;
270*35238bceSAndroid Build Coastguard Worker             egl.destroyContext(*display, contextA);
271*35238bceSAndroid Build Coastguard Worker             contextA = EGL_NO_CONTEXT;
272*35238bceSAndroid Build Coastguard Worker         }
273*35238bceSAndroid Build Coastguard Worker         else
274*35238bceSAndroid Build Coastguard Worker         {
275*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << "Destroy context A" << tcu::TestLog::EndMessage;
276*35238bceSAndroid Build Coastguard Worker             egl.destroyContext(*display, contextA);
277*35238bceSAndroid Build Coastguard Worker             contextA = EGL_NO_CONTEXT;
278*35238bceSAndroid Build Coastguard Worker 
279*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << "Destroy context B" << tcu::TestLog::EndMessage;
280*35238bceSAndroid Build Coastguard Worker             egl.destroyContext(*display, contextB);
281*35238bceSAndroid Build Coastguard Worker             contextB = EGL_NO_CONTEXT;
282*35238bceSAndroid Build Coastguard Worker         }
283*35238bceSAndroid Build Coastguard Worker 
284*35238bceSAndroid Build Coastguard Worker         EGLU_CHECK(egl);
285*35238bceSAndroid Build Coastguard Worker     }
286*35238bceSAndroid Build Coastguard Worker     catch (...)
287*35238bceSAndroid Build Coastguard Worker     {
288*35238bceSAndroid Build Coastguard Worker         egl.makeCurrent(*display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
289*35238bceSAndroid Build Coastguard Worker         if (contextA != EGL_NO_CONTEXT)
290*35238bceSAndroid Build Coastguard Worker             egl.destroyContext(*display, contextA);
291*35238bceSAndroid Build Coastguard Worker         if (contextB != EGL_NO_CONTEXT)
292*35238bceSAndroid Build Coastguard Worker             egl.destroyContext(*display, contextB);
293*35238bceSAndroid Build Coastguard Worker         throw;
294*35238bceSAndroid Build Coastguard Worker     }
295*35238bceSAndroid Build Coastguard Worker 
296*35238bceSAndroid Build Coastguard Worker     if (isOk)
297*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
298*35238bceSAndroid Build Coastguard Worker     else
299*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
300*35238bceSAndroid Build Coastguard Worker 
301*35238bceSAndroid Build Coastguard Worker     return STOP;
302*35238bceSAndroid Build Coastguard Worker }
303*35238bceSAndroid Build Coastguard Worker 
304*35238bceSAndroid Build Coastguard Worker class GLES2BufferSharingTest : public GLES2SharingTest
305*35238bceSAndroid Build Coastguard Worker {
306*35238bceSAndroid Build Coastguard Worker public:
307*35238bceSAndroid Build Coastguard Worker     GLES2BufferSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
308*35238bceSAndroid Build Coastguard Worker                            const GLES2SharingTest::TestSpec &spec);
309*35238bceSAndroid Build Coastguard Worker 
310*35238bceSAndroid Build Coastguard Worker private:
311*35238bceSAndroid Build Coastguard Worker     GLuint m_glBuffer;
312*35238bceSAndroid Build Coastguard Worker     std::vector<GLubyte> m_buffer;
313*35238bceSAndroid Build Coastguard Worker 
314*35238bceSAndroid Build Coastguard Worker     virtual void createResource(void);
315*35238bceSAndroid Build Coastguard Worker     virtual void destroyResource(void);
316*35238bceSAndroid Build Coastguard Worker     virtual void renderResource(tcu::Surface *screen, tcu::Surface *reference);
317*35238bceSAndroid Build Coastguard Worker };
318*35238bceSAndroid Build Coastguard Worker 
GLES2BufferSharingTest(EglTestContext & eglTestCtx,const char * name,const char * desc,const GLES2SharingTest::TestSpec & spec)319*35238bceSAndroid Build Coastguard Worker GLES2BufferSharingTest::GLES2BufferSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
320*35238bceSAndroid Build Coastguard Worker                                                const GLES2SharingTest::TestSpec &spec)
321*35238bceSAndroid Build Coastguard Worker     : GLES2SharingTest(eglTestCtx, name, desc, spec)
322*35238bceSAndroid Build Coastguard Worker     , m_glBuffer(0)
323*35238bceSAndroid Build Coastguard Worker {
324*35238bceSAndroid Build Coastguard Worker }
325*35238bceSAndroid Build Coastguard Worker 
createResource(void)326*35238bceSAndroid Build Coastguard Worker void GLES2BufferSharingTest::createResource(void)
327*35238bceSAndroid Build Coastguard Worker {
328*35238bceSAndroid Build Coastguard Worker     int size = 16 * 16 * 4;
329*35238bceSAndroid Build Coastguard Worker 
330*35238bceSAndroid Build Coastguard Worker     m_buffer.reserve(size);
331*35238bceSAndroid Build Coastguard Worker 
332*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < size; i++)
333*35238bceSAndroid Build Coastguard Worker         m_buffer.push_back((GLubyte)m_random.getInt(0, 255));
334*35238bceSAndroid Build Coastguard Worker 
335*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, genBuffers(1, &m_glBuffer));
336*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindBuffer(GL_ARRAY_BUFFER, m_glBuffer));
337*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bufferData(GL_ARRAY_BUFFER, (GLsizei)(m_buffer.size() * sizeof(GLubyte)), &(m_buffer[0]),
338*35238bceSAndroid Build Coastguard Worker                                         GL_DYNAMIC_DRAW));
339*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindBuffer(GL_ARRAY_BUFFER, 0));
340*35238bceSAndroid Build Coastguard Worker }
341*35238bceSAndroid Build Coastguard Worker 
destroyResource(void)342*35238bceSAndroid Build Coastguard Worker void GLES2BufferSharingTest::destroyResource(void)
343*35238bceSAndroid Build Coastguard Worker {
344*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, deleteBuffers(1, &m_glBuffer));
345*35238bceSAndroid Build Coastguard Worker     m_buffer.clear();
346*35238bceSAndroid Build Coastguard Worker }
347*35238bceSAndroid Build Coastguard Worker 
renderResource(tcu::Surface * screen,tcu::Surface * reference)348*35238bceSAndroid Build Coastguard Worker void GLES2BufferSharingTest::renderResource(tcu::Surface *screen, tcu::Surface *reference)
349*35238bceSAndroid Build Coastguard Worker {
350*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((screen && reference) || (!screen && !reference));
351*35238bceSAndroid Build Coastguard Worker 
352*35238bceSAndroid Build Coastguard Worker     const char *vertexShader = ""
353*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec2 a_pos;\n"
354*35238bceSAndroid Build Coastguard Worker                                "attribute mediump float a_color;\n"
355*35238bceSAndroid Build Coastguard Worker                                "varying mediump float v_color;\n"
356*35238bceSAndroid Build Coastguard Worker                                "void main(void)\n"
357*35238bceSAndroid Build Coastguard Worker                                "{\n"
358*35238bceSAndroid Build Coastguard Worker                                "\tv_color = a_color;\n"
359*35238bceSAndroid Build Coastguard Worker                                "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
360*35238bceSAndroid Build Coastguard Worker                                "}\n";
361*35238bceSAndroid Build Coastguard Worker 
362*35238bceSAndroid Build Coastguard Worker     const char *fragmentShader = ""
363*35238bceSAndroid Build Coastguard Worker                                  "varying mediump float v_color;\n"
364*35238bceSAndroid Build Coastguard Worker                                  "void main(void)\n"
365*35238bceSAndroid Build Coastguard Worker                                  "{\n"
366*35238bceSAndroid Build Coastguard Worker                                  "\tgl_FragColor = vec4(v_color, v_color, v_color, 1.0);\n"
367*35238bceSAndroid Build Coastguard Worker                                  "}\n";
368*35238bceSAndroid Build Coastguard Worker 
369*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgram program(m_gl, glu::makeVtxFragSources(vertexShader, fragmentShader));
370*35238bceSAndroid Build Coastguard Worker 
371*35238bceSAndroid Build Coastguard Worker     if (!program.isOk())
372*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shader program");
373*35238bceSAndroid Build Coastguard Worker 
374*35238bceSAndroid Build Coastguard Worker     std::vector<uint16_t> indices;
375*35238bceSAndroid Build Coastguard Worker     std::vector<float> coords;
376*35238bceSAndroid Build Coastguard Worker 
377*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_buffer.size() % 4 == 0);
378*35238bceSAndroid Build Coastguard Worker 
379*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < (int)m_buffer.size() / 4; i++)
380*35238bceSAndroid Build Coastguard Worker     {
381*35238bceSAndroid Build Coastguard Worker         indices.push_back((uint16_t)(i * 4));
382*35238bceSAndroid Build Coastguard Worker         indices.push_back((uint16_t)(i * 4 + 1));
383*35238bceSAndroid Build Coastguard Worker         indices.push_back((uint16_t)(i * 4 + 2));
384*35238bceSAndroid Build Coastguard Worker         indices.push_back((uint16_t)(i * 4 + 2));
385*35238bceSAndroid Build Coastguard Worker         indices.push_back((uint16_t)(i * 4 + 3));
386*35238bceSAndroid Build Coastguard Worker         indices.push_back((uint16_t)(i * 4));
387*35238bceSAndroid Build Coastguard Worker 
388*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)(i % 16) - 1.0f);
389*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)((int)((float)i / 16.0f)) - 1.0f);
390*35238bceSAndroid Build Coastguard Worker 
391*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)(i % 16) - 1.0f);
392*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)((int)((float)i / 16.0f) + 1) - 1.0f);
393*35238bceSAndroid Build Coastguard Worker 
394*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)((i % 16) + 1) - 1.0f);
395*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)((int)((float)i / 16.0f) + 1) - 1.0f);
396*35238bceSAndroid Build Coastguard Worker 
397*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)((i % 16) + 1) - 1.0f);
398*35238bceSAndroid Build Coastguard Worker         coords.push_back(0.125f * (float)((int)((float)i / 16.0f)) - 1.0f);
399*35238bceSAndroid Build Coastguard Worker     }
400*35238bceSAndroid Build Coastguard Worker 
401*35238bceSAndroid Build Coastguard Worker     int width  = 240;
402*35238bceSAndroid Build Coastguard Worker     int height = 240;
403*35238bceSAndroid Build Coastguard Worker 
404*35238bceSAndroid Build Coastguard Worker     if (screen)
405*35238bceSAndroid Build Coastguard Worker     {
406*35238bceSAndroid Build Coastguard Worker         width  = screen->getWidth();
407*35238bceSAndroid Build Coastguard Worker         height = screen->getHeight();
408*35238bceSAndroid Build Coastguard Worker     }
409*35238bceSAndroid Build Coastguard Worker 
410*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, viewport(0, 0, width, height));
411*35238bceSAndroid Build Coastguard Worker 
412*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clearColor(1.0f, 0.0f, 0.0f, 1.0f));
413*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clear(GL_COLOR_BUFFER_BIT));
414*35238bceSAndroid Build Coastguard Worker 
415*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(program.getProgram()));
416*35238bceSAndroid Build Coastguard Worker 
417*35238bceSAndroid Build Coastguard Worker     GLuint gridLocation = m_gl.getAttribLocation(program.getProgram(), "a_pos");
418*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
419*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(gridLocation != (GLuint)-1);
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker     GLuint colorLocation = m_gl.getAttribLocation(program.getProgram(), "a_color");
422*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
423*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(colorLocation != (GLuint)-1);
424*35238bceSAndroid Build Coastguard Worker 
425*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(colorLocation));
426*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(gridLocation));
427*35238bceSAndroid Build Coastguard Worker 
428*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindBuffer(GL_ARRAY_BUFFER, m_glBuffer));
429*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(colorLocation, 1, GL_UNSIGNED_BYTE, GL_TRUE, 0, DE_NULL));
430*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindBuffer(GL_ARRAY_BUFFER, 0));
431*35238bceSAndroid Build Coastguard Worker 
432*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(gridLocation, 2, GL_FLOAT, GL_FALSE, 0, &(coords[0])));
433*35238bceSAndroid Build Coastguard Worker 
434*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, drawElements(GL_TRIANGLES, (GLsizei)indices.size(), GL_UNSIGNED_SHORT, &(indices[0])));
435*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(colorLocation));
436*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(gridLocation));
437*35238bceSAndroid Build Coastguard Worker 
438*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(0));
439*35238bceSAndroid Build Coastguard Worker 
440*35238bceSAndroid Build Coastguard Worker     if (screen)
441*35238bceSAndroid Build Coastguard Worker     {
442*35238bceSAndroid Build Coastguard Worker         tcu::clear(reference->getAccess(), tcu::IVec4(0xff, 0, 0, 0xff));
443*35238bceSAndroid Build Coastguard Worker         m_gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
444*35238bceSAndroid Build Coastguard Worker                         screen->getAccess().getDataPtr());
445*35238bceSAndroid Build Coastguard Worker         for (int i = 0; i < (int)m_buffer.size() / 4; i++)
446*35238bceSAndroid Build Coastguard Worker         {
447*35238bceSAndroid Build Coastguard Worker             float fx1 = 0.125f * (float)(i % 16) - 1.0f;
448*35238bceSAndroid Build Coastguard Worker             float fy1 = 0.125f * (float)((int)((float)i / 16.0f)) - 1.0f;
449*35238bceSAndroid Build Coastguard Worker             float fx2 = 0.125f * (float)((i % 16) + 1) - 1.0f;
450*35238bceSAndroid Build Coastguard Worker             float fy2 = 0.125f * (float)((int)((float)i / 16.0f) + 1) - 1.0f;
451*35238bceSAndroid Build Coastguard Worker 
452*35238bceSAndroid Build Coastguard Worker             int ox = deRoundFloatToInt32((float)width / 2.0f);
453*35238bceSAndroid Build Coastguard Worker             int oy = deRoundFloatToInt32((float)height / 2.0f);
454*35238bceSAndroid Build Coastguard Worker             int x1 = deRoundFloatToInt32(((float)width * fx1 / 2.0f) + (float)ox);
455*35238bceSAndroid Build Coastguard Worker             int y1 = deRoundFloatToInt32(((float)height * fy1 / 2.0f) + (float)oy);
456*35238bceSAndroid Build Coastguard Worker             int x2 = deRoundFloatToInt32(((float)width * fx2 / 2.0f) + (float)ox);
457*35238bceSAndroid Build Coastguard Worker             int y2 = deRoundFloatToInt32(((float)height * fy2 / 2.0f) + (float)oy);
458*35238bceSAndroid Build Coastguard Worker 
459*35238bceSAndroid Build Coastguard Worker             for (int x = x1; x < x2; x++)
460*35238bceSAndroid Build Coastguard Worker             {
461*35238bceSAndroid Build Coastguard Worker                 for (int y = y1; y < y2; y++)
462*35238bceSAndroid Build Coastguard Worker                 {
463*35238bceSAndroid Build Coastguard Worker                     float xf  = ((float)(x - x1) + 0.5f) / (float)(x2 - x1);
464*35238bceSAndroid Build Coastguard Worker                     float yf  = ((float)(y - y1) + 0.5f) / (float)(y2 - y1);
465*35238bceSAndroid Build Coastguard Worker                     bool tri  = yf >= xf;
466*35238bceSAndroid Build Coastguard Worker                     uint8_t a = m_buffer[i * 4 + (tri ? 1 : 3)];
467*35238bceSAndroid Build Coastguard Worker                     uint8_t b = m_buffer[i * 4 + (tri ? 2 : 0)];
468*35238bceSAndroid Build Coastguard Worker                     uint8_t c = m_buffer[i * 4 + (tri ? 0 : 2)];
469*35238bceSAndroid Build Coastguard Worker                     float s   = tri ? xf : 1.0f - xf;
470*35238bceSAndroid Build Coastguard Worker                     float t   = tri ? 1.0f - yf : yf;
471*35238bceSAndroid Build Coastguard Worker                     float val = (float)a + (float)(b - a) * s + (float)(c - a) * t;
472*35238bceSAndroid Build Coastguard Worker 
473*35238bceSAndroid Build Coastguard Worker                     reference->setPixel(x, y, tcu::RGBA((uint8_t)val, (uint8_t)val, (uint8_t)val, 255));
474*35238bceSAndroid Build Coastguard Worker                 }
475*35238bceSAndroid Build Coastguard Worker             }
476*35238bceSAndroid Build Coastguard Worker         }
477*35238bceSAndroid Build Coastguard Worker     }
478*35238bceSAndroid Build Coastguard Worker }
479*35238bceSAndroid Build Coastguard Worker 
480*35238bceSAndroid Build Coastguard Worker class GLES2TextureSharingTest : public GLES2SharingTest
481*35238bceSAndroid Build Coastguard Worker {
482*35238bceSAndroid Build Coastguard Worker public:
483*35238bceSAndroid Build Coastguard Worker     GLES2TextureSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
484*35238bceSAndroid Build Coastguard Worker                             const GLES2SharingTest::TestSpec &spec, bool asColorAttachment);
485*35238bceSAndroid Build Coastguard Worker 
486*35238bceSAndroid Build Coastguard Worker private:
487*35238bceSAndroid Build Coastguard Worker     GLuint m_glTexture;
488*35238bceSAndroid Build Coastguard Worker     tcu::Texture2D m_texture;
489*35238bceSAndroid Build Coastguard Worker     bool m_glTextureAsColorAttachment;
490*35238bceSAndroid Build Coastguard Worker 
491*35238bceSAndroid Build Coastguard Worker     virtual void createResource(void);
492*35238bceSAndroid Build Coastguard Worker     virtual void destroyResource(void);
493*35238bceSAndroid Build Coastguard Worker     virtual void renderResource(tcu::Surface *screen, tcu::Surface *reference);
494*35238bceSAndroid Build Coastguard Worker };
495*35238bceSAndroid Build Coastguard Worker 
GLES2TextureSharingTest(EglTestContext & eglTestCtx,const char * name,const char * desc,const GLES2SharingTest::TestSpec & spec,bool asColorAttachment)496*35238bceSAndroid Build Coastguard Worker GLES2TextureSharingTest::GLES2TextureSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
497*35238bceSAndroid Build Coastguard Worker                                                  const GLES2SharingTest::TestSpec &spec, bool asColorAttachment)
498*35238bceSAndroid Build Coastguard Worker     : GLES2SharingTest(eglTestCtx, name, desc, spec)
499*35238bceSAndroid Build Coastguard Worker     , m_glTexture(0)
500*35238bceSAndroid Build Coastguard Worker     , m_texture(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1)
501*35238bceSAndroid Build Coastguard Worker     , m_glTextureAsColorAttachment(asColorAttachment)
502*35238bceSAndroid Build Coastguard Worker {
503*35238bceSAndroid Build Coastguard Worker }
504*35238bceSAndroid Build Coastguard Worker 
createResource(void)505*35238bceSAndroid Build Coastguard Worker void GLES2TextureSharingTest::createResource(void)
506*35238bceSAndroid Build Coastguard Worker {
507*35238bceSAndroid Build Coastguard Worker     int width  = 128;
508*35238bceSAndroid Build Coastguard Worker     int height = 128;
509*35238bceSAndroid Build Coastguard Worker     m_texture =
510*35238bceSAndroid Build Coastguard Worker         tcu::Texture2D(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), width, height);
511*35238bceSAndroid Build Coastguard Worker     m_texture.allocLevel(0);
512*35238bceSAndroid Build Coastguard Worker 
513*35238bceSAndroid Build Coastguard Worker     tcu::fillWithComponentGradients(m_texture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
514*35238bceSAndroid Build Coastguard Worker                                     tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
515*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, genTextures(1, &m_glTexture));
516*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindTexture(GL_TEXTURE_2D, m_glTexture));
517*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
518*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
519*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
520*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
521*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
522*35238bceSAndroid Build Coastguard Worker                                         m_texture.getLevel(0).getDataPtr()));
523*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindTexture(GL_TEXTURE_2D, 0));
524*35238bceSAndroid Build Coastguard Worker }
525*35238bceSAndroid Build Coastguard Worker 
destroyResource(void)526*35238bceSAndroid Build Coastguard Worker void GLES2TextureSharingTest::destroyResource(void)
527*35238bceSAndroid Build Coastguard Worker {
528*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, deleteTextures(1, &m_glTexture));
529*35238bceSAndroid Build Coastguard Worker }
530*35238bceSAndroid Build Coastguard Worker 
renderResource(tcu::Surface * screen,tcu::Surface * reference)531*35238bceSAndroid Build Coastguard Worker void GLES2TextureSharingTest::renderResource(tcu::Surface *screen, tcu::Surface *reference)
532*35238bceSAndroid Build Coastguard Worker {
533*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((screen && reference) || (!screen && !reference));
534*35238bceSAndroid Build Coastguard Worker 
535*35238bceSAndroid Build Coastguard Worker     const char *vertexShader = ""
536*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec2 a_pos;\n"
537*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec2 a_texCorod;\n"
538*35238bceSAndroid Build Coastguard Worker                                "varying mediump vec2 v_texCoord;\n"
539*35238bceSAndroid Build Coastguard Worker                                "void main(void)\n"
540*35238bceSAndroid Build Coastguard Worker                                "{\n"
541*35238bceSAndroid Build Coastguard Worker                                "\tv_texCoord = a_texCorod;\n"
542*35238bceSAndroid Build Coastguard Worker                                "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
543*35238bceSAndroid Build Coastguard Worker                                "}\n";
544*35238bceSAndroid Build Coastguard Worker 
545*35238bceSAndroid Build Coastguard Worker     const char *fragmentShader = ""
546*35238bceSAndroid Build Coastguard Worker                                  "varying mediump vec2 v_texCoord;\n"
547*35238bceSAndroid Build Coastguard Worker                                  "uniform sampler2D u_sampler;\n"
548*35238bceSAndroid Build Coastguard Worker                                  "void main(void)\n"
549*35238bceSAndroid Build Coastguard Worker                                  "{\n"
550*35238bceSAndroid Build Coastguard Worker                                  "\tgl_FragColor = texture2D(u_sampler, v_texCoord);\n"
551*35238bceSAndroid Build Coastguard Worker                                  "}\n";
552*35238bceSAndroid Build Coastguard Worker 
553*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgram program(m_gl, glu::makeVtxFragSources(vertexShader, fragmentShader));
554*35238bceSAndroid Build Coastguard Worker 
555*35238bceSAndroid Build Coastguard Worker     if (!program.isOk())
556*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shader program");
557*35238bceSAndroid Build Coastguard Worker 
558*35238bceSAndroid Build Coastguard Worker     int width  = 240;
559*35238bceSAndroid Build Coastguard Worker     int height = 240;
560*35238bceSAndroid Build Coastguard Worker 
561*35238bceSAndroid Build Coastguard Worker     if (screen)
562*35238bceSAndroid Build Coastguard Worker     {
563*35238bceSAndroid Build Coastguard Worker         width  = screen->getWidth();
564*35238bceSAndroid Build Coastguard Worker         height = screen->getHeight();
565*35238bceSAndroid Build Coastguard Worker     }
566*35238bceSAndroid Build Coastguard Worker 
567*35238bceSAndroid Build Coastguard Worker     static const GLfloat coords[] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f};
568*35238bceSAndroid Build Coastguard Worker 
569*35238bceSAndroid Build Coastguard Worker     static const GLfloat texCoords[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
570*35238bceSAndroid Build Coastguard Worker 
571*35238bceSAndroid Build Coastguard Worker     static const GLushort indices[] = {0, 1, 2, 2, 3, 0};
572*35238bceSAndroid Build Coastguard Worker 
573*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, viewport(0, 0, width, height));
574*35238bceSAndroid Build Coastguard Worker 
575*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clearColor(1.0f, 0.0f, 0.0f, 1.0f));
576*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clear(GL_COLOR_BUFFER_BIT));
577*35238bceSAndroid Build Coastguard Worker 
578*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(program.getProgram()));
579*35238bceSAndroid Build Coastguard Worker 
580*35238bceSAndroid Build Coastguard Worker     GLuint coordLocation = m_gl.getAttribLocation(program.getProgram(), "a_pos");
581*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
582*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(coordLocation != (GLuint)-1);
583*35238bceSAndroid Build Coastguard Worker 
584*35238bceSAndroid Build Coastguard Worker     GLuint texCoordLocation = m_gl.getAttribLocation(program.getProgram(), "a_texCorod");
585*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
586*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(texCoordLocation != (GLuint)-1);
587*35238bceSAndroid Build Coastguard Worker 
588*35238bceSAndroid Build Coastguard Worker     GLuint samplerLocation = m_gl.getUniformLocation(program.getProgram(), "u_sampler");
589*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetUniformLocation()");
590*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(samplerLocation != (GLuint)-1);
591*35238bceSAndroid Build Coastguard Worker 
592*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, activeTexture(GL_TEXTURE0));
593*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindTexture(GL_TEXTURE_2D, m_glTexture));
594*35238bceSAndroid Build Coastguard Worker 
595*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, uniform1i(samplerLocation, 0));
596*35238bceSAndroid Build Coastguard Worker     if (!m_glTextureAsColorAttachment)
597*35238bceSAndroid Build Coastguard Worker     {
598*35238bceSAndroid Build Coastguard Worker 
599*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(texCoordLocation));
600*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(coordLocation));
601*35238bceSAndroid Build Coastguard Worker 
602*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texCoords));
603*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, coords));
604*35238bceSAndroid Build Coastguard Worker 
605*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices));
606*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(coordLocation));
607*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(texCoordLocation));
608*35238bceSAndroid Build Coastguard Worker 
609*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, bindTexture(GL_TEXTURE_2D, 0));
610*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, useProgram(0));
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker         if (screen)
613*35238bceSAndroid Build Coastguard Worker         {
614*35238bceSAndroid Build Coastguard Worker             m_gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
615*35238bceSAndroid Build Coastguard Worker                             screen->getAccess().getDataPtr());
616*35238bceSAndroid Build Coastguard Worker 
617*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < width; x++)
618*35238bceSAndroid Build Coastguard Worker             {
619*35238bceSAndroid Build Coastguard Worker                 for (int y = 0; y < height; y++)
620*35238bceSAndroid Build Coastguard Worker                 {
621*35238bceSAndroid Build Coastguard Worker                     float t   = ((float)x / ((float)width - 1.0f));
622*35238bceSAndroid Build Coastguard Worker                     float s   = ((float)y / ((float)height - 1.0f));
623*35238bceSAndroid Build Coastguard Worker                     float lod = 0.0f;
624*35238bceSAndroid Build Coastguard Worker 
625*35238bceSAndroid Build Coastguard Worker                     tcu::Vec4 color = m_texture.sample(tcu::Sampler(tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL,
626*35238bceSAndroid Build Coastguard Worker                                                                     tcu::Sampler::REPEAT_GL, tcu::Sampler::LINEAR,
627*35238bceSAndroid Build Coastguard Worker                                                                     tcu::Sampler::LINEAR),
628*35238bceSAndroid Build Coastguard Worker                                                        t, s, lod);
629*35238bceSAndroid Build Coastguard Worker 
630*35238bceSAndroid Build Coastguard Worker                     int r = deClamp32((int)(255.0f * color.x()), 0, 255);
631*35238bceSAndroid Build Coastguard Worker                     int g = deClamp32((int)(255.0f * color.y()), 0, 255);
632*35238bceSAndroid Build Coastguard Worker                     int b = deClamp32((int)(255.0f * color.z()), 0, 255);
633*35238bceSAndroid Build Coastguard Worker                     int a = deClamp32((int)(255.0f * color.w()), 0, 255);
634*35238bceSAndroid Build Coastguard Worker 
635*35238bceSAndroid Build Coastguard Worker                     reference->setPixel(x, y, tcu::RGBA(r, g, b, a));
636*35238bceSAndroid Build Coastguard Worker                 }
637*35238bceSAndroid Build Coastguard Worker             }
638*35238bceSAndroid Build Coastguard Worker         }
639*35238bceSAndroid Build Coastguard Worker     }
640*35238bceSAndroid Build Coastguard Worker     else
641*35238bceSAndroid Build Coastguard Worker     {
642*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_glTextureAsColorAttachment);
643*35238bceSAndroid Build Coastguard Worker 
644*35238bceSAndroid Build Coastguard Worker         for (int i = 0; i < 2; i++)
645*35238bceSAndroid Build Coastguard Worker         {
646*35238bceSAndroid Build Coastguard Worker             /* Draw left half of rectangle */
647*35238bceSAndroid Build Coastguard Worker             {
648*35238bceSAndroid Build Coastguard Worker                 GLfloat vertices[]  = {-1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f};
649*35238bceSAndroid Build Coastguard Worker                 GLfloat texcoords[] = {0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 1.0f, 0.0f, 1.0f};
650*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(texCoordLocation));
651*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(coordLocation));
652*35238bceSAndroid Build Coastguard Worker 
653*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords));
654*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, vertices));
655*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices));
656*35238bceSAndroid Build Coastguard Worker             }
657*35238bceSAndroid Build Coastguard Worker             /* Bind the m_glTexture as user fbo color attachments */
658*35238bceSAndroid Build Coastguard Worker             {
659*35238bceSAndroid Build Coastguard Worker                 GLuint fbo = 0;
660*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, bindTexture(GL_TEXTURE_2D, m_glTexture));
661*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, genFramebuffers(1, &fbo));
662*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, bindFramebuffer(GL_FRAMEBUFFER, fbo));
663*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(
664*35238bceSAndroid Build Coastguard Worker                     m_gl, framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_glTexture, 0));
665*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, checkFramebufferStatus(GL_FRAMEBUFFER));
666*35238bceSAndroid Build Coastguard Worker                 GLubyte data[] = {0, 0, 0, 0};
667*35238bceSAndroid Build Coastguard Worker                 m_gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
668*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
669*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, deleteFramebuffers(1, &fbo));
670*35238bceSAndroid Build Coastguard Worker             }
671*35238bceSAndroid Build Coastguard Worker             /* Draw right half of rectangle */
672*35238bceSAndroid Build Coastguard Worker             {
673*35238bceSAndroid Build Coastguard Worker                 GLfloat vertices[]  = {0.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f};
674*35238bceSAndroid Build Coastguard Worker                 GLfloat texcoords[] = {0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f, 1.0f};
675*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(texCoordLocation));
676*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(coordLocation));
677*35238bceSAndroid Build Coastguard Worker 
678*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords));
679*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, vertices));
680*35238bceSAndroid Build Coastguard Worker                 GLU_CHECK_GLW_CALL(m_gl, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices));
681*35238bceSAndroid Build Coastguard Worker             }
682*35238bceSAndroid Build Coastguard Worker 
683*35238bceSAndroid Build Coastguard Worker             if (0 == i)
684*35238bceSAndroid Build Coastguard Worker             {
685*35238bceSAndroid Build Coastguard Worker                 /* Get the reference data */
686*35238bceSAndroid Build Coastguard Worker                 m_gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
687*35238bceSAndroid Build Coastguard Worker                                 reference->getAccess().getDataPtr());
688*35238bceSAndroid Build Coastguard Worker             }
689*35238bceSAndroid Build Coastguard Worker             else
690*35238bceSAndroid Build Coastguard Worker             {
691*35238bceSAndroid Build Coastguard Worker                 m_gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
692*35238bceSAndroid Build Coastguard Worker                                 screen->getAccess().getDataPtr());
693*35238bceSAndroid Build Coastguard Worker             }
694*35238bceSAndroid Build Coastguard Worker         }
695*35238bceSAndroid Build Coastguard Worker     }
696*35238bceSAndroid Build Coastguard Worker }
697*35238bceSAndroid Build Coastguard Worker 
698*35238bceSAndroid Build Coastguard Worker class GLES2ProgramSharingTest : public GLES2SharingTest
699*35238bceSAndroid Build Coastguard Worker {
700*35238bceSAndroid Build Coastguard Worker public:
701*35238bceSAndroid Build Coastguard Worker     GLES2ProgramSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
702*35238bceSAndroid Build Coastguard Worker                             const GLES2SharingTest::TestSpec &spec);
703*35238bceSAndroid Build Coastguard Worker 
704*35238bceSAndroid Build Coastguard Worker private:
705*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgram *m_program;
706*35238bceSAndroid Build Coastguard Worker 
707*35238bceSAndroid Build Coastguard Worker     virtual void createResource(void);
708*35238bceSAndroid Build Coastguard Worker     virtual void destroyResource(void);
709*35238bceSAndroid Build Coastguard Worker     virtual void renderResource(tcu::Surface *screen, tcu::Surface *reference);
710*35238bceSAndroid Build Coastguard Worker };
711*35238bceSAndroid Build Coastguard Worker 
GLES2ProgramSharingTest(EglTestContext & eglTestCtx,const char * name,const char * desc,const GLES2SharingTest::TestSpec & spec)712*35238bceSAndroid Build Coastguard Worker GLES2ProgramSharingTest::GLES2ProgramSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
713*35238bceSAndroid Build Coastguard Worker                                                  const GLES2SharingTest::TestSpec &spec)
714*35238bceSAndroid Build Coastguard Worker     : GLES2SharingTest(eglTestCtx, name, desc, spec)
715*35238bceSAndroid Build Coastguard Worker     , m_program(DE_NULL)
716*35238bceSAndroid Build Coastguard Worker {
717*35238bceSAndroid Build Coastguard Worker }
718*35238bceSAndroid Build Coastguard Worker 
createResource(void)719*35238bceSAndroid Build Coastguard Worker void GLES2ProgramSharingTest::createResource(void)
720*35238bceSAndroid Build Coastguard Worker {
721*35238bceSAndroid Build Coastguard Worker     const char *vertexShader = ""
722*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec2 a_pos;\n"
723*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec4 a_color;\n"
724*35238bceSAndroid Build Coastguard Worker                                "varying mediump vec4 v_color;\n"
725*35238bceSAndroid Build Coastguard Worker                                "void main(void)\n"
726*35238bceSAndroid Build Coastguard Worker                                "{\n"
727*35238bceSAndroid Build Coastguard Worker                                "\tv_color = a_color;\n"
728*35238bceSAndroid Build Coastguard Worker                                "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
729*35238bceSAndroid Build Coastguard Worker                                "}\n";
730*35238bceSAndroid Build Coastguard Worker 
731*35238bceSAndroid Build Coastguard Worker     const char *fragmentShader = ""
732*35238bceSAndroid Build Coastguard Worker                                  "varying mediump vec4 v_color;\n"
733*35238bceSAndroid Build Coastguard Worker                                  "void main(void)\n"
734*35238bceSAndroid Build Coastguard Worker                                  "{\n"
735*35238bceSAndroid Build Coastguard Worker                                  "\tgl_FragColor = v_color;\n"
736*35238bceSAndroid Build Coastguard Worker                                  "}\n";
737*35238bceSAndroid Build Coastguard Worker 
738*35238bceSAndroid Build Coastguard Worker     m_program = new glu::ShaderProgram(m_gl, glu::makeVtxFragSources(vertexShader, fragmentShader));
739*35238bceSAndroid Build Coastguard Worker 
740*35238bceSAndroid Build Coastguard Worker     if (!m_program->isOk())
741*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shader program");
742*35238bceSAndroid Build Coastguard Worker }
743*35238bceSAndroid Build Coastguard Worker 
destroyResource(void)744*35238bceSAndroid Build Coastguard Worker void GLES2ProgramSharingTest::destroyResource(void)
745*35238bceSAndroid Build Coastguard Worker {
746*35238bceSAndroid Build Coastguard Worker     delete m_program;
747*35238bceSAndroid Build Coastguard Worker }
748*35238bceSAndroid Build Coastguard Worker 
renderResource(tcu::Surface * screen,tcu::Surface * reference)749*35238bceSAndroid Build Coastguard Worker void GLES2ProgramSharingTest::renderResource(tcu::Surface *screen, tcu::Surface *reference)
750*35238bceSAndroid Build Coastguard Worker {
751*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((screen && reference) || (!screen && !reference));
752*35238bceSAndroid Build Coastguard Worker 
753*35238bceSAndroid Build Coastguard Worker     int width  = 240;
754*35238bceSAndroid Build Coastguard Worker     int height = 240;
755*35238bceSAndroid Build Coastguard Worker 
756*35238bceSAndroid Build Coastguard Worker     if (screen)
757*35238bceSAndroid Build Coastguard Worker     {
758*35238bceSAndroid Build Coastguard Worker         width  = screen->getWidth();
759*35238bceSAndroid Build Coastguard Worker         height = screen->getHeight();
760*35238bceSAndroid Build Coastguard Worker     }
761*35238bceSAndroid Build Coastguard Worker 
762*35238bceSAndroid Build Coastguard Worker     static const GLfloat coords[] = {-0.9f, -0.9f, 0.9f, -0.9f, 0.9f, 0.9f, -0.9f, 0.9f};
763*35238bceSAndroid Build Coastguard Worker 
764*35238bceSAndroid Build Coastguard Worker     static const GLfloat colors[] = {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
765*35238bceSAndroid Build Coastguard Worker                                      0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
766*35238bceSAndroid Build Coastguard Worker 
767*35238bceSAndroid Build Coastguard Worker     static const GLushort indices[] = {0, 1, 2, 2, 3, 0};
768*35238bceSAndroid Build Coastguard Worker 
769*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, viewport(0, 0, width, height));
770*35238bceSAndroid Build Coastguard Worker 
771*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clearColor(1.0f, 0.0f, 0.0f, 1.0f));
772*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clear(GL_COLOR_BUFFER_BIT));
773*35238bceSAndroid Build Coastguard Worker 
774*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(m_program->getProgram()));
775*35238bceSAndroid Build Coastguard Worker 
776*35238bceSAndroid Build Coastguard Worker     GLuint coordLocation = m_gl.getAttribLocation(m_program->getProgram(), "a_pos");
777*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
778*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(coordLocation != (GLuint)-1);
779*35238bceSAndroid Build Coastguard Worker 
780*35238bceSAndroid Build Coastguard Worker     GLuint colorLocation = m_gl.getAttribLocation(m_program->getProgram(), "a_color");
781*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
782*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(colorLocation != (GLuint)-1);
783*35238bceSAndroid Build Coastguard Worker 
784*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(colorLocation));
785*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(coordLocation));
786*35238bceSAndroid Build Coastguard Worker 
787*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, colors));
788*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, coords));
789*35238bceSAndroid Build Coastguard Worker 
790*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices));
791*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(coordLocation));
792*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(colorLocation));
793*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(0));
794*35238bceSAndroid Build Coastguard Worker 
795*35238bceSAndroid Build Coastguard Worker     if (screen)
796*35238bceSAndroid Build Coastguard Worker     {
797*35238bceSAndroid Build Coastguard Worker         m_gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
798*35238bceSAndroid Build Coastguard Worker                         screen->getAccess().getDataPtr());
799*35238bceSAndroid Build Coastguard Worker 
800*35238bceSAndroid Build Coastguard Worker         tcu::clear(reference->getAccess(), tcu::IVec4(0xff, 0, 0, 0xff));
801*35238bceSAndroid Build Coastguard Worker 
802*35238bceSAndroid Build Coastguard Worker         int x1 = (int)(((float)width / 2.0f) * (-0.9f) + ((float)width / 2.0f));
803*35238bceSAndroid Build Coastguard Worker         int x2 = (int)(((float)width / 2.0f) * 0.9f + ((float)width / 2.0f));
804*35238bceSAndroid Build Coastguard Worker         int y1 = (int)(((float)height / 2.0f) * (-0.9f) + ((float)height / 2.0f));
805*35238bceSAndroid Build Coastguard Worker         int y2 = (int)(((float)height / 2.0f) * 0.9f + ((float)height / 2.0f));
806*35238bceSAndroid Build Coastguard Worker 
807*35238bceSAndroid Build Coastguard Worker         for (int x = x1; x <= x2; x++)
808*35238bceSAndroid Build Coastguard Worker         {
809*35238bceSAndroid Build Coastguard Worker             for (int y = y1; y <= y2; y++)
810*35238bceSAndroid Build Coastguard Worker             {
811*35238bceSAndroid Build Coastguard Worker                 float t      = ((float)(x - x1) / (float)(x2 - x1));
812*35238bceSAndroid Build Coastguard Worker                 float s      = ((float)(y - y1) / (float)(y2 - y1));
813*35238bceSAndroid Build Coastguard Worker                 bool isUpper = t > s;
814*35238bceSAndroid Build Coastguard Worker 
815*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 a(colors[0], colors[1], colors[2], colors[3]);
816*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 b(colors[4 + 0], colors[4 + 1], colors[4 + 2], colors[4 + 3]);
817*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 c(colors[8 + 0], colors[8 + 1], colors[8 + 2], colors[8 + 3]);
818*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 d(colors[12 + 0], colors[12 + 1], colors[12 + 2], colors[12 + 3]);
819*35238bceSAndroid Build Coastguard Worker 
820*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 color;
821*35238bceSAndroid Build Coastguard Worker 
822*35238bceSAndroid Build Coastguard Worker                 if (isUpper)
823*35238bceSAndroid Build Coastguard Worker                     color = a * (1.0f - t) + b * (t - s) + s * c;
824*35238bceSAndroid Build Coastguard Worker                 else
825*35238bceSAndroid Build Coastguard Worker                     color = a * (1.0f - s) + d * (s - t) + t * c;
826*35238bceSAndroid Build Coastguard Worker 
827*35238bceSAndroid Build Coastguard Worker                 int red   = deClamp32((int)(255.0f * color.x()), 0, 255);
828*35238bceSAndroid Build Coastguard Worker                 int green = deClamp32((int)(255.0f * color.y()), 0, 255);
829*35238bceSAndroid Build Coastguard Worker                 int blue  = deClamp32((int)(255.0f * color.z()), 0, 255);
830*35238bceSAndroid Build Coastguard Worker                 int alpha = deClamp32((int)(255.0f * color.w()), 0, 255);
831*35238bceSAndroid Build Coastguard Worker 
832*35238bceSAndroid Build Coastguard Worker                 reference->setPixel(x, y, tcu::RGBA(red, green, blue, alpha));
833*35238bceSAndroid Build Coastguard Worker             }
834*35238bceSAndroid Build Coastguard Worker         }
835*35238bceSAndroid Build Coastguard Worker     }
836*35238bceSAndroid Build Coastguard Worker }
837*35238bceSAndroid Build Coastguard Worker 
838*35238bceSAndroid Build Coastguard Worker class GLES2ShaderSharingTest : public GLES2SharingTest
839*35238bceSAndroid Build Coastguard Worker {
840*35238bceSAndroid Build Coastguard Worker public:
841*35238bceSAndroid Build Coastguard Worker     GLES2ShaderSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc, GLenum shaderType,
842*35238bceSAndroid Build Coastguard Worker                            const GLES2SharingTest::TestSpec &spec);
843*35238bceSAndroid Build Coastguard Worker 
844*35238bceSAndroid Build Coastguard Worker private:
845*35238bceSAndroid Build Coastguard Worker     GLuint m_shader;
846*35238bceSAndroid Build Coastguard Worker     GLenum m_shaderType;
847*35238bceSAndroid Build Coastguard Worker 
848*35238bceSAndroid Build Coastguard Worker     virtual void createResource(void);
849*35238bceSAndroid Build Coastguard Worker     virtual void destroyResource(void);
850*35238bceSAndroid Build Coastguard Worker     virtual void renderResource(tcu::Surface *screen, tcu::Surface *reference);
851*35238bceSAndroid Build Coastguard Worker };
852*35238bceSAndroid Build Coastguard Worker 
GLES2ShaderSharingTest(EglTestContext & eglTestCtx,const char * name,const char * desc,GLenum shaderType,const GLES2SharingTest::TestSpec & spec)853*35238bceSAndroid Build Coastguard Worker GLES2ShaderSharingTest::GLES2ShaderSharingTest(EglTestContext &eglTestCtx, const char *name, const char *desc,
854*35238bceSAndroid Build Coastguard Worker                                                GLenum shaderType, const GLES2SharingTest::TestSpec &spec)
855*35238bceSAndroid Build Coastguard Worker     : GLES2SharingTest(eglTestCtx, name, desc, spec)
856*35238bceSAndroid Build Coastguard Worker     , m_shader(0)
857*35238bceSAndroid Build Coastguard Worker     , m_shaderType(shaderType)
858*35238bceSAndroid Build Coastguard Worker {
859*35238bceSAndroid Build Coastguard Worker }
860*35238bceSAndroid Build Coastguard Worker 
createResource(void)861*35238bceSAndroid Build Coastguard Worker void GLES2ShaderSharingTest::createResource(void)
862*35238bceSAndroid Build Coastguard Worker {
863*35238bceSAndroid Build Coastguard Worker     const char *vertexShader = ""
864*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec2 a_pos;\n"
865*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec4 a_color;\n"
866*35238bceSAndroid Build Coastguard Worker                                "varying mediump vec4 v_color;\n"
867*35238bceSAndroid Build Coastguard Worker                                "void main(void)\n"
868*35238bceSAndroid Build Coastguard Worker                                "{\n"
869*35238bceSAndroid Build Coastguard Worker                                "\tv_color = a_color;\n"
870*35238bceSAndroid Build Coastguard Worker                                "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
871*35238bceSAndroid Build Coastguard Worker                                "}\n";
872*35238bceSAndroid Build Coastguard Worker 
873*35238bceSAndroid Build Coastguard Worker     const char *fragmentShader = ""
874*35238bceSAndroid Build Coastguard Worker                                  "varying mediump vec4 v_color;\n"
875*35238bceSAndroid Build Coastguard Worker                                  "void main(void)\n"
876*35238bceSAndroid Build Coastguard Worker                                  "{\n"
877*35238bceSAndroid Build Coastguard Worker                                  "\tgl_FragColor = v_color;\n"
878*35238bceSAndroid Build Coastguard Worker                                  "}\n";
879*35238bceSAndroid Build Coastguard Worker 
880*35238bceSAndroid Build Coastguard Worker     m_shader = m_gl.createShader(m_shaderType);
881*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glCreateShader()");
882*35238bceSAndroid Build Coastguard Worker 
883*35238bceSAndroid Build Coastguard Worker     switch (m_shaderType)
884*35238bceSAndroid Build Coastguard Worker     {
885*35238bceSAndroid Build Coastguard Worker     case GL_VERTEX_SHADER:
886*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, shaderSource(m_shader, 1, &vertexShader, DE_NULL));
887*35238bceSAndroid Build Coastguard Worker         break;
888*35238bceSAndroid Build Coastguard Worker 
889*35238bceSAndroid Build Coastguard Worker     case GL_FRAGMENT_SHADER:
890*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, shaderSource(m_shader, 1, &fragmentShader, DE_NULL));
891*35238bceSAndroid Build Coastguard Worker         break;
892*35238bceSAndroid Build Coastguard Worker 
893*35238bceSAndroid Build Coastguard Worker     default:
894*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
895*35238bceSAndroid Build Coastguard Worker     }
896*35238bceSAndroid Build Coastguard Worker 
897*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, compileShader(m_shader));
898*35238bceSAndroid Build Coastguard Worker 
899*35238bceSAndroid Build Coastguard Worker     GLint status = 0;
900*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, getShaderiv(m_shader, GL_COMPILE_STATUS, &status));
901*35238bceSAndroid Build Coastguard Worker 
902*35238bceSAndroid Build Coastguard Worker     if (!status)
903*35238bceSAndroid Build Coastguard Worker     {
904*35238bceSAndroid Build Coastguard Worker         char buffer[256];
905*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, getShaderInfoLog(m_shader, 256, DE_NULL, buffer));
906*35238bceSAndroid Build Coastguard Worker 
907*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << "Failed to compile shader" << tcu::TestLog::EndMessage;
908*35238bceSAndroid Build Coastguard Worker 
909*35238bceSAndroid Build Coastguard Worker         switch (m_shaderType)
910*35238bceSAndroid Build Coastguard Worker         {
911*35238bceSAndroid Build Coastguard Worker         case GL_VERTEX_SHADER:
912*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << vertexShader << tcu::TestLog::EndMessage;
913*35238bceSAndroid Build Coastguard Worker             break;
914*35238bceSAndroid Build Coastguard Worker 
915*35238bceSAndroid Build Coastguard Worker         case GL_FRAGMENT_SHADER:
916*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << fragmentShader << tcu::TestLog::EndMessage;
917*35238bceSAndroid Build Coastguard Worker             break;
918*35238bceSAndroid Build Coastguard Worker 
919*35238bceSAndroid Build Coastguard Worker         default:
920*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false);
921*35238bceSAndroid Build Coastguard Worker         }
922*35238bceSAndroid Build Coastguard Worker 
923*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << buffer << tcu::TestLog::EndMessage;
924*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shader");
925*35238bceSAndroid Build Coastguard Worker     }
926*35238bceSAndroid Build Coastguard Worker }
927*35238bceSAndroid Build Coastguard Worker 
destroyResource(void)928*35238bceSAndroid Build Coastguard Worker void GLES2ShaderSharingTest::destroyResource(void)
929*35238bceSAndroid Build Coastguard Worker {
930*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, deleteShader(m_shader));
931*35238bceSAndroid Build Coastguard Worker }
932*35238bceSAndroid Build Coastguard Worker 
renderResource(tcu::Surface * screen,tcu::Surface * reference)933*35238bceSAndroid Build Coastguard Worker void GLES2ShaderSharingTest::renderResource(tcu::Surface *screen, tcu::Surface *reference)
934*35238bceSAndroid Build Coastguard Worker {
935*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((screen && reference) || (!screen && !reference));
936*35238bceSAndroid Build Coastguard Worker 
937*35238bceSAndroid Build Coastguard Worker     int width  = 240;
938*35238bceSAndroid Build Coastguard Worker     int height = 240;
939*35238bceSAndroid Build Coastguard Worker 
940*35238bceSAndroid Build Coastguard Worker     const char *vertexShader = ""
941*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec2 a_pos;\n"
942*35238bceSAndroid Build Coastguard Worker                                "attribute mediump vec4 a_color;\n"
943*35238bceSAndroid Build Coastguard Worker                                "varying mediump vec4 v_color;\n"
944*35238bceSAndroid Build Coastguard Worker                                "void main(void)\n"
945*35238bceSAndroid Build Coastguard Worker                                "{\n"
946*35238bceSAndroid Build Coastguard Worker                                "\tv_color = a_color;\n"
947*35238bceSAndroid Build Coastguard Worker                                "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
948*35238bceSAndroid Build Coastguard Worker                                "}\n";
949*35238bceSAndroid Build Coastguard Worker 
950*35238bceSAndroid Build Coastguard Worker     const char *fragmentShader = ""
951*35238bceSAndroid Build Coastguard Worker                                  "varying mediump vec4 v_color;\n"
952*35238bceSAndroid Build Coastguard Worker                                  "void main(void)\n"
953*35238bceSAndroid Build Coastguard Worker                                  "{\n"
954*35238bceSAndroid Build Coastguard Worker                                  "\tgl_FragColor = v_color;\n"
955*35238bceSAndroid Build Coastguard Worker                                  "}\n";
956*35238bceSAndroid Build Coastguard Worker 
957*35238bceSAndroid Build Coastguard Worker     GLuint otherShader = (GLuint)-1;
958*35238bceSAndroid Build Coastguard Worker 
959*35238bceSAndroid Build Coastguard Worker     switch (m_shaderType)
960*35238bceSAndroid Build Coastguard Worker     {
961*35238bceSAndroid Build Coastguard Worker     case GL_VERTEX_SHADER:
962*35238bceSAndroid Build Coastguard Worker         otherShader = m_gl.createShader(GL_FRAGMENT_SHADER);
963*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_MSG(m_gl, "glCreateShader()");
964*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, shaderSource(otherShader, 1, &fragmentShader, DE_NULL));
965*35238bceSAndroid Build Coastguard Worker         break;
966*35238bceSAndroid Build Coastguard Worker 
967*35238bceSAndroid Build Coastguard Worker     case GL_FRAGMENT_SHADER:
968*35238bceSAndroid Build Coastguard Worker         otherShader = m_gl.createShader(GL_VERTEX_SHADER);
969*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_MSG(m_gl, "glCreateShader()");
970*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, shaderSource(otherShader, 1, &vertexShader, DE_NULL));
971*35238bceSAndroid Build Coastguard Worker         break;
972*35238bceSAndroid Build Coastguard Worker 
973*35238bceSAndroid Build Coastguard Worker     default:
974*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
975*35238bceSAndroid Build Coastguard Worker     }
976*35238bceSAndroid Build Coastguard Worker 
977*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, compileShader(otherShader));
978*35238bceSAndroid Build Coastguard Worker 
979*35238bceSAndroid Build Coastguard Worker     GLint status = 0;
980*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, getShaderiv(otherShader, GL_COMPILE_STATUS, &status));
981*35238bceSAndroid Build Coastguard Worker 
982*35238bceSAndroid Build Coastguard Worker     if (!status)
983*35238bceSAndroid Build Coastguard Worker     {
984*35238bceSAndroid Build Coastguard Worker         char buffer[256];
985*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, getShaderInfoLog(otherShader, 256, DE_NULL, buffer));
986*35238bceSAndroid Build Coastguard Worker 
987*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << "Failed to compile shader" << tcu::TestLog::EndMessage;
988*35238bceSAndroid Build Coastguard Worker 
989*35238bceSAndroid Build Coastguard Worker         switch (m_shaderType)
990*35238bceSAndroid Build Coastguard Worker         {
991*35238bceSAndroid Build Coastguard Worker         case GL_FRAGMENT_SHADER:
992*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << vertexShader << tcu::TestLog::EndMessage;
993*35238bceSAndroid Build Coastguard Worker             break;
994*35238bceSAndroid Build Coastguard Worker 
995*35238bceSAndroid Build Coastguard Worker         case GL_VERTEX_SHADER:
996*35238bceSAndroid Build Coastguard Worker             m_log << tcu::TestLog::Message << fragmentShader << tcu::TestLog::EndMessage;
997*35238bceSAndroid Build Coastguard Worker             break;
998*35238bceSAndroid Build Coastguard Worker 
999*35238bceSAndroid Build Coastguard Worker         default:
1000*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false);
1001*35238bceSAndroid Build Coastguard Worker         }
1002*35238bceSAndroid Build Coastguard Worker 
1003*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << buffer << tcu::TestLog::EndMessage;
1004*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shader");
1005*35238bceSAndroid Build Coastguard Worker     }
1006*35238bceSAndroid Build Coastguard Worker 
1007*35238bceSAndroid Build Coastguard Worker     GLuint program = m_gl.createProgram();
1008*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glCreateProgram()");
1009*35238bceSAndroid Build Coastguard Worker 
1010*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, attachShader(program, m_shader));
1011*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, attachShader(program, otherShader));
1012*35238bceSAndroid Build Coastguard Worker 
1013*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, linkProgram(program));
1014*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, deleteShader(otherShader));
1015*35238bceSAndroid Build Coastguard Worker 
1016*35238bceSAndroid Build Coastguard Worker     status = 0;
1017*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, getProgramiv(program, GL_LINK_STATUS, &status));
1018*35238bceSAndroid Build Coastguard Worker 
1019*35238bceSAndroid Build Coastguard Worker     if (!status)
1020*35238bceSAndroid Build Coastguard Worker     {
1021*35238bceSAndroid Build Coastguard Worker         char buffer[256];
1022*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, getProgramInfoLog(program, 256, DE_NULL, buffer));
1023*35238bceSAndroid Build Coastguard Worker 
1024*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << "Failed to link program" << tcu::TestLog::EndMessage;
1025*35238bceSAndroid Build Coastguard Worker 
1026*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << vertexShader << tcu::TestLog::EndMessage;
1027*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << fragmentShader << tcu::TestLog::EndMessage;
1028*35238bceSAndroid Build Coastguard Worker         m_log << tcu::TestLog::Message << buffer << tcu::TestLog::EndMessage;
1029*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to link program");
1030*35238bceSAndroid Build Coastguard Worker     }
1031*35238bceSAndroid Build Coastguard Worker 
1032*35238bceSAndroid Build Coastguard Worker     if (screen)
1033*35238bceSAndroid Build Coastguard Worker     {
1034*35238bceSAndroid Build Coastguard Worker         width  = screen->getWidth();
1035*35238bceSAndroid Build Coastguard Worker         height = screen->getHeight();
1036*35238bceSAndroid Build Coastguard Worker     }
1037*35238bceSAndroid Build Coastguard Worker 
1038*35238bceSAndroid Build Coastguard Worker     static const GLfloat coords[] = {-0.9f, -0.9f, 0.9f, -0.9f, 0.9f, 0.9f, -0.9f, 0.9f};
1039*35238bceSAndroid Build Coastguard Worker 
1040*35238bceSAndroid Build Coastguard Worker     static const GLfloat colors[] = {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1041*35238bceSAndroid Build Coastguard Worker                                      0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
1042*35238bceSAndroid Build Coastguard Worker 
1043*35238bceSAndroid Build Coastguard Worker     static const GLushort indices[] = {0, 1, 2, 2, 3, 0};
1044*35238bceSAndroid Build Coastguard Worker 
1045*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, viewport(0, 0, width, height));
1046*35238bceSAndroid Build Coastguard Worker 
1047*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clearColor(1.0f, 0.0f, 0.0f, 1.0f));
1048*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clear(GL_COLOR_BUFFER_BIT));
1049*35238bceSAndroid Build Coastguard Worker 
1050*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(program));
1051*35238bceSAndroid Build Coastguard Worker 
1052*35238bceSAndroid Build Coastguard Worker     GLuint coordLocation = m_gl.getAttribLocation(program, "a_pos");
1053*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
1054*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(coordLocation != (GLuint)-1);
1055*35238bceSAndroid Build Coastguard Worker 
1056*35238bceSAndroid Build Coastguard Worker     GLuint colorLocation = m_gl.getAttribLocation(program, "a_color");
1057*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_MSG(m_gl, "glGetAttribLocation()");
1058*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(colorLocation != (GLuint)-1);
1059*35238bceSAndroid Build Coastguard Worker 
1060*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(colorLocation));
1061*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(coordLocation));
1062*35238bceSAndroid Build Coastguard Worker 
1063*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, colors));
1064*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, coords));
1065*35238bceSAndroid Build Coastguard Worker 
1066*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices));
1067*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(coordLocation));
1068*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, disableVertexAttribArray(colorLocation));
1069*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(0));
1070*35238bceSAndroid Build Coastguard Worker 
1071*35238bceSAndroid Build Coastguard Worker     if (screen)
1072*35238bceSAndroid Build Coastguard Worker     {
1073*35238bceSAndroid Build Coastguard Worker         m_gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
1074*35238bceSAndroid Build Coastguard Worker                         screen->getAccess().getDataPtr());
1075*35238bceSAndroid Build Coastguard Worker 
1076*35238bceSAndroid Build Coastguard Worker         tcu::clear(reference->getAccess(), tcu::IVec4(0xff, 0, 0, 0xff));
1077*35238bceSAndroid Build Coastguard Worker 
1078*35238bceSAndroid Build Coastguard Worker         int x1 = (int)(((float)width / 2.0f) * (-0.9f) + ((float)width / 2.0f));
1079*35238bceSAndroid Build Coastguard Worker         int x2 = (int)(((float)width / 2.0f) * 0.9f + ((float)width / 2.0f));
1080*35238bceSAndroid Build Coastguard Worker         int y1 = (int)(((float)height / 2.0f) * (-0.9f) + ((float)height / 2.0f));
1081*35238bceSAndroid Build Coastguard Worker         int y2 = (int)(((float)height / 2.0f) * 0.9f + ((float)height / 2.0f));
1082*35238bceSAndroid Build Coastguard Worker 
1083*35238bceSAndroid Build Coastguard Worker         for (int x = x1; x <= x2; x++)
1084*35238bceSAndroid Build Coastguard Worker         {
1085*35238bceSAndroid Build Coastguard Worker             for (int y = y1; y <= y2; y++)
1086*35238bceSAndroid Build Coastguard Worker             {
1087*35238bceSAndroid Build Coastguard Worker                 float t      = ((float)(x - x1) / (float)(x2 - x1));
1088*35238bceSAndroid Build Coastguard Worker                 float s      = ((float)(y - y1) / (float)(y2 - y1));
1089*35238bceSAndroid Build Coastguard Worker                 bool isUpper = t > s;
1090*35238bceSAndroid Build Coastguard Worker 
1091*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 a(colors[0], colors[1], colors[2], colors[3]);
1092*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 b(colors[4 + 0], colors[4 + 1], colors[4 + 2], colors[4 + 3]);
1093*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 c(colors[8 + 0], colors[8 + 1], colors[8 + 2], colors[8 + 3]);
1094*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 d(colors[12 + 0], colors[12 + 1], colors[12 + 2], colors[12 + 3]);
1095*35238bceSAndroid Build Coastguard Worker 
1096*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4 color;
1097*35238bceSAndroid Build Coastguard Worker 
1098*35238bceSAndroid Build Coastguard Worker                 if (isUpper)
1099*35238bceSAndroid Build Coastguard Worker                     color = a * (1.0f - t) + b * (t - s) + s * c;
1100*35238bceSAndroid Build Coastguard Worker                 else
1101*35238bceSAndroid Build Coastguard Worker                     color = a * (1.0f - s) + d * (s - t) + t * c;
1102*35238bceSAndroid Build Coastguard Worker 
1103*35238bceSAndroid Build Coastguard Worker                 int red   = deClamp32((int)(255.0f * color.x()), 0, 255);
1104*35238bceSAndroid Build Coastguard Worker                 int green = deClamp32((int)(255.0f * color.y()), 0, 255);
1105*35238bceSAndroid Build Coastguard Worker                 int blue  = deClamp32((int)(255.0f * color.z()), 0, 255);
1106*35238bceSAndroid Build Coastguard Worker                 int alpha = deClamp32((int)(255.0f * color.w()), 0, 255);
1107*35238bceSAndroid Build Coastguard Worker 
1108*35238bceSAndroid Build Coastguard Worker                 reference->setPixel(x, y, tcu::RGBA(red, green, blue, alpha));
1109*35238bceSAndroid Build Coastguard Worker             }
1110*35238bceSAndroid Build Coastguard Worker         }
1111*35238bceSAndroid Build Coastguard Worker     }
1112*35238bceSAndroid Build Coastguard Worker }
1113*35238bceSAndroid Build Coastguard Worker 
SharingTests(EglTestContext & eglTestCtx)1114*35238bceSAndroid Build Coastguard Worker SharingTests::SharingTests(EglTestContext &eglTestCtx) : TestCaseGroup(eglTestCtx, "sharing", "Sharing test cases")
1115*35238bceSAndroid Build Coastguard Worker {
1116*35238bceSAndroid Build Coastguard Worker }
1117*35238bceSAndroid Build Coastguard Worker 
init(void)1118*35238bceSAndroid Build Coastguard Worker void SharingTests::init(void)
1119*35238bceSAndroid Build Coastguard Worker {
1120*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *gles2 = new TestCaseGroup(m_eglTestCtx, "gles2", "OpenGL ES 2 sharing test");
1121*35238bceSAndroid Build Coastguard Worker 
1122*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *context = new TestCaseGroup(m_eglTestCtx, "context", "Context creation and destruction tests");
1123*35238bceSAndroid Build Coastguard Worker 
1124*35238bceSAndroid Build Coastguard Worker     {
1125*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1126*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1127*35238bceSAndroid Build Coastguard Worker         spec.useResource          = false;
1128*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1129*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1130*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1131*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = true;
1132*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1133*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = true;
1134*35238bceSAndroid Build Coastguard Worker 
1135*35238bceSAndroid Build Coastguard Worker         context->addChild(
1136*35238bceSAndroid Build Coastguard Worker             new GLES2SharingTest(m_eglTestCtx, "create_destroy", "Simple context creation and destruction", spec));
1137*35238bceSAndroid Build Coastguard Worker     }
1138*35238bceSAndroid Build Coastguard Worker     {
1139*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1140*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = true;
1141*35238bceSAndroid Build Coastguard Worker         spec.useResource          = false;
1142*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1143*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = false;
1144*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1145*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1146*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1147*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1148*35238bceSAndroid Build Coastguard Worker 
1149*35238bceSAndroid Build Coastguard Worker         context->addChild(new GLES2SharingTest(
1150*35238bceSAndroid Build Coastguard Worker             m_eglTestCtx, "create_destroy_mixed",
1151*35238bceSAndroid Build Coastguard Worker             "Simple context creation and destruction test with different destruction order", spec));
1152*35238bceSAndroid Build Coastguard Worker     }
1153*35238bceSAndroid Build Coastguard Worker 
1154*35238bceSAndroid Build Coastguard Worker     gles2->addChild(context);
1155*35238bceSAndroid Build Coastguard Worker 
1156*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *buffer =
1157*35238bceSAndroid Build Coastguard Worker         new TestCaseGroup(m_eglTestCtx, "buffer", "Buffer creation, destruction and rendering test");
1158*35238bceSAndroid Build Coastguard Worker 
1159*35238bceSAndroid Build Coastguard Worker     {
1160*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1161*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1162*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1163*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1164*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1165*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1166*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1167*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1168*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1169*35238bceSAndroid Build Coastguard Worker 
1170*35238bceSAndroid Build Coastguard Worker         buffer->addChild(
1171*35238bceSAndroid Build Coastguard Worker             new GLES2BufferSharingTest(m_eglTestCtx, "create_delete", "Create and delete on shared context", spec));
1172*35238bceSAndroid Build Coastguard Worker     }
1173*35238bceSAndroid Build Coastguard Worker     {
1174*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1175*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1176*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1177*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = true;
1178*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1179*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1180*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1181*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1182*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1183*35238bceSAndroid Build Coastguard Worker 
1184*35238bceSAndroid Build Coastguard Worker         buffer->addChild(new GLES2BufferSharingTest(m_eglTestCtx, "create_delete_mixed",
1185*35238bceSAndroid Build Coastguard Worker                                                     "Create and delet on different contexts", spec));
1186*35238bceSAndroid Build Coastguard Worker     }
1187*35238bceSAndroid Build Coastguard Worker     {
1188*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1189*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1190*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1191*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1192*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1193*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1194*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = true;
1195*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1196*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = true;
1197*35238bceSAndroid Build Coastguard Worker 
1198*35238bceSAndroid Build Coastguard Worker         buffer->addChild(new GLES2BufferSharingTest(m_eglTestCtx, "render",
1199*35238bceSAndroid Build Coastguard Worker                                                     "Create, rendering on two different contexts and delete", spec));
1200*35238bceSAndroid Build Coastguard Worker     }
1201*35238bceSAndroid Build Coastguard Worker 
1202*35238bceSAndroid Build Coastguard Worker     gles2->addChild(buffer);
1203*35238bceSAndroid Build Coastguard Worker 
1204*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *texture =
1205*35238bceSAndroid Build Coastguard Worker         new TestCaseGroup(m_eglTestCtx, "texture", "Texture creation, destruction and rendering tests");
1206*35238bceSAndroid Build Coastguard Worker 
1207*35238bceSAndroid Build Coastguard Worker     {
1208*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1209*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1210*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1211*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1212*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1213*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1214*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1215*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1216*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1217*35238bceSAndroid Build Coastguard Worker 
1218*35238bceSAndroid Build Coastguard Worker         texture->addChild(new GLES2TextureSharingTest(m_eglTestCtx, "create_delete",
1219*35238bceSAndroid Build Coastguard Worker                                                       "Create and delete on shared context", spec, false));
1220*35238bceSAndroid Build Coastguard Worker     }
1221*35238bceSAndroid Build Coastguard Worker     {
1222*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1223*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1224*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1225*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = true;
1226*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1227*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1228*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1229*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1230*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1231*35238bceSAndroid Build Coastguard Worker 
1232*35238bceSAndroid Build Coastguard Worker         texture->addChild(new GLES2TextureSharingTest(m_eglTestCtx, "create_delete_mixed",
1233*35238bceSAndroid Build Coastguard Worker                                                       "Create and delete on different contexts", spec, false));
1234*35238bceSAndroid Build Coastguard Worker     }
1235*35238bceSAndroid Build Coastguard Worker     {
1236*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1237*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1238*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1239*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1240*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1241*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1242*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = true;
1243*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1244*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = true;
1245*35238bceSAndroid Build Coastguard Worker 
1246*35238bceSAndroid Build Coastguard Worker         texture->addChild(new GLES2TextureSharingTest(m_eglTestCtx, "render",
1247*35238bceSAndroid Build Coastguard Worker                                                       "Create, render in two contexts and delete", spec, false));
1248*35238bceSAndroid Build Coastguard Worker     }
1249*35238bceSAndroid Build Coastguard Worker     {
1250*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1251*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1252*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1253*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1254*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1255*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1256*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1257*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1258*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1259*35238bceSAndroid Build Coastguard Worker 
1260*35238bceSAndroid Build Coastguard Worker         texture->addChild(new GLES2TextureSharingTest(m_eglTestCtx, "render_sample_mixed",
1261*35238bceSAndroid Build Coastguard Worker                                                       "sampling, read pixels in different fbo", spec, true));
1262*35238bceSAndroid Build Coastguard Worker     }
1263*35238bceSAndroid Build Coastguard Worker     gles2->addChild(texture);
1264*35238bceSAndroid Build Coastguard Worker 
1265*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *program =
1266*35238bceSAndroid Build Coastguard Worker         new TestCaseGroup(m_eglTestCtx, "program", "Program creation, destruction and rendering test");
1267*35238bceSAndroid Build Coastguard Worker 
1268*35238bceSAndroid Build Coastguard Worker     {
1269*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1270*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1271*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1272*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1273*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1274*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1275*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1276*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1277*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1278*35238bceSAndroid Build Coastguard Worker 
1279*35238bceSAndroid Build Coastguard Worker         program->addChild(
1280*35238bceSAndroid Build Coastguard Worker             new GLES2ProgramSharingTest(m_eglTestCtx, "create_delete", "Create and delete on shared context", spec));
1281*35238bceSAndroid Build Coastguard Worker     }
1282*35238bceSAndroid Build Coastguard Worker     {
1283*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1284*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1285*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1286*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = true;
1287*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1288*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1289*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1290*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1291*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1292*35238bceSAndroid Build Coastguard Worker 
1293*35238bceSAndroid Build Coastguard Worker         program->addChild(new GLES2ProgramSharingTest(m_eglTestCtx, "create_delete_mixed",
1294*35238bceSAndroid Build Coastguard Worker                                                       "Create and delete on different contexts", spec));
1295*35238bceSAndroid Build Coastguard Worker     }
1296*35238bceSAndroid Build Coastguard Worker     {
1297*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1298*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1299*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1300*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1301*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1302*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1303*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = true;
1304*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1305*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = true;
1306*35238bceSAndroid Build Coastguard Worker 
1307*35238bceSAndroid Build Coastguard Worker         program->addChild(
1308*35238bceSAndroid Build Coastguard Worker             new GLES2ProgramSharingTest(m_eglTestCtx, "render", "Create, render in two contexts and delete", spec));
1309*35238bceSAndroid Build Coastguard Worker     }
1310*35238bceSAndroid Build Coastguard Worker 
1311*35238bceSAndroid Build Coastguard Worker     gles2->addChild(program);
1312*35238bceSAndroid Build Coastguard Worker 
1313*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *shader =
1314*35238bceSAndroid Build Coastguard Worker         new TestCaseGroup(m_eglTestCtx, "shader", "Shader creation, destruction and rendering test");
1315*35238bceSAndroid Build Coastguard Worker 
1316*35238bceSAndroid Build Coastguard Worker     {
1317*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1318*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1319*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1320*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1321*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1322*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1323*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1324*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1325*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1326*35238bceSAndroid Build Coastguard Worker 
1327*35238bceSAndroid Build Coastguard Worker         shader->addChild(new GLES2ShaderSharingTest(m_eglTestCtx, "create_delete_vert",
1328*35238bceSAndroid Build Coastguard Worker                                                     "Create and delete on shared context", GL_VERTEX_SHADER, spec));
1329*35238bceSAndroid Build Coastguard Worker     }
1330*35238bceSAndroid Build Coastguard Worker     {
1331*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1332*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1333*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1334*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = true;
1335*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1336*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1337*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1338*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1339*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1340*35238bceSAndroid Build Coastguard Worker 
1341*35238bceSAndroid Build Coastguard Worker         shader->addChild(new GLES2ShaderSharingTest(m_eglTestCtx, "create_delete_mixed_vert",
1342*35238bceSAndroid Build Coastguard Worker                                                     "Create and delete on different contexts", GL_VERTEX_SHADER, spec));
1343*35238bceSAndroid Build Coastguard Worker     }
1344*35238bceSAndroid Build Coastguard Worker     {
1345*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1346*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1347*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1348*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1349*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1350*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1351*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = true;
1352*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1353*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = true;
1354*35238bceSAndroid Build Coastguard Worker 
1355*35238bceSAndroid Build Coastguard Worker         shader->addChild(new GLES2ShaderSharingTest(
1356*35238bceSAndroid Build Coastguard Worker             m_eglTestCtx, "render_vert", "Create, render on two contexts and delete", GL_VERTEX_SHADER, spec));
1357*35238bceSAndroid Build Coastguard Worker     }
1358*35238bceSAndroid Build Coastguard Worker     {
1359*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1360*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1361*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1362*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1363*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1364*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1365*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1366*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1367*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1368*35238bceSAndroid Build Coastguard Worker 
1369*35238bceSAndroid Build Coastguard Worker         shader->addChild(new GLES2ShaderSharingTest(m_eglTestCtx, "create_delete_frag",
1370*35238bceSAndroid Build Coastguard Worker                                                     "Create and delete on shared context", GL_FRAGMENT_SHADER, spec));
1371*35238bceSAndroid Build Coastguard Worker     }
1372*35238bceSAndroid Build Coastguard Worker     {
1373*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1374*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1375*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1376*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = true;
1377*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1378*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = false;
1379*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = false;
1380*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = false;
1381*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = false;
1382*35238bceSAndroid Build Coastguard Worker 
1383*35238bceSAndroid Build Coastguard Worker         shader->addChild(new GLES2ShaderSharingTest(m_eglTestCtx, "create_delete_mixed_frag",
1384*35238bceSAndroid Build Coastguard Worker                                                     "Create and delete on different contexts", GL_FRAGMENT_SHADER,
1385*35238bceSAndroid Build Coastguard Worker                                                     spec));
1386*35238bceSAndroid Build Coastguard Worker     }
1387*35238bceSAndroid Build Coastguard Worker     {
1388*35238bceSAndroid Build Coastguard Worker         GLES2SharingTest::TestSpec spec;
1389*35238bceSAndroid Build Coastguard Worker         spec.destroyContextBFirst = false;
1390*35238bceSAndroid Build Coastguard Worker         spec.useResource          = true;
1391*35238bceSAndroid Build Coastguard Worker         spec.destroyOnContexB     = false;
1392*35238bceSAndroid Build Coastguard Worker         spec.initializeData       = true;
1393*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexA      = true;
1394*35238bceSAndroid Build Coastguard Worker         spec.renderOnContexB      = true;
1395*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexA      = true;
1396*35238bceSAndroid Build Coastguard Worker         spec.verifyOnContexB      = true;
1397*35238bceSAndroid Build Coastguard Worker 
1398*35238bceSAndroid Build Coastguard Worker         shader->addChild(new GLES2ShaderSharingTest(
1399*35238bceSAndroid Build Coastguard Worker             m_eglTestCtx, "render_frag", "Create, render on two contexts and delete", GL_FRAGMENT_SHADER, spec));
1400*35238bceSAndroid Build Coastguard Worker     }
1401*35238bceSAndroid Build Coastguard Worker 
1402*35238bceSAndroid Build Coastguard Worker     gles2->addChild(shader);
1403*35238bceSAndroid Build Coastguard Worker 
1404*35238bceSAndroid Build Coastguard Worker     gles2->addChild(new GLES2SharingThreadedTests(m_eglTestCtx));
1405*35238bceSAndroid Build Coastguard Worker 
1406*35238bceSAndroid Build Coastguard Worker     addChild(gles2);
1407*35238bceSAndroid Build Coastguard Worker }
1408*35238bceSAndroid Build Coastguard Worker 
1409*35238bceSAndroid Build Coastguard Worker } // namespace egl
1410*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1411