1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES Utilities
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 Reference Rendering Context.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceUtils.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "sglrShaderProgram.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuMatrix.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuMatrixUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "deMemory.h"
37*35238bceSAndroid Build Coastguard Worker #include "rrFragmentOperations.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "rrRenderer.hpp"
39*35238bceSAndroid Build Coastguard Worker
40*35238bceSAndroid Build Coastguard Worker #include <cstdint>
41*35238bceSAndroid Build Coastguard Worker
42*35238bceSAndroid Build Coastguard Worker namespace sglr
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker
45*35238bceSAndroid Build Coastguard Worker using std::map;
46*35238bceSAndroid Build Coastguard Worker using std::vector;
47*35238bceSAndroid Build Coastguard Worker
48*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
49*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
50*35238bceSAndroid Build Coastguard Worker using tcu::RGBA;
51*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
52*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
53*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
54*35238bceSAndroid Build Coastguard Worker
55*35238bceSAndroid Build Coastguard Worker // Reference context implementation
56*35238bceSAndroid Build Coastguard Worker using namespace rc;
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker using tcu::ConstPixelBufferAccess;
59*35238bceSAndroid Build Coastguard Worker using tcu::PixelBufferAccess;
60*35238bceSAndroid Build Coastguard Worker using tcu::TextureFormat;
61*35238bceSAndroid Build Coastguard Worker
62*35238bceSAndroid Build Coastguard Worker // Utilities for ReferenceContext
63*35238bceSAndroid Build Coastguard Worker #define RC_RET_VOID
64*35238bceSAndroid Build Coastguard Worker
65*35238bceSAndroid Build Coastguard Worker #define RC_ERROR_RET(ERR, RET) \
66*35238bceSAndroid Build Coastguard Worker do \
67*35238bceSAndroid Build Coastguard Worker { \
68*35238bceSAndroid Build Coastguard Worker setError(ERR); \
69*35238bceSAndroid Build Coastguard Worker return RET; \
70*35238bceSAndroid Build Coastguard Worker } while (false)
71*35238bceSAndroid Build Coastguard Worker
72*35238bceSAndroid Build Coastguard Worker #define RC_IF_ERROR(COND, ERR, RET) \
73*35238bceSAndroid Build Coastguard Worker do \
74*35238bceSAndroid Build Coastguard Worker { \
75*35238bceSAndroid Build Coastguard Worker if (COND) \
76*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(ERR, RET); \
77*35238bceSAndroid Build Coastguard Worker } while (false)
78*35238bceSAndroid Build Coastguard Worker
nullAccess(void)79*35238bceSAndroid Build Coastguard Worker static inline tcu::PixelBufferAccess nullAccess(void)
80*35238bceSAndroid Build Coastguard Worker {
81*35238bceSAndroid Build Coastguard Worker return tcu::PixelBufferAccess(TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8), 0, 0, 0, DE_NULL);
82*35238bceSAndroid Build Coastguard Worker }
83*35238bceSAndroid Build Coastguard Worker
isEmpty(const tcu::ConstPixelBufferAccess & access)84*35238bceSAndroid Build Coastguard Worker static inline bool isEmpty(const tcu::ConstPixelBufferAccess &access)
85*35238bceSAndroid Build Coastguard Worker {
86*35238bceSAndroid Build Coastguard Worker return access.getWidth() == 0 || access.getHeight() == 0 || access.getDepth() == 0;
87*35238bceSAndroid Build Coastguard Worker }
88*35238bceSAndroid Build Coastguard Worker
isEmpty(const rr::MultisampleConstPixelBufferAccess & access)89*35238bceSAndroid Build Coastguard Worker static inline bool isEmpty(const rr::MultisampleConstPixelBufferAccess &access)
90*35238bceSAndroid Build Coastguard Worker {
91*35238bceSAndroid Build Coastguard Worker return access.raw().getWidth() == 0 || access.raw().getHeight() == 0 || access.raw().getDepth() == 0;
92*35238bceSAndroid Build Coastguard Worker }
93*35238bceSAndroid Build Coastguard Worker
isEmpty(const IVec4 & rect)94*35238bceSAndroid Build Coastguard Worker static inline bool isEmpty(const IVec4 &rect)
95*35238bceSAndroid Build Coastguard Worker {
96*35238bceSAndroid Build Coastguard Worker return rect.z() == 0 || rect.w() == 0;
97*35238bceSAndroid Build Coastguard Worker }
98*35238bceSAndroid Build Coastguard Worker
getNumMipLevels1D(int size)99*35238bceSAndroid Build Coastguard Worker inline int getNumMipLevels1D(int size)
100*35238bceSAndroid Build Coastguard Worker {
101*35238bceSAndroid Build Coastguard Worker return deLog2Floor32(size) + 1;
102*35238bceSAndroid Build Coastguard Worker }
103*35238bceSAndroid Build Coastguard Worker
getNumMipLevels2D(int width,int height)104*35238bceSAndroid Build Coastguard Worker inline int getNumMipLevels2D(int width, int height)
105*35238bceSAndroid Build Coastguard Worker {
106*35238bceSAndroid Build Coastguard Worker return deLog2Floor32(de::max(width, height)) + 1;
107*35238bceSAndroid Build Coastguard Worker }
108*35238bceSAndroid Build Coastguard Worker
getNumMipLevels3D(int width,int height,int depth)109*35238bceSAndroid Build Coastguard Worker inline int getNumMipLevels3D(int width, int height, int depth)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker return deLog2Floor32(de::max(width, de::max(height, depth))) + 1;
112*35238bceSAndroid Build Coastguard Worker }
113*35238bceSAndroid Build Coastguard Worker
getMipLevelSize(int baseLevelSize,int levelNdx)114*35238bceSAndroid Build Coastguard Worker inline int getMipLevelSize(int baseLevelSize, int levelNdx)
115*35238bceSAndroid Build Coastguard Worker {
116*35238bceSAndroid Build Coastguard Worker return de::max(baseLevelSize >> levelNdx, 1);
117*35238bceSAndroid Build Coastguard Worker }
118*35238bceSAndroid Build Coastguard Worker
isMipmapFilter(const tcu::Sampler::FilterMode mode)119*35238bceSAndroid Build Coastguard Worker inline bool isMipmapFilter(const tcu::Sampler::FilterMode mode)
120*35238bceSAndroid Build Coastguard Worker {
121*35238bceSAndroid Build Coastguard Worker return mode != tcu::Sampler::NEAREST && mode != tcu::Sampler::LINEAR;
122*35238bceSAndroid Build Coastguard Worker }
123*35238bceSAndroid Build Coastguard Worker
texTargetToFace(Framebuffer::TexTarget target)124*35238bceSAndroid Build Coastguard Worker static tcu::CubeFace texTargetToFace(Framebuffer::TexTarget target)
125*35238bceSAndroid Build Coastguard Worker {
126*35238bceSAndroid Build Coastguard Worker switch (target)
127*35238bceSAndroid Build Coastguard Worker {
128*35238bceSAndroid Build Coastguard Worker case Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_X:
129*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_NEGATIVE_X;
130*35238bceSAndroid Build Coastguard Worker case Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_X:
131*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_POSITIVE_X;
132*35238bceSAndroid Build Coastguard Worker case Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_Y:
133*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_NEGATIVE_Y;
134*35238bceSAndroid Build Coastguard Worker case Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_Y:
135*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_POSITIVE_Y;
136*35238bceSAndroid Build Coastguard Worker case Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_Z:
137*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_NEGATIVE_Z;
138*35238bceSAndroid Build Coastguard Worker case Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_Z:
139*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_POSITIVE_Z;
140*35238bceSAndroid Build Coastguard Worker default:
141*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_LAST;
142*35238bceSAndroid Build Coastguard Worker }
143*35238bceSAndroid Build Coastguard Worker }
144*35238bceSAndroid Build Coastguard Worker
texLayeredTypeToTarget(Texture::Type type)145*35238bceSAndroid Build Coastguard Worker static Framebuffer::TexTarget texLayeredTypeToTarget(Texture::Type type)
146*35238bceSAndroid Build Coastguard Worker {
147*35238bceSAndroid Build Coastguard Worker switch (type)
148*35238bceSAndroid Build Coastguard Worker {
149*35238bceSAndroid Build Coastguard Worker case Texture::TYPE_2D_ARRAY:
150*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_2D_ARRAY;
151*35238bceSAndroid Build Coastguard Worker case Texture::TYPE_3D:
152*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_3D;
153*35238bceSAndroid Build Coastguard Worker case Texture::TYPE_CUBE_MAP_ARRAY:
154*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_ARRAY;
155*35238bceSAndroid Build Coastguard Worker default:
156*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_LAST;
157*35238bceSAndroid Build Coastguard Worker }
158*35238bceSAndroid Build Coastguard Worker }
159*35238bceSAndroid Build Coastguard Worker
mapGLCubeFace(uint32_t face)160*35238bceSAndroid Build Coastguard Worker static tcu::CubeFace mapGLCubeFace(uint32_t face)
161*35238bceSAndroid Build Coastguard Worker {
162*35238bceSAndroid Build Coastguard Worker switch (face)
163*35238bceSAndroid Build Coastguard Worker {
164*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
165*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_NEGATIVE_X;
166*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
167*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_POSITIVE_X;
168*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
169*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_NEGATIVE_Y;
170*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
171*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_POSITIVE_Y;
172*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
173*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_NEGATIVE_Z;
174*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
175*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_POSITIVE_Z;
176*35238bceSAndroid Build Coastguard Worker default:
177*35238bceSAndroid Build Coastguard Worker return tcu::CUBEFACE_LAST;
178*35238bceSAndroid Build Coastguard Worker }
179*35238bceSAndroid Build Coastguard Worker }
180*35238bceSAndroid Build Coastguard Worker
toTextureFormat(const tcu::PixelFormat & pixelFmt)181*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat toTextureFormat(const tcu::PixelFormat &pixelFmt)
182*35238bceSAndroid Build Coastguard Worker {
183*35238bceSAndroid Build Coastguard Worker static const struct
184*35238bceSAndroid Build Coastguard Worker {
185*35238bceSAndroid Build Coastguard Worker tcu::PixelFormat pixelFmt;
186*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat texFmt;
187*35238bceSAndroid Build Coastguard Worker } pixelFormatMap[] = {
188*35238bceSAndroid Build Coastguard Worker {tcu::PixelFormat(8, 8, 8, 8), tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)},
189*35238bceSAndroid Build Coastguard Worker {tcu::PixelFormat(8, 8, 8, 0), tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8)},
190*35238bceSAndroid Build Coastguard Worker {tcu::PixelFormat(4, 4, 4, 4),
191*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_SHORT_4444)},
192*35238bceSAndroid Build Coastguard Worker {tcu::PixelFormat(5, 5, 5, 1),
193*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_SHORT_5551)},
194*35238bceSAndroid Build Coastguard Worker {tcu::PixelFormat(5, 6, 5, 0),
195*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_SHORT_565)}};
196*35238bceSAndroid Build Coastguard Worker
197*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(pixelFormatMap); ndx++)
198*35238bceSAndroid Build Coastguard Worker {
199*35238bceSAndroid Build Coastguard Worker if (pixelFormatMap[ndx].pixelFmt == pixelFmt)
200*35238bceSAndroid Build Coastguard Worker return pixelFormatMap[ndx].texFmt;
201*35238bceSAndroid Build Coastguard Worker }
202*35238bceSAndroid Build Coastguard Worker
203*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map pixel format to texture format");
204*35238bceSAndroid Build Coastguard Worker }
205*35238bceSAndroid Build Coastguard Worker
toNonSRGBFormat(const tcu::TextureFormat & fmt)206*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat toNonSRGBFormat(const tcu::TextureFormat &fmt)
207*35238bceSAndroid Build Coastguard Worker {
208*35238bceSAndroid Build Coastguard Worker switch (fmt.order)
209*35238bceSAndroid Build Coastguard Worker {
210*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::sRGB:
211*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::RGB, fmt.type);
212*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::sRGBA:
213*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::RGBA, fmt.type);
214*35238bceSAndroid Build Coastguard Worker default:
215*35238bceSAndroid Build Coastguard Worker return fmt;
216*35238bceSAndroid Build Coastguard Worker }
217*35238bceSAndroid Build Coastguard Worker }
218*35238bceSAndroid Build Coastguard Worker
getDepthFormat(int depthBits)219*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat getDepthFormat(int depthBits)
220*35238bceSAndroid Build Coastguard Worker {
221*35238bceSAndroid Build Coastguard Worker switch (depthBits)
222*35238bceSAndroid Build Coastguard Worker {
223*35238bceSAndroid Build Coastguard Worker case 8:
224*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT8);
225*35238bceSAndroid Build Coastguard Worker case 16:
226*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
227*35238bceSAndroid Build Coastguard Worker case 24:
228*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNSIGNED_INT_24_8);
229*35238bceSAndroid Build Coastguard Worker case 32:
230*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
231*35238bceSAndroid Build Coastguard Worker default:
232*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map depth buffer format");
233*35238bceSAndroid Build Coastguard Worker }
234*35238bceSAndroid Build Coastguard Worker }
235*35238bceSAndroid Build Coastguard Worker
getStencilFormat(int stencilBits)236*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat getStencilFormat(int stencilBits)
237*35238bceSAndroid Build Coastguard Worker {
238*35238bceSAndroid Build Coastguard Worker switch (stencilBits)
239*35238bceSAndroid Build Coastguard Worker {
240*35238bceSAndroid Build Coastguard Worker case 8:
241*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT8);
242*35238bceSAndroid Build Coastguard Worker case 16:
243*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT16);
244*35238bceSAndroid Build Coastguard Worker case 24:
245*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT_24_8);
246*35238bceSAndroid Build Coastguard Worker case 32:
247*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT32);
248*35238bceSAndroid Build Coastguard Worker default:
249*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map depth buffer format");
250*35238bceSAndroid Build Coastguard Worker }
251*35238bceSAndroid Build Coastguard Worker }
252*35238bceSAndroid Build Coastguard Worker
intersect(const tcu::IVec4 & a,const tcu::IVec4 & b)253*35238bceSAndroid Build Coastguard Worker static inline tcu::IVec4 intersect(const tcu::IVec4 &a, const tcu::IVec4 &b)
254*35238bceSAndroid Build Coastguard Worker {
255*35238bceSAndroid Build Coastguard Worker int x0 = de::max(a.x(), b.x());
256*35238bceSAndroid Build Coastguard Worker int y0 = de::max(a.y(), b.y());
257*35238bceSAndroid Build Coastguard Worker int x1 = de::min(a.x() + a.z(), b.x() + b.z());
258*35238bceSAndroid Build Coastguard Worker int y1 = de::min(a.y() + a.w(), b.y() + b.w());
259*35238bceSAndroid Build Coastguard Worker int w = de::max(0, x1 - x0);
260*35238bceSAndroid Build Coastguard Worker int h = de::max(0, y1 - y0);
261*35238bceSAndroid Build Coastguard Worker
262*35238bceSAndroid Build Coastguard Worker return tcu::IVec4(x0, y0, w, h);
263*35238bceSAndroid Build Coastguard Worker }
264*35238bceSAndroid Build Coastguard Worker
getBufferRect(const rr::MultisampleConstPixelBufferAccess & access)265*35238bceSAndroid Build Coastguard Worker static inline tcu::IVec4 getBufferRect(const rr::MultisampleConstPixelBufferAccess &access)
266*35238bceSAndroid Build Coastguard Worker {
267*35238bceSAndroid Build Coastguard Worker return tcu::IVec4(0, 0, access.raw().getHeight(), access.raw().getDepth());
268*35238bceSAndroid Build Coastguard Worker }
269*35238bceSAndroid Build Coastguard Worker
ReferenceContextLimits(const glu::RenderContext & renderCtx)270*35238bceSAndroid Build Coastguard Worker ReferenceContextLimits::ReferenceContextLimits(const glu::RenderContext &renderCtx)
271*35238bceSAndroid Build Coastguard Worker : contextType(renderCtx.getType())
272*35238bceSAndroid Build Coastguard Worker , maxTextureImageUnits(0)
273*35238bceSAndroid Build Coastguard Worker , maxTexture2DSize(0)
274*35238bceSAndroid Build Coastguard Worker , maxTextureCubeSize(0)
275*35238bceSAndroid Build Coastguard Worker , maxTexture2DArrayLayers(0)
276*35238bceSAndroid Build Coastguard Worker , maxTexture3DSize(0)
277*35238bceSAndroid Build Coastguard Worker , maxRenderbufferSize(0)
278*35238bceSAndroid Build Coastguard Worker , maxVertexAttribs(0)
279*35238bceSAndroid Build Coastguard Worker , subpixelBits(0)
280*35238bceSAndroid Build Coastguard Worker {
281*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = renderCtx.getFunctions();
282*35238bceSAndroid Build Coastguard Worker
283*35238bceSAndroid Build Coastguard Worker // When the OpenGL ES's major version bigger than 3, and the expect context version is 3,
284*35238bceSAndroid Build Coastguard Worker // we need query the real GL context version and update the real version to reference context.
285*35238bceSAndroid Build Coastguard Worker if (glu::IsES3Compatible(gl) && isES2Context(contextType))
286*35238bceSAndroid Build Coastguard Worker {
287*35238bceSAndroid Build Coastguard Worker int majorVersion = contextType.getMajorVersion();
288*35238bceSAndroid Build Coastguard Worker int minorVersion = contextType.getMinorVersion();
289*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAJOR_VERSION, &majorVersion);
290*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MINOR_VERSION, &minorVersion);
291*35238bceSAndroid Build Coastguard Worker contextType.setAPI(glu::ApiType::es(majorVersion, minorVersion));
292*35238bceSAndroid Build Coastguard Worker }
293*35238bceSAndroid Build Coastguard Worker
294*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
295*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexture2DSize);
296*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxTextureCubeSize);
297*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize);
298*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
299*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_SUBPIXEL_BITS, &subpixelBits);
300*35238bceSAndroid Build Coastguard Worker
301*35238bceSAndroid Build Coastguard Worker if (contextSupports(contextType, glu::ApiType::es(3, 0)) || glu::isContextTypeGLCore(contextType))
302*35238bceSAndroid Build Coastguard Worker {
303*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTexture2DArrayLayers);
304*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_MAX_3D_TEXTURE_SIZE, &maxTexture3DSize);
305*35238bceSAndroid Build Coastguard Worker }
306*35238bceSAndroid Build Coastguard Worker
307*35238bceSAndroid Build Coastguard Worker // Limit texture sizes to supported values
308*35238bceSAndroid Build Coastguard Worker maxTexture2DSize = de::min(maxTexture2DSize, (int)MAX_TEXTURE_SIZE);
309*35238bceSAndroid Build Coastguard Worker maxTextureCubeSize = de::min(maxTextureCubeSize, (int)MAX_TEXTURE_SIZE);
310*35238bceSAndroid Build Coastguard Worker maxTexture3DSize = de::min(maxTexture3DSize, (int)MAX_TEXTURE_SIZE);
311*35238bceSAndroid Build Coastguard Worker
312*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), GL_NO_ERROR);
313*35238bceSAndroid Build Coastguard Worker
314*35238bceSAndroid Build Coastguard Worker // \todo [pyry] Figure out following things:
315*35238bceSAndroid Build Coastguard Worker // + supported fbo configurations
316*35238bceSAndroid Build Coastguard Worker // ...
317*35238bceSAndroid Build Coastguard Worker
318*35238bceSAndroid Build Coastguard Worker // \todo [2013-08-01 pyry] Do we want to make these conditional based on renderCtx?
319*35238bceSAndroid Build Coastguard Worker addExtension("GL_EXT_color_buffer_half_float");
320*35238bceSAndroid Build Coastguard Worker addExtension("GL_EXT_color_buffer_float");
321*35238bceSAndroid Build Coastguard Worker
322*35238bceSAndroid Build Coastguard Worker if (contextSupports(contextType, glu::ApiType::es(3, 1)))
323*35238bceSAndroid Build Coastguard Worker addExtension("GL_EXT_texture_cube_map_array");
324*35238bceSAndroid Build Coastguard Worker }
325*35238bceSAndroid Build Coastguard Worker
addExtension(const char * extension)326*35238bceSAndroid Build Coastguard Worker void ReferenceContextLimits::addExtension(const char *extension)
327*35238bceSAndroid Build Coastguard Worker {
328*35238bceSAndroid Build Coastguard Worker extensionList.push_back(extension);
329*35238bceSAndroid Build Coastguard Worker
330*35238bceSAndroid Build Coastguard Worker if (!extensionStr.empty())
331*35238bceSAndroid Build Coastguard Worker extensionStr += " ";
332*35238bceSAndroid Build Coastguard Worker extensionStr += extension;
333*35238bceSAndroid Build Coastguard Worker }
334*35238bceSAndroid Build Coastguard Worker
ReferenceContextBuffers(const tcu::PixelFormat & colorBits,int depthBits,int stencilBits,int width,int height,int samples)335*35238bceSAndroid Build Coastguard Worker ReferenceContextBuffers::ReferenceContextBuffers(const tcu::PixelFormat &colorBits, int depthBits, int stencilBits,
336*35238bceSAndroid Build Coastguard Worker int width, int height, int samples)
337*35238bceSAndroid Build Coastguard Worker {
338*35238bceSAndroid Build Coastguard Worker m_colorbuffer.setStorage(toTextureFormat(colorBits), samples, width, height);
339*35238bceSAndroid Build Coastguard Worker
340*35238bceSAndroid Build Coastguard Worker if (depthBits > 0)
341*35238bceSAndroid Build Coastguard Worker m_depthbuffer.setStorage(getDepthFormat(depthBits), samples, width, height);
342*35238bceSAndroid Build Coastguard Worker
343*35238bceSAndroid Build Coastguard Worker if (stencilBits > 0)
344*35238bceSAndroid Build Coastguard Worker m_stencilbuffer.setStorage(getStencilFormat(stencilBits), samples, width, height);
345*35238bceSAndroid Build Coastguard Worker }
346*35238bceSAndroid Build Coastguard Worker
StencilState(void)347*35238bceSAndroid Build Coastguard Worker ReferenceContext::StencilState::StencilState(void)
348*35238bceSAndroid Build Coastguard Worker : func(GL_ALWAYS)
349*35238bceSAndroid Build Coastguard Worker , ref(0)
350*35238bceSAndroid Build Coastguard Worker , opMask(~0u)
351*35238bceSAndroid Build Coastguard Worker , opStencilFail(GL_KEEP)
352*35238bceSAndroid Build Coastguard Worker , opDepthFail(GL_KEEP)
353*35238bceSAndroid Build Coastguard Worker , opDepthPass(GL_KEEP)
354*35238bceSAndroid Build Coastguard Worker , writeMask(~0u)
355*35238bceSAndroid Build Coastguard Worker {
356*35238bceSAndroid Build Coastguard Worker }
357*35238bceSAndroid Build Coastguard Worker
ReferenceContext(const ReferenceContextLimits & limits,const rr::MultisamplePixelBufferAccess & colorbuffer,const rr::MultisamplePixelBufferAccess & depthbuffer,const rr::MultisamplePixelBufferAccess & stencilbuffer)358*35238bceSAndroid Build Coastguard Worker ReferenceContext::ReferenceContext(const ReferenceContextLimits &limits,
359*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &colorbuffer,
360*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &depthbuffer,
361*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &stencilbuffer)
362*35238bceSAndroid Build Coastguard Worker : Context(limits.contextType)
363*35238bceSAndroid Build Coastguard Worker , m_limits(limits)
364*35238bceSAndroid Build Coastguard Worker , m_defaultColorbuffer(colorbuffer)
365*35238bceSAndroid Build Coastguard Worker , m_defaultDepthbuffer(depthbuffer)
366*35238bceSAndroid Build Coastguard Worker , m_defaultStencilbuffer(stencilbuffer)
367*35238bceSAndroid Build Coastguard Worker , m_clientVertexArray(0, m_limits.maxVertexAttribs)
368*35238bceSAndroid Build Coastguard Worker
369*35238bceSAndroid Build Coastguard Worker , m_viewport(0, 0, colorbuffer.raw().getHeight(), colorbuffer.raw().getDepth())
370*35238bceSAndroid Build Coastguard Worker
371*35238bceSAndroid Build Coastguard Worker , m_activeTexture(0)
372*35238bceSAndroid Build Coastguard Worker , m_textureUnits(m_limits.maxTextureImageUnits)
373*35238bceSAndroid Build Coastguard Worker , m_emptyTex1D()
374*35238bceSAndroid Build Coastguard Worker , m_emptyTex2D(isES2Context(limits.contextType))
375*35238bceSAndroid Build Coastguard Worker , m_emptyTexCube(!isES2Context(limits.contextType))
376*35238bceSAndroid Build Coastguard Worker , m_emptyTex2DArray()
377*35238bceSAndroid Build Coastguard Worker , m_emptyTex3D()
378*35238bceSAndroid Build Coastguard Worker , m_emptyTexCubeArray()
379*35238bceSAndroid Build Coastguard Worker
380*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackRowLength(0)
381*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackSkipRows(0)
382*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackSkipPixels(0)
383*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackImageHeight(0)
384*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackSkipImages(0)
385*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackAlignment(4)
386*35238bceSAndroid Build Coastguard Worker , m_pixelPackAlignment(4)
387*35238bceSAndroid Build Coastguard Worker
388*35238bceSAndroid Build Coastguard Worker , m_readFramebufferBinding(DE_NULL)
389*35238bceSAndroid Build Coastguard Worker , m_drawFramebufferBinding(DE_NULL)
390*35238bceSAndroid Build Coastguard Worker , m_renderbufferBinding(DE_NULL)
391*35238bceSAndroid Build Coastguard Worker , m_vertexArrayBinding(DE_NULL)
392*35238bceSAndroid Build Coastguard Worker , m_currentProgram(DE_NULL)
393*35238bceSAndroid Build Coastguard Worker
394*35238bceSAndroid Build Coastguard Worker , m_arrayBufferBinding(DE_NULL)
395*35238bceSAndroid Build Coastguard Worker , m_pixelPackBufferBinding(DE_NULL)
396*35238bceSAndroid Build Coastguard Worker , m_pixelUnpackBufferBinding(DE_NULL)
397*35238bceSAndroid Build Coastguard Worker , m_transformFeedbackBufferBinding(DE_NULL)
398*35238bceSAndroid Build Coastguard Worker , m_uniformBufferBinding(DE_NULL)
399*35238bceSAndroid Build Coastguard Worker , m_copyReadBufferBinding(DE_NULL)
400*35238bceSAndroid Build Coastguard Worker , m_copyWriteBufferBinding(DE_NULL)
401*35238bceSAndroid Build Coastguard Worker , m_drawIndirectBufferBinding(DE_NULL)
402*35238bceSAndroid Build Coastguard Worker
403*35238bceSAndroid Build Coastguard Worker , m_clearColor(0.0f, 0.0f, 0.0f, 0.0f)
404*35238bceSAndroid Build Coastguard Worker , m_clearDepth(1.0f)
405*35238bceSAndroid Build Coastguard Worker , m_clearStencil(0)
406*35238bceSAndroid Build Coastguard Worker , m_scissorEnabled(false)
407*35238bceSAndroid Build Coastguard Worker , m_scissorBox(m_viewport)
408*35238bceSAndroid Build Coastguard Worker , m_stencilTestEnabled(false)
409*35238bceSAndroid Build Coastguard Worker , m_depthTestEnabled(false)
410*35238bceSAndroid Build Coastguard Worker , m_depthFunc(GL_LESS)
411*35238bceSAndroid Build Coastguard Worker , m_depthRangeNear(0.0f)
412*35238bceSAndroid Build Coastguard Worker , m_depthRangeFar(1.0f)
413*35238bceSAndroid Build Coastguard Worker , m_polygonOffsetFactor(0.0f)
414*35238bceSAndroid Build Coastguard Worker , m_polygonOffsetUnits(0.0f)
415*35238bceSAndroid Build Coastguard Worker , m_polygonOffsetFillEnabled(false)
416*35238bceSAndroid Build Coastguard Worker , m_provokingFirstVertexConvention(false)
417*35238bceSAndroid Build Coastguard Worker , m_blendEnabled(false)
418*35238bceSAndroid Build Coastguard Worker , m_blendModeRGB(GL_FUNC_ADD)
419*35238bceSAndroid Build Coastguard Worker , m_blendModeAlpha(GL_FUNC_ADD)
420*35238bceSAndroid Build Coastguard Worker , m_blendFactorSrcRGB(GL_ONE)
421*35238bceSAndroid Build Coastguard Worker , m_blendFactorDstRGB(GL_ZERO)
422*35238bceSAndroid Build Coastguard Worker , m_blendFactorSrcAlpha(GL_ONE)
423*35238bceSAndroid Build Coastguard Worker , m_blendFactorDstAlpha(GL_ZERO)
424*35238bceSAndroid Build Coastguard Worker , m_blendColor(0.0f, 0.0f, 0.0f, 0.0f)
425*35238bceSAndroid Build Coastguard Worker , m_sRGBUpdateEnabled(true)
426*35238bceSAndroid Build Coastguard Worker , m_depthClampEnabled(false)
427*35238bceSAndroid Build Coastguard Worker , m_colorMask(true, true, true, true)
428*35238bceSAndroid Build Coastguard Worker , m_depthMask(true)
429*35238bceSAndroid Build Coastguard Worker , m_currentAttribs(m_limits.maxVertexAttribs, rr::GenericVec4(tcu::Vec4(0, 0, 0, 1)))
430*35238bceSAndroid Build Coastguard Worker , m_lineWidth(1.0f)
431*35238bceSAndroid Build Coastguard Worker , m_primitiveRestartFixedIndex(false)
432*35238bceSAndroid Build Coastguard Worker , m_primitiveRestartSettableIndex(false)
433*35238bceSAndroid Build Coastguard Worker , m_primitiveRestartIndex(0)
434*35238bceSAndroid Build Coastguard Worker
435*35238bceSAndroid Build Coastguard Worker , m_lastError(GL_NO_ERROR)
436*35238bceSAndroid Build Coastguard Worker {
437*35238bceSAndroid Build Coastguard Worker // Create empty textures to be used when texture objects are incomplete.
438*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.getSampler().wrapS = tcu::Sampler::CLAMP_TO_EDGE;
439*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.getSampler().wrapT = tcu::Sampler::CLAMP_TO_EDGE;
440*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.getSampler().minFilter = tcu::Sampler::NEAREST;
441*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.getSampler().magFilter = tcu::Sampler::NEAREST;
442*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.allocLevel(0, tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1);
443*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.getLevel(0).setPixel(Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0, 0);
444*35238bceSAndroid Build Coastguard Worker m_emptyTex1D.updateView(tcu::Sampler::MODE_LAST);
445*35238bceSAndroid Build Coastguard Worker
446*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.getSampler().wrapS = tcu::Sampler::CLAMP_TO_EDGE;
447*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.getSampler().wrapT = tcu::Sampler::CLAMP_TO_EDGE;
448*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.getSampler().minFilter = tcu::Sampler::NEAREST;
449*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.getSampler().magFilter = tcu::Sampler::NEAREST;
450*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.allocLevel(0, tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1);
451*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.getLevel(0).setPixel(Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0, 0);
452*35238bceSAndroid Build Coastguard Worker m_emptyTex2D.updateView(tcu::Sampler::MODE_LAST);
453*35238bceSAndroid Build Coastguard Worker
454*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.getSampler().wrapS = tcu::Sampler::CLAMP_TO_EDGE;
455*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.getSampler().wrapT = tcu::Sampler::CLAMP_TO_EDGE;
456*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.getSampler().minFilter = tcu::Sampler::NEAREST;
457*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.getSampler().magFilter = tcu::Sampler::NEAREST;
458*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
459*35238bceSAndroid Build Coastguard Worker {
460*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.allocFace(0, (tcu::CubeFace)face,
461*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1);
462*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.getFace(0, (tcu::CubeFace)face).setPixel(Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0, 0);
463*35238bceSAndroid Build Coastguard Worker }
464*35238bceSAndroid Build Coastguard Worker m_emptyTexCube.updateView(tcu::Sampler::MODE_LAST);
465*35238bceSAndroid Build Coastguard Worker
466*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.getSampler().wrapS = tcu::Sampler::CLAMP_TO_EDGE;
467*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.getSampler().wrapT = tcu::Sampler::CLAMP_TO_EDGE;
468*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.getSampler().minFilter = tcu::Sampler::NEAREST;
469*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.getSampler().magFilter = tcu::Sampler::NEAREST;
470*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.allocLevel(0, tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1,
471*35238bceSAndroid Build Coastguard Worker 1);
472*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.getLevel(0).setPixel(Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0, 0);
473*35238bceSAndroid Build Coastguard Worker m_emptyTex2DArray.updateView(tcu::Sampler::MODE_LAST);
474*35238bceSAndroid Build Coastguard Worker
475*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.getSampler().wrapS = tcu::Sampler::CLAMP_TO_EDGE;
476*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.getSampler().wrapT = tcu::Sampler::CLAMP_TO_EDGE;
477*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.getSampler().wrapR = tcu::Sampler::CLAMP_TO_EDGE;
478*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.getSampler().minFilter = tcu::Sampler::NEAREST;
479*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.getSampler().magFilter = tcu::Sampler::NEAREST;
480*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.allocLevel(0, tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1, 1, 1);
481*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.getLevel(0).setPixel(Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0, 0);
482*35238bceSAndroid Build Coastguard Worker m_emptyTex3D.updateView(tcu::Sampler::MODE_LAST);
483*35238bceSAndroid Build Coastguard Worker
484*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.getSampler().wrapS = tcu::Sampler::CLAMP_TO_EDGE;
485*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.getSampler().wrapT = tcu::Sampler::CLAMP_TO_EDGE;
486*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.getSampler().minFilter = tcu::Sampler::NEAREST;
487*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.getSampler().magFilter = tcu::Sampler::NEAREST;
488*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.allocLevel(0, tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 1,
489*35238bceSAndroid Build Coastguard Worker 1, 6);
490*35238bceSAndroid Build Coastguard Worker for (int faceNdx = 0; faceNdx < 6; faceNdx++)
491*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.getLevel(0).setPixel(Vec4(0.0f, 0.0f, 0.0f, 1.0f), 0, 0, faceNdx);
492*35238bceSAndroid Build Coastguard Worker m_emptyTexCubeArray.updateView(tcu::Sampler::MODE_LAST);
493*35238bceSAndroid Build Coastguard Worker
494*35238bceSAndroid Build Coastguard Worker for (int unitNdx = 0; unitNdx < m_limits.maxTextureImageUnits; unitNdx++)
495*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].defaultCubeTex.getSampler().seamlessCubeMap = !isES2Context(limits.contextType);
496*35238bceSAndroid Build Coastguard Worker
497*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
498*35238bceSAndroid Build Coastguard Worker m_sRGBUpdateEnabled = false;
499*35238bceSAndroid Build Coastguard Worker }
500*35238bceSAndroid Build Coastguard Worker
~ReferenceContext(void)501*35238bceSAndroid Build Coastguard Worker ReferenceContext::~ReferenceContext(void)
502*35238bceSAndroid Build Coastguard Worker {
503*35238bceSAndroid Build Coastguard Worker // Destroy all objects -- verifies that ref counting works
504*35238bceSAndroid Build Coastguard Worker {
505*35238bceSAndroid Build Coastguard Worker vector<VertexArray *> vertexArrays;
506*35238bceSAndroid Build Coastguard Worker m_vertexArrays.getAll(vertexArrays);
507*35238bceSAndroid Build Coastguard Worker for (vector<VertexArray *>::iterator i = vertexArrays.begin(); i != vertexArrays.end(); i++)
508*35238bceSAndroid Build Coastguard Worker deleteVertexArray(*i);
509*35238bceSAndroid Build Coastguard Worker
510*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_clientVertexArray.getRefCount() == 1);
511*35238bceSAndroid Build Coastguard Worker }
512*35238bceSAndroid Build Coastguard Worker
513*35238bceSAndroid Build Coastguard Worker {
514*35238bceSAndroid Build Coastguard Worker vector<Texture *> textures;
515*35238bceSAndroid Build Coastguard Worker m_textures.getAll(textures);
516*35238bceSAndroid Build Coastguard Worker for (vector<Texture *>::iterator i = textures.begin(); i != textures.end(); i++)
517*35238bceSAndroid Build Coastguard Worker deleteTexture(*i);
518*35238bceSAndroid Build Coastguard Worker }
519*35238bceSAndroid Build Coastguard Worker
520*35238bceSAndroid Build Coastguard Worker {
521*35238bceSAndroid Build Coastguard Worker vector<Framebuffer *> framebuffers;
522*35238bceSAndroid Build Coastguard Worker m_framebuffers.getAll(framebuffers);
523*35238bceSAndroid Build Coastguard Worker for (vector<Framebuffer *>::iterator i = framebuffers.begin(); i != framebuffers.end(); i++)
524*35238bceSAndroid Build Coastguard Worker deleteFramebuffer(*i);
525*35238bceSAndroid Build Coastguard Worker }
526*35238bceSAndroid Build Coastguard Worker
527*35238bceSAndroid Build Coastguard Worker {
528*35238bceSAndroid Build Coastguard Worker vector<Renderbuffer *> renderbuffers;
529*35238bceSAndroid Build Coastguard Worker m_renderbuffers.getAll(renderbuffers);
530*35238bceSAndroid Build Coastguard Worker for (vector<Renderbuffer *>::iterator i = renderbuffers.begin(); i != renderbuffers.end(); i++)
531*35238bceSAndroid Build Coastguard Worker deleteRenderbuffer(*i);
532*35238bceSAndroid Build Coastguard Worker }
533*35238bceSAndroid Build Coastguard Worker
534*35238bceSAndroid Build Coastguard Worker {
535*35238bceSAndroid Build Coastguard Worker vector<DataBuffer *> buffers;
536*35238bceSAndroid Build Coastguard Worker m_buffers.getAll(buffers);
537*35238bceSAndroid Build Coastguard Worker for (vector<DataBuffer *>::iterator i = buffers.begin(); i != buffers.end(); i++)
538*35238bceSAndroid Build Coastguard Worker deleteBuffer(*i);
539*35238bceSAndroid Build Coastguard Worker }
540*35238bceSAndroid Build Coastguard Worker
541*35238bceSAndroid Build Coastguard Worker {
542*35238bceSAndroid Build Coastguard Worker vector<ShaderProgramObjectContainer *> programs;
543*35238bceSAndroid Build Coastguard Worker m_programs.getAll(programs);
544*35238bceSAndroid Build Coastguard Worker for (vector<ShaderProgramObjectContainer *>::iterator i = programs.begin(); i != programs.end(); i++)
545*35238bceSAndroid Build Coastguard Worker deleteProgramObject(*i);
546*35238bceSAndroid Build Coastguard Worker }
547*35238bceSAndroid Build Coastguard Worker }
548*35238bceSAndroid Build Coastguard Worker
activeTexture(uint32_t texture)549*35238bceSAndroid Build Coastguard Worker void ReferenceContext::activeTexture(uint32_t texture)
550*35238bceSAndroid Build Coastguard Worker {
551*35238bceSAndroid Build Coastguard Worker if (deInBounds32(texture, GL_TEXTURE0, GL_TEXTURE0 + (uint32_t)m_textureUnits.size()))
552*35238bceSAndroid Build Coastguard Worker m_activeTexture = texture - GL_TEXTURE0;
553*35238bceSAndroid Build Coastguard Worker else
554*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
555*35238bceSAndroid Build Coastguard Worker }
556*35238bceSAndroid Build Coastguard Worker
setTex1DBinding(int unitNdx,Texture1D * texture)557*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setTex1DBinding(int unitNdx, Texture1D *texture)
558*35238bceSAndroid Build Coastguard Worker {
559*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].tex1DBinding)
560*35238bceSAndroid Build Coastguard Worker {
561*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(m_textureUnits[unitNdx].tex1DBinding);
562*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex1DBinding = DE_NULL;
563*35238bceSAndroid Build Coastguard Worker }
564*35238bceSAndroid Build Coastguard Worker
565*35238bceSAndroid Build Coastguard Worker if (texture)
566*35238bceSAndroid Build Coastguard Worker {
567*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
568*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex1DBinding = texture;
569*35238bceSAndroid Build Coastguard Worker }
570*35238bceSAndroid Build Coastguard Worker }
571*35238bceSAndroid Build Coastguard Worker
setTex2DBinding(int unitNdx,Texture2D * texture)572*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setTex2DBinding(int unitNdx, Texture2D *texture)
573*35238bceSAndroid Build Coastguard Worker {
574*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].tex2DBinding)
575*35238bceSAndroid Build Coastguard Worker {
576*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(m_textureUnits[unitNdx].tex2DBinding);
577*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex2DBinding = DE_NULL;
578*35238bceSAndroid Build Coastguard Worker }
579*35238bceSAndroid Build Coastguard Worker
580*35238bceSAndroid Build Coastguard Worker if (texture)
581*35238bceSAndroid Build Coastguard Worker {
582*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
583*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex2DBinding = texture;
584*35238bceSAndroid Build Coastguard Worker }
585*35238bceSAndroid Build Coastguard Worker }
586*35238bceSAndroid Build Coastguard Worker
setTexCubeBinding(int unitNdx,TextureCube * texture)587*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setTexCubeBinding(int unitNdx, TextureCube *texture)
588*35238bceSAndroid Build Coastguard Worker {
589*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].texCubeBinding)
590*35238bceSAndroid Build Coastguard Worker {
591*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(m_textureUnits[unitNdx].texCubeBinding);
592*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].texCubeBinding = DE_NULL;
593*35238bceSAndroid Build Coastguard Worker }
594*35238bceSAndroid Build Coastguard Worker
595*35238bceSAndroid Build Coastguard Worker if (texture)
596*35238bceSAndroid Build Coastguard Worker {
597*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
598*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].texCubeBinding = texture;
599*35238bceSAndroid Build Coastguard Worker }
600*35238bceSAndroid Build Coastguard Worker }
601*35238bceSAndroid Build Coastguard Worker
setTex2DArrayBinding(int unitNdx,Texture2DArray * texture)602*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setTex2DArrayBinding(int unitNdx, Texture2DArray *texture)
603*35238bceSAndroid Build Coastguard Worker {
604*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].tex2DArrayBinding)
605*35238bceSAndroid Build Coastguard Worker {
606*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(m_textureUnits[unitNdx].tex2DArrayBinding);
607*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex2DArrayBinding = DE_NULL;
608*35238bceSAndroid Build Coastguard Worker }
609*35238bceSAndroid Build Coastguard Worker
610*35238bceSAndroid Build Coastguard Worker if (texture)
611*35238bceSAndroid Build Coastguard Worker {
612*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
613*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex2DArrayBinding = texture;
614*35238bceSAndroid Build Coastguard Worker }
615*35238bceSAndroid Build Coastguard Worker }
616*35238bceSAndroid Build Coastguard Worker
setTex3DBinding(int unitNdx,Texture3D * texture)617*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setTex3DBinding(int unitNdx, Texture3D *texture)
618*35238bceSAndroid Build Coastguard Worker {
619*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].tex3DBinding)
620*35238bceSAndroid Build Coastguard Worker {
621*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(m_textureUnits[unitNdx].tex3DBinding);
622*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex3DBinding = DE_NULL;
623*35238bceSAndroid Build Coastguard Worker }
624*35238bceSAndroid Build Coastguard Worker
625*35238bceSAndroid Build Coastguard Worker if (texture)
626*35238bceSAndroid Build Coastguard Worker {
627*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
628*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].tex3DBinding = texture;
629*35238bceSAndroid Build Coastguard Worker }
630*35238bceSAndroid Build Coastguard Worker }
631*35238bceSAndroid Build Coastguard Worker
setTexCubeArrayBinding(int unitNdx,TextureCubeArray * texture)632*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setTexCubeArrayBinding(int unitNdx, TextureCubeArray *texture)
633*35238bceSAndroid Build Coastguard Worker {
634*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].texCubeArrayBinding)
635*35238bceSAndroid Build Coastguard Worker {
636*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(m_textureUnits[unitNdx].texCubeArrayBinding);
637*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].texCubeArrayBinding = DE_NULL;
638*35238bceSAndroid Build Coastguard Worker }
639*35238bceSAndroid Build Coastguard Worker
640*35238bceSAndroid Build Coastguard Worker if (texture)
641*35238bceSAndroid Build Coastguard Worker {
642*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
643*35238bceSAndroid Build Coastguard Worker m_textureUnits[unitNdx].texCubeArrayBinding = texture;
644*35238bceSAndroid Build Coastguard Worker }
645*35238bceSAndroid Build Coastguard Worker }
646*35238bceSAndroid Build Coastguard Worker
bindTexture(uint32_t target,uint32_t texture)647*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bindTexture(uint32_t target, uint32_t texture)
648*35238bceSAndroid Build Coastguard Worker {
649*35238bceSAndroid Build Coastguard Worker int unitNdx = m_activeTexture;
650*35238bceSAndroid Build Coastguard Worker
651*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_TEXTURE_1D && target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP &&
652*35238bceSAndroid Build Coastguard Worker target != GL_TEXTURE_2D_ARRAY && target != GL_TEXTURE_3D && target != GL_TEXTURE_CUBE_MAP_ARRAY,
653*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
654*35238bceSAndroid Build Coastguard Worker
655*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(glu::isContextTypeES(m_limits.contextType) && (target == GL_TEXTURE_1D), GL_INVALID_ENUM, RC_RET_VOID);
656*35238bceSAndroid Build Coastguard Worker
657*35238bceSAndroid Build Coastguard Worker if (texture == 0)
658*35238bceSAndroid Build Coastguard Worker {
659*35238bceSAndroid Build Coastguard Worker // Clear binding.
660*35238bceSAndroid Build Coastguard Worker switch (target)
661*35238bceSAndroid Build Coastguard Worker {
662*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_1D:
663*35238bceSAndroid Build Coastguard Worker setTex1DBinding(unitNdx, DE_NULL);
664*35238bceSAndroid Build Coastguard Worker break;
665*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
666*35238bceSAndroid Build Coastguard Worker setTex2DBinding(unitNdx, DE_NULL);
667*35238bceSAndroid Build Coastguard Worker break;
668*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP:
669*35238bceSAndroid Build Coastguard Worker setTexCubeBinding(unitNdx, DE_NULL);
670*35238bceSAndroid Build Coastguard Worker break;
671*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D_ARRAY:
672*35238bceSAndroid Build Coastguard Worker setTex2DArrayBinding(unitNdx, DE_NULL);
673*35238bceSAndroid Build Coastguard Worker break;
674*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_3D:
675*35238bceSAndroid Build Coastguard Worker setTex3DBinding(unitNdx, DE_NULL);
676*35238bceSAndroid Build Coastguard Worker break;
677*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_ARRAY:
678*35238bceSAndroid Build Coastguard Worker setTexCubeArrayBinding(unitNdx, DE_NULL);
679*35238bceSAndroid Build Coastguard Worker break;
680*35238bceSAndroid Build Coastguard Worker default:
681*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
682*35238bceSAndroid Build Coastguard Worker }
683*35238bceSAndroid Build Coastguard Worker }
684*35238bceSAndroid Build Coastguard Worker else
685*35238bceSAndroid Build Coastguard Worker {
686*35238bceSAndroid Build Coastguard Worker Texture *texObj = m_textures.find(texture);
687*35238bceSAndroid Build Coastguard Worker
688*35238bceSAndroid Build Coastguard Worker if (texObj)
689*35238bceSAndroid Build Coastguard Worker {
690*35238bceSAndroid Build Coastguard Worker // Validate type.
691*35238bceSAndroid Build Coastguard Worker Texture::Type expectedType = Texture::TYPE_LAST;
692*35238bceSAndroid Build Coastguard Worker switch (target)
693*35238bceSAndroid Build Coastguard Worker {
694*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_1D:
695*35238bceSAndroid Build Coastguard Worker expectedType = Texture::TYPE_1D;
696*35238bceSAndroid Build Coastguard Worker break;
697*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
698*35238bceSAndroid Build Coastguard Worker expectedType = Texture::TYPE_2D;
699*35238bceSAndroid Build Coastguard Worker break;
700*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP:
701*35238bceSAndroid Build Coastguard Worker expectedType = Texture::TYPE_CUBE_MAP;
702*35238bceSAndroid Build Coastguard Worker break;
703*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D_ARRAY:
704*35238bceSAndroid Build Coastguard Worker expectedType = Texture::TYPE_2D_ARRAY;
705*35238bceSAndroid Build Coastguard Worker break;
706*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_3D:
707*35238bceSAndroid Build Coastguard Worker expectedType = Texture::TYPE_3D;
708*35238bceSAndroid Build Coastguard Worker break;
709*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_ARRAY:
710*35238bceSAndroid Build Coastguard Worker expectedType = Texture::TYPE_CUBE_MAP_ARRAY;
711*35238bceSAndroid Build Coastguard Worker break;
712*35238bceSAndroid Build Coastguard Worker default:
713*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
714*35238bceSAndroid Build Coastguard Worker }
715*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texObj->getType() != expectedType, GL_INVALID_OPERATION, RC_RET_VOID);
716*35238bceSAndroid Build Coastguard Worker }
717*35238bceSAndroid Build Coastguard Worker else
718*35238bceSAndroid Build Coastguard Worker {
719*35238bceSAndroid Build Coastguard Worker // New texture object.
720*35238bceSAndroid Build Coastguard Worker bool seamlessCubeMap = !isES2Context(m_limits.contextType);
721*35238bceSAndroid Build Coastguard Worker switch (target)
722*35238bceSAndroid Build Coastguard Worker {
723*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_1D:
724*35238bceSAndroid Build Coastguard Worker texObj = new Texture1D(texture);
725*35238bceSAndroid Build Coastguard Worker break;
726*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
727*35238bceSAndroid Build Coastguard Worker texObj = new Texture2D(texture);
728*35238bceSAndroid Build Coastguard Worker break;
729*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP:
730*35238bceSAndroid Build Coastguard Worker texObj = new TextureCube(texture, seamlessCubeMap);
731*35238bceSAndroid Build Coastguard Worker break;
732*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D_ARRAY:
733*35238bceSAndroid Build Coastguard Worker texObj = new Texture2DArray(texture);
734*35238bceSAndroid Build Coastguard Worker break;
735*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_3D:
736*35238bceSAndroid Build Coastguard Worker texObj = new Texture3D(texture);
737*35238bceSAndroid Build Coastguard Worker break;
738*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_ARRAY:
739*35238bceSAndroid Build Coastguard Worker texObj = new TextureCubeArray(texture);
740*35238bceSAndroid Build Coastguard Worker break;
741*35238bceSAndroid Build Coastguard Worker default:
742*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
743*35238bceSAndroid Build Coastguard Worker }
744*35238bceSAndroid Build Coastguard Worker
745*35238bceSAndroid Build Coastguard Worker m_textures.insert(texObj);
746*35238bceSAndroid Build Coastguard Worker }
747*35238bceSAndroid Build Coastguard Worker
748*35238bceSAndroid Build Coastguard Worker switch (target)
749*35238bceSAndroid Build Coastguard Worker {
750*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_1D:
751*35238bceSAndroid Build Coastguard Worker setTex1DBinding(unitNdx, static_cast<Texture1D *>(texObj));
752*35238bceSAndroid Build Coastguard Worker break;
753*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
754*35238bceSAndroid Build Coastguard Worker setTex2DBinding(unitNdx, static_cast<Texture2D *>(texObj));
755*35238bceSAndroid Build Coastguard Worker break;
756*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP:
757*35238bceSAndroid Build Coastguard Worker setTexCubeBinding(unitNdx, static_cast<TextureCube *>(texObj));
758*35238bceSAndroid Build Coastguard Worker break;
759*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D_ARRAY:
760*35238bceSAndroid Build Coastguard Worker setTex2DArrayBinding(unitNdx, static_cast<Texture2DArray *>(texObj));
761*35238bceSAndroid Build Coastguard Worker break;
762*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_3D:
763*35238bceSAndroid Build Coastguard Worker setTex3DBinding(unitNdx, static_cast<Texture3D *>(texObj));
764*35238bceSAndroid Build Coastguard Worker break;
765*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_ARRAY:
766*35238bceSAndroid Build Coastguard Worker setTexCubeArrayBinding(unitNdx, static_cast<TextureCubeArray *>(texObj));
767*35238bceSAndroid Build Coastguard Worker break;
768*35238bceSAndroid Build Coastguard Worker default:
769*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
770*35238bceSAndroid Build Coastguard Worker }
771*35238bceSAndroid Build Coastguard Worker }
772*35238bceSAndroid Build Coastguard Worker }
773*35238bceSAndroid Build Coastguard Worker
genTextures(int numTextures,uint32_t * textures)774*35238bceSAndroid Build Coastguard Worker void ReferenceContext::genTextures(int numTextures, uint32_t *textures)
775*35238bceSAndroid Build Coastguard Worker {
776*35238bceSAndroid Build Coastguard Worker while (numTextures--)
777*35238bceSAndroid Build Coastguard Worker *textures++ = m_textures.allocateName();
778*35238bceSAndroid Build Coastguard Worker }
779*35238bceSAndroid Build Coastguard Worker
deleteTextures(int numTextures,const uint32_t * textures)780*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteTextures(int numTextures, const uint32_t *textures)
781*35238bceSAndroid Build Coastguard Worker {
782*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numTextures; i++)
783*35238bceSAndroid Build Coastguard Worker {
784*35238bceSAndroid Build Coastguard Worker uint32_t name = textures[i];
785*35238bceSAndroid Build Coastguard Worker Texture *texture = name ? m_textures.find(name) : DE_NULL;
786*35238bceSAndroid Build Coastguard Worker
787*35238bceSAndroid Build Coastguard Worker if (texture)
788*35238bceSAndroid Build Coastguard Worker deleteTexture(texture);
789*35238bceSAndroid Build Coastguard Worker }
790*35238bceSAndroid Build Coastguard Worker }
791*35238bceSAndroid Build Coastguard Worker
deleteTexture(Texture * texture)792*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteTexture(Texture *texture)
793*35238bceSAndroid Build Coastguard Worker {
794*35238bceSAndroid Build Coastguard Worker // Unbind from context
795*35238bceSAndroid Build Coastguard Worker for (int unitNdx = 0; unitNdx < (int)m_textureUnits.size(); unitNdx++)
796*35238bceSAndroid Build Coastguard Worker {
797*35238bceSAndroid Build Coastguard Worker if (m_textureUnits[unitNdx].tex1DBinding == texture)
798*35238bceSAndroid Build Coastguard Worker setTex1DBinding(unitNdx, DE_NULL);
799*35238bceSAndroid Build Coastguard Worker else if (m_textureUnits[unitNdx].tex2DBinding == texture)
800*35238bceSAndroid Build Coastguard Worker setTex2DBinding(unitNdx, DE_NULL);
801*35238bceSAndroid Build Coastguard Worker else if (m_textureUnits[unitNdx].texCubeBinding == texture)
802*35238bceSAndroid Build Coastguard Worker setTexCubeBinding(unitNdx, DE_NULL);
803*35238bceSAndroid Build Coastguard Worker else if (m_textureUnits[unitNdx].tex2DArrayBinding == texture)
804*35238bceSAndroid Build Coastguard Worker setTex2DArrayBinding(unitNdx, DE_NULL);
805*35238bceSAndroid Build Coastguard Worker else if (m_textureUnits[unitNdx].tex3DBinding == texture)
806*35238bceSAndroid Build Coastguard Worker setTex3DBinding(unitNdx, DE_NULL);
807*35238bceSAndroid Build Coastguard Worker else if (m_textureUnits[unitNdx].texCubeArrayBinding == texture)
808*35238bceSAndroid Build Coastguard Worker setTexCubeArrayBinding(unitNdx, DE_NULL);
809*35238bceSAndroid Build Coastguard Worker }
810*35238bceSAndroid Build Coastguard Worker
811*35238bceSAndroid Build Coastguard Worker // Unbind from currently bound framebuffers
812*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 2; ndx++)
813*35238bceSAndroid Build Coastguard Worker {
814*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *framebufferBinding = ndx ? m_drawFramebufferBinding : m_readFramebufferBinding;
815*35238bceSAndroid Build Coastguard Worker if (framebufferBinding)
816*35238bceSAndroid Build Coastguard Worker {
817*35238bceSAndroid Build Coastguard Worker int releaseRefCount = (framebufferBinding == m_drawFramebufferBinding ? 1 : 0) +
818*35238bceSAndroid Build Coastguard Worker (framebufferBinding == m_readFramebufferBinding ? 1 : 0);
819*35238bceSAndroid Build Coastguard Worker
820*35238bceSAndroid Build Coastguard Worker for (int point = 0; point < Framebuffer::ATTACHMENTPOINT_LAST; point++)
821*35238bceSAndroid Build Coastguard Worker {
822*35238bceSAndroid Build Coastguard Worker Framebuffer::Attachment &attachment =
823*35238bceSAndroid Build Coastguard Worker framebufferBinding->getAttachment((Framebuffer::AttachmentPoint)point);
824*35238bceSAndroid Build Coastguard Worker if (attachment.name == texture->getName())
825*35238bceSAndroid Build Coastguard Worker {
826*35238bceSAndroid Build Coastguard Worker for (int refNdx = 0; refNdx < releaseRefCount; refNdx++)
827*35238bceSAndroid Build Coastguard Worker releaseFboAttachmentReference(attachment);
828*35238bceSAndroid Build Coastguard Worker attachment = Framebuffer::Attachment();
829*35238bceSAndroid Build Coastguard Worker }
830*35238bceSAndroid Build Coastguard Worker }
831*35238bceSAndroid Build Coastguard Worker }
832*35238bceSAndroid Build Coastguard Worker }
833*35238bceSAndroid Build Coastguard Worker
834*35238bceSAndroid Build Coastguard Worker DE_ASSERT(texture->getRefCount() == 1);
835*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(texture);
836*35238bceSAndroid Build Coastguard Worker }
837*35238bceSAndroid Build Coastguard Worker
bindFramebuffer(uint32_t target,uint32_t name)838*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bindFramebuffer(uint32_t target, uint32_t name)
839*35238bceSAndroid Build Coastguard Worker {
840*35238bceSAndroid Build Coastguard Worker Framebuffer *fbo = DE_NULL;
841*35238bceSAndroid Build Coastguard Worker
842*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER,
843*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
844*35238bceSAndroid Build Coastguard Worker
845*35238bceSAndroid Build Coastguard Worker if (name != 0)
846*35238bceSAndroid Build Coastguard Worker {
847*35238bceSAndroid Build Coastguard Worker // Find or create framebuffer object.
848*35238bceSAndroid Build Coastguard Worker fbo = m_framebuffers.find(name);
849*35238bceSAndroid Build Coastguard Worker if (!fbo)
850*35238bceSAndroid Build Coastguard Worker {
851*35238bceSAndroid Build Coastguard Worker fbo = new Framebuffer(name);
852*35238bceSAndroid Build Coastguard Worker m_framebuffers.insert(fbo);
853*35238bceSAndroid Build Coastguard Worker }
854*35238bceSAndroid Build Coastguard Worker }
855*35238bceSAndroid Build Coastguard Worker
856*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 2; ndx++)
857*35238bceSAndroid Build Coastguard Worker {
858*35238bceSAndroid Build Coastguard Worker uint32_t bindingTarget = ndx ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER;
859*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *&binding = ndx ? m_drawFramebufferBinding : m_readFramebufferBinding;
860*35238bceSAndroid Build Coastguard Worker
861*35238bceSAndroid Build Coastguard Worker if (target != GL_FRAMEBUFFER && target != bindingTarget)
862*35238bceSAndroid Build Coastguard Worker continue; // Doesn't match this target.
863*35238bceSAndroid Build Coastguard Worker
864*35238bceSAndroid Build Coastguard Worker // Remove old references
865*35238bceSAndroid Build Coastguard Worker if (binding)
866*35238bceSAndroid Build Coastguard Worker {
867*35238bceSAndroid Build Coastguard Worker // Clear all attachment point references
868*35238bceSAndroid Build Coastguard Worker for (int point = 0; point < Framebuffer::ATTACHMENTPOINT_LAST; point++)
869*35238bceSAndroid Build Coastguard Worker releaseFboAttachmentReference(binding->getAttachment((Framebuffer::AttachmentPoint)point));
870*35238bceSAndroid Build Coastguard Worker
871*35238bceSAndroid Build Coastguard Worker m_framebuffers.releaseReference(binding);
872*35238bceSAndroid Build Coastguard Worker }
873*35238bceSAndroid Build Coastguard Worker
874*35238bceSAndroid Build Coastguard Worker // Create new references
875*35238bceSAndroid Build Coastguard Worker if (fbo)
876*35238bceSAndroid Build Coastguard Worker {
877*35238bceSAndroid Build Coastguard Worker m_framebuffers.acquireReference(fbo);
878*35238bceSAndroid Build Coastguard Worker
879*35238bceSAndroid Build Coastguard Worker for (int point = 0; point < Framebuffer::ATTACHMENTPOINT_LAST; point++)
880*35238bceSAndroid Build Coastguard Worker acquireFboAttachmentReference(fbo->getAttachment((Framebuffer::AttachmentPoint)point));
881*35238bceSAndroid Build Coastguard Worker }
882*35238bceSAndroid Build Coastguard Worker
883*35238bceSAndroid Build Coastguard Worker binding = fbo;
884*35238bceSAndroid Build Coastguard Worker }
885*35238bceSAndroid Build Coastguard Worker }
886*35238bceSAndroid Build Coastguard Worker
genFramebuffers(int numFramebuffers,uint32_t * framebuffers)887*35238bceSAndroid Build Coastguard Worker void ReferenceContext::genFramebuffers(int numFramebuffers, uint32_t *framebuffers)
888*35238bceSAndroid Build Coastguard Worker {
889*35238bceSAndroid Build Coastguard Worker while (numFramebuffers--)
890*35238bceSAndroid Build Coastguard Worker *framebuffers++ = m_framebuffers.allocateName();
891*35238bceSAndroid Build Coastguard Worker }
892*35238bceSAndroid Build Coastguard Worker
deleteFramebuffer(Framebuffer * framebuffer)893*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteFramebuffer(Framebuffer *framebuffer)
894*35238bceSAndroid Build Coastguard Worker {
895*35238bceSAndroid Build Coastguard Worker // Remove bindings.
896*35238bceSAndroid Build Coastguard Worker if (m_drawFramebufferBinding == framebuffer)
897*35238bceSAndroid Build Coastguard Worker bindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
898*35238bceSAndroid Build Coastguard Worker if (m_readFramebufferBinding == framebuffer)
899*35238bceSAndroid Build Coastguard Worker bindFramebuffer(GL_READ_FRAMEBUFFER, 0);
900*35238bceSAndroid Build Coastguard Worker
901*35238bceSAndroid Build Coastguard Worker DE_ASSERT(framebuffer->getRefCount() == 1);
902*35238bceSAndroid Build Coastguard Worker m_framebuffers.releaseReference(framebuffer);
903*35238bceSAndroid Build Coastguard Worker }
904*35238bceSAndroid Build Coastguard Worker
deleteFramebuffers(int numFramebuffers,const uint32_t * framebuffers)905*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteFramebuffers(int numFramebuffers, const uint32_t *framebuffers)
906*35238bceSAndroid Build Coastguard Worker {
907*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numFramebuffers; i++)
908*35238bceSAndroid Build Coastguard Worker {
909*35238bceSAndroid Build Coastguard Worker uint32_t name = framebuffers[i];
910*35238bceSAndroid Build Coastguard Worker Framebuffer *framebuffer = name ? m_framebuffers.find(name) : DE_NULL;
911*35238bceSAndroid Build Coastguard Worker
912*35238bceSAndroid Build Coastguard Worker if (framebuffer)
913*35238bceSAndroid Build Coastguard Worker deleteFramebuffer(framebuffer);
914*35238bceSAndroid Build Coastguard Worker }
915*35238bceSAndroid Build Coastguard Worker }
916*35238bceSAndroid Build Coastguard Worker
bindRenderbuffer(uint32_t target,uint32_t name)917*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bindRenderbuffer(uint32_t target, uint32_t name)
918*35238bceSAndroid Build Coastguard Worker {
919*35238bceSAndroid Build Coastguard Worker Renderbuffer *rbo = DE_NULL;
920*35238bceSAndroid Build Coastguard Worker
921*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_RENDERBUFFER, GL_INVALID_ENUM, RC_RET_VOID);
922*35238bceSAndroid Build Coastguard Worker
923*35238bceSAndroid Build Coastguard Worker if (name != 0)
924*35238bceSAndroid Build Coastguard Worker {
925*35238bceSAndroid Build Coastguard Worker rbo = m_renderbuffers.find(name);
926*35238bceSAndroid Build Coastguard Worker if (!rbo)
927*35238bceSAndroid Build Coastguard Worker {
928*35238bceSAndroid Build Coastguard Worker rbo = new Renderbuffer(name);
929*35238bceSAndroid Build Coastguard Worker m_renderbuffers.insert(rbo);
930*35238bceSAndroid Build Coastguard Worker }
931*35238bceSAndroid Build Coastguard Worker }
932*35238bceSAndroid Build Coastguard Worker
933*35238bceSAndroid Build Coastguard Worker // Remove old reference
934*35238bceSAndroid Build Coastguard Worker if (m_renderbufferBinding)
935*35238bceSAndroid Build Coastguard Worker m_renderbuffers.releaseReference(m_renderbufferBinding);
936*35238bceSAndroid Build Coastguard Worker
937*35238bceSAndroid Build Coastguard Worker // Create new reference
938*35238bceSAndroid Build Coastguard Worker if (rbo)
939*35238bceSAndroid Build Coastguard Worker m_renderbuffers.acquireReference(rbo);
940*35238bceSAndroid Build Coastguard Worker
941*35238bceSAndroid Build Coastguard Worker m_renderbufferBinding = rbo;
942*35238bceSAndroid Build Coastguard Worker }
943*35238bceSAndroid Build Coastguard Worker
genRenderbuffers(int numRenderbuffers,uint32_t * renderbuffers)944*35238bceSAndroid Build Coastguard Worker void ReferenceContext::genRenderbuffers(int numRenderbuffers, uint32_t *renderbuffers)
945*35238bceSAndroid Build Coastguard Worker {
946*35238bceSAndroid Build Coastguard Worker while (numRenderbuffers--)
947*35238bceSAndroid Build Coastguard Worker *renderbuffers++ = m_renderbuffers.allocateName();
948*35238bceSAndroid Build Coastguard Worker }
949*35238bceSAndroid Build Coastguard Worker
deleteRenderbuffer(Renderbuffer * renderbuffer)950*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteRenderbuffer(Renderbuffer *renderbuffer)
951*35238bceSAndroid Build Coastguard Worker {
952*35238bceSAndroid Build Coastguard Worker if (m_renderbufferBinding == renderbuffer)
953*35238bceSAndroid Build Coastguard Worker bindRenderbuffer(GL_RENDERBUFFER, 0);
954*35238bceSAndroid Build Coastguard Worker
955*35238bceSAndroid Build Coastguard Worker // Unbind from currently bound framebuffers
956*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 2; ndx++)
957*35238bceSAndroid Build Coastguard Worker {
958*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *framebufferBinding = ndx ? m_drawFramebufferBinding : m_readFramebufferBinding;
959*35238bceSAndroid Build Coastguard Worker if (framebufferBinding)
960*35238bceSAndroid Build Coastguard Worker {
961*35238bceSAndroid Build Coastguard Worker int releaseRefCount = (framebufferBinding == m_drawFramebufferBinding ? 1 : 0) +
962*35238bceSAndroid Build Coastguard Worker (framebufferBinding == m_readFramebufferBinding ? 1 : 0);
963*35238bceSAndroid Build Coastguard Worker
964*35238bceSAndroid Build Coastguard Worker for (int point = 0; point < Framebuffer::ATTACHMENTPOINT_LAST; point++)
965*35238bceSAndroid Build Coastguard Worker {
966*35238bceSAndroid Build Coastguard Worker Framebuffer::Attachment &attachment =
967*35238bceSAndroid Build Coastguard Worker framebufferBinding->getAttachment((Framebuffer::AttachmentPoint)point);
968*35238bceSAndroid Build Coastguard Worker if (attachment.name == renderbuffer->getName())
969*35238bceSAndroid Build Coastguard Worker {
970*35238bceSAndroid Build Coastguard Worker for (int refNdx = 0; refNdx < releaseRefCount; refNdx++)
971*35238bceSAndroid Build Coastguard Worker releaseFboAttachmentReference(attachment);
972*35238bceSAndroid Build Coastguard Worker attachment = Framebuffer::Attachment();
973*35238bceSAndroid Build Coastguard Worker }
974*35238bceSAndroid Build Coastguard Worker }
975*35238bceSAndroid Build Coastguard Worker }
976*35238bceSAndroid Build Coastguard Worker }
977*35238bceSAndroid Build Coastguard Worker
978*35238bceSAndroid Build Coastguard Worker DE_ASSERT(renderbuffer->getRefCount() == 1);
979*35238bceSAndroid Build Coastguard Worker m_renderbuffers.releaseReference(renderbuffer);
980*35238bceSAndroid Build Coastguard Worker }
981*35238bceSAndroid Build Coastguard Worker
deleteRenderbuffers(int numRenderbuffers,const uint32_t * renderbuffers)982*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteRenderbuffers(int numRenderbuffers, const uint32_t *renderbuffers)
983*35238bceSAndroid Build Coastguard Worker {
984*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numRenderbuffers; i++)
985*35238bceSAndroid Build Coastguard Worker {
986*35238bceSAndroid Build Coastguard Worker uint32_t name = renderbuffers[i];
987*35238bceSAndroid Build Coastguard Worker Renderbuffer *renderbuffer = name ? m_renderbuffers.find(name) : DE_NULL;
988*35238bceSAndroid Build Coastguard Worker
989*35238bceSAndroid Build Coastguard Worker if (renderbuffer)
990*35238bceSAndroid Build Coastguard Worker deleteRenderbuffer(renderbuffer);
991*35238bceSAndroid Build Coastguard Worker }
992*35238bceSAndroid Build Coastguard Worker }
993*35238bceSAndroid Build Coastguard Worker
pixelStorei(uint32_t pname,int param)994*35238bceSAndroid Build Coastguard Worker void ReferenceContext::pixelStorei(uint32_t pname, int param)
995*35238bceSAndroid Build Coastguard Worker {
996*35238bceSAndroid Build Coastguard Worker switch (pname)
997*35238bceSAndroid Build Coastguard Worker {
998*35238bceSAndroid Build Coastguard Worker case GL_UNPACK_ALIGNMENT:
999*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param != 1 && param != 2 && param != 4 && param != 8, GL_INVALID_VALUE, RC_RET_VOID);
1000*35238bceSAndroid Build Coastguard Worker m_pixelUnpackAlignment = param;
1001*35238bceSAndroid Build Coastguard Worker break;
1002*35238bceSAndroid Build Coastguard Worker
1003*35238bceSAndroid Build Coastguard Worker case GL_PACK_ALIGNMENT:
1004*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param != 1 && param != 2 && param != 4 && param != 8, GL_INVALID_VALUE, RC_RET_VOID);
1005*35238bceSAndroid Build Coastguard Worker m_pixelPackAlignment = param;
1006*35238bceSAndroid Build Coastguard Worker break;
1007*35238bceSAndroid Build Coastguard Worker
1008*35238bceSAndroid Build Coastguard Worker case GL_UNPACK_ROW_LENGTH:
1009*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param < 0, GL_INVALID_VALUE, RC_RET_VOID);
1010*35238bceSAndroid Build Coastguard Worker m_pixelUnpackRowLength = param;
1011*35238bceSAndroid Build Coastguard Worker break;
1012*35238bceSAndroid Build Coastguard Worker
1013*35238bceSAndroid Build Coastguard Worker case GL_UNPACK_SKIP_ROWS:
1014*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param < 0, GL_INVALID_VALUE, RC_RET_VOID);
1015*35238bceSAndroid Build Coastguard Worker m_pixelUnpackSkipRows = param;
1016*35238bceSAndroid Build Coastguard Worker break;
1017*35238bceSAndroid Build Coastguard Worker
1018*35238bceSAndroid Build Coastguard Worker case GL_UNPACK_SKIP_PIXELS:
1019*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param < 0, GL_INVALID_VALUE, RC_RET_VOID);
1020*35238bceSAndroid Build Coastguard Worker m_pixelUnpackSkipPixels = param;
1021*35238bceSAndroid Build Coastguard Worker break;
1022*35238bceSAndroid Build Coastguard Worker
1023*35238bceSAndroid Build Coastguard Worker case GL_UNPACK_IMAGE_HEIGHT:
1024*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param < 0, GL_INVALID_VALUE, RC_RET_VOID);
1025*35238bceSAndroid Build Coastguard Worker m_pixelUnpackImageHeight = param;
1026*35238bceSAndroid Build Coastguard Worker break;
1027*35238bceSAndroid Build Coastguard Worker
1028*35238bceSAndroid Build Coastguard Worker case GL_UNPACK_SKIP_IMAGES:
1029*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(param < 0, GL_INVALID_VALUE, RC_RET_VOID);
1030*35238bceSAndroid Build Coastguard Worker m_pixelUnpackSkipImages = param;
1031*35238bceSAndroid Build Coastguard Worker break;
1032*35238bceSAndroid Build Coastguard Worker
1033*35238bceSAndroid Build Coastguard Worker default:
1034*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
1035*35238bceSAndroid Build Coastguard Worker }
1036*35238bceSAndroid Build Coastguard Worker }
1037*35238bceSAndroid Build Coastguard Worker
getUnpack2DAccess(const tcu::TextureFormat & format,int width,int height,const void * data)1038*35238bceSAndroid Build Coastguard Worker tcu::ConstPixelBufferAccess ReferenceContext::getUnpack2DAccess(const tcu::TextureFormat &format, int width, int height,
1039*35238bceSAndroid Build Coastguard Worker const void *data)
1040*35238bceSAndroid Build Coastguard Worker {
1041*35238bceSAndroid Build Coastguard Worker int pixelSize = format.getPixelSize();
1042*35238bceSAndroid Build Coastguard Worker int rowLen = m_pixelUnpackRowLength > 0 ? m_pixelUnpackRowLength : width;
1043*35238bceSAndroid Build Coastguard Worker int rowPitch = deAlign32(rowLen * pixelSize, m_pixelUnpackAlignment);
1044*35238bceSAndroid Build Coastguard Worker const uint8_t *ptr = (const uint8_t *)data + m_pixelUnpackSkipRows * rowPitch + m_pixelUnpackSkipPixels * pixelSize;
1045*35238bceSAndroid Build Coastguard Worker
1046*35238bceSAndroid Build Coastguard Worker return tcu::ConstPixelBufferAccess(format, width, height, 1, rowPitch, 0, ptr);
1047*35238bceSAndroid Build Coastguard Worker }
1048*35238bceSAndroid Build Coastguard Worker
getUnpack3DAccess(const tcu::TextureFormat & format,int width,int height,int depth,const void * data)1049*35238bceSAndroid Build Coastguard Worker tcu::ConstPixelBufferAccess ReferenceContext::getUnpack3DAccess(const tcu::TextureFormat &format, int width, int height,
1050*35238bceSAndroid Build Coastguard Worker int depth, const void *data)
1051*35238bceSAndroid Build Coastguard Worker {
1052*35238bceSAndroid Build Coastguard Worker int pixelSize = format.getPixelSize();
1053*35238bceSAndroid Build Coastguard Worker int rowLen = m_pixelUnpackRowLength > 0 ? m_pixelUnpackRowLength : width;
1054*35238bceSAndroid Build Coastguard Worker int imageHeight = m_pixelUnpackImageHeight > 0 ? m_pixelUnpackImageHeight : height;
1055*35238bceSAndroid Build Coastguard Worker int rowPitch = deAlign32(rowLen * pixelSize, m_pixelUnpackAlignment);
1056*35238bceSAndroid Build Coastguard Worker int slicePitch = imageHeight * rowPitch;
1057*35238bceSAndroid Build Coastguard Worker const uint8_t *ptr = (const uint8_t *)data + m_pixelUnpackSkipImages * slicePitch +
1058*35238bceSAndroid Build Coastguard Worker m_pixelUnpackSkipRows * rowPitch + m_pixelUnpackSkipPixels * pixelSize;
1059*35238bceSAndroid Build Coastguard Worker
1060*35238bceSAndroid Build Coastguard Worker return tcu::ConstPixelBufferAccess(format, width, height, depth, rowPitch, slicePitch, ptr);
1061*35238bceSAndroid Build Coastguard Worker }
1062*35238bceSAndroid Build Coastguard Worker
mapInternalFormat(uint32_t internalFormat)1063*35238bceSAndroid Build Coastguard Worker static tcu::TextureFormat mapInternalFormat(uint32_t internalFormat)
1064*35238bceSAndroid Build Coastguard Worker {
1065*35238bceSAndroid Build Coastguard Worker switch (internalFormat)
1066*35238bceSAndroid Build Coastguard Worker {
1067*35238bceSAndroid Build Coastguard Worker case GL_ALPHA:
1068*35238bceSAndroid Build Coastguard Worker return TextureFormat(TextureFormat::A, TextureFormat::UNORM_INT8);
1069*35238bceSAndroid Build Coastguard Worker case GL_LUMINANCE:
1070*35238bceSAndroid Build Coastguard Worker return TextureFormat(TextureFormat::L, TextureFormat::UNORM_INT8);
1071*35238bceSAndroid Build Coastguard Worker case GL_LUMINANCE_ALPHA:
1072*35238bceSAndroid Build Coastguard Worker return TextureFormat(TextureFormat::LA, TextureFormat::UNORM_INT8);
1073*35238bceSAndroid Build Coastguard Worker case GL_RGB:
1074*35238bceSAndroid Build Coastguard Worker return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8);
1075*35238bceSAndroid Build Coastguard Worker case GL_RGBA:
1076*35238bceSAndroid Build Coastguard Worker return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8);
1077*35238bceSAndroid Build Coastguard Worker
1078*35238bceSAndroid Build Coastguard Worker default:
1079*35238bceSAndroid Build Coastguard Worker return glu::mapGLInternalFormat(internalFormat);
1080*35238bceSAndroid Build Coastguard Worker }
1081*35238bceSAndroid Build Coastguard Worker }
1082*35238bceSAndroid Build Coastguard Worker
depthValueFloatClampCopy(const PixelBufferAccess & dst,const ConstPixelBufferAccess & src)1083*35238bceSAndroid Build Coastguard Worker static void depthValueFloatClampCopy(const PixelBufferAccess &dst, const ConstPixelBufferAccess &src)
1084*35238bceSAndroid Build Coastguard Worker {
1085*35238bceSAndroid Build Coastguard Worker int width = dst.getWidth();
1086*35238bceSAndroid Build Coastguard Worker int height = dst.getHeight();
1087*35238bceSAndroid Build Coastguard Worker int depth = dst.getDepth();
1088*35238bceSAndroid Build Coastguard Worker
1089*35238bceSAndroid Build Coastguard Worker DE_ASSERT(src.getWidth() == width && src.getHeight() == height && src.getDepth() == depth);
1090*35238bceSAndroid Build Coastguard Worker
1091*35238bceSAndroid Build Coastguard Worker // clamping copy
1092*35238bceSAndroid Build Coastguard Worker
1093*35238bceSAndroid Build Coastguard Worker if (src.getFormat().order == tcu::TextureFormat::DS && dst.getFormat().order == tcu::TextureFormat::DS)
1094*35238bceSAndroid Build Coastguard Worker {
1095*35238bceSAndroid Build Coastguard Worker // copy only depth and stencil
1096*35238bceSAndroid Build Coastguard Worker for (int z = 0; z < depth; z++)
1097*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < height; y++)
1098*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < width; x++)
1099*35238bceSAndroid Build Coastguard Worker {
1100*35238bceSAndroid Build Coastguard Worker dst.setPixDepth(de::clamp(src.getPixDepth(x, y, z), 0.0f, 1.0f), x, y, z);
1101*35238bceSAndroid Build Coastguard Worker dst.setPixStencil(src.getPixStencil(x, y, z), x, y, z);
1102*35238bceSAndroid Build Coastguard Worker }
1103*35238bceSAndroid Build Coastguard Worker }
1104*35238bceSAndroid Build Coastguard Worker else
1105*35238bceSAndroid Build Coastguard Worker {
1106*35238bceSAndroid Build Coastguard Worker // copy only depth
1107*35238bceSAndroid Build Coastguard Worker for (int z = 0; z < depth; z++)
1108*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < height; y++)
1109*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < width; x++)
1110*35238bceSAndroid Build Coastguard Worker dst.setPixDepth(de::clamp(src.getPixDepth(x, y, z), 0.0f, 1.0f), x, y, z);
1111*35238bceSAndroid Build Coastguard Worker }
1112*35238bceSAndroid Build Coastguard Worker }
1113*35238bceSAndroid Build Coastguard Worker
texImage1D(uint32_t target,int level,uint32_t internalFormat,int width,int border,uint32_t format,uint32_t type,const void * data)1114*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texImage1D(uint32_t target, int level, uint32_t internalFormat, int width, int border,
1115*35238bceSAndroid Build Coastguard Worker uint32_t format, uint32_t type, const void *data)
1116*35238bceSAndroid Build Coastguard Worker {
1117*35238bceSAndroid Build Coastguard Worker texImage2D(target, level, internalFormat, width, 1, border, format, type, data);
1118*35238bceSAndroid Build Coastguard Worker }
1119*35238bceSAndroid Build Coastguard Worker
texImage2D(uint32_t target,int level,uint32_t internalFormat,int width,int height,int border,uint32_t format,uint32_t type,const void * data)1120*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texImage2D(uint32_t target, int level, uint32_t internalFormat, int width, int height,
1121*35238bceSAndroid Build Coastguard Worker int border, uint32_t format, uint32_t type, const void *data)
1122*35238bceSAndroid Build Coastguard Worker {
1123*35238bceSAndroid Build Coastguard Worker texImage3D(target, level, internalFormat, width, height, 1, border, format, type, data);
1124*35238bceSAndroid Build Coastguard Worker }
1125*35238bceSAndroid Build Coastguard Worker
clearToTextureInitialValue(PixelBufferAccess access)1126*35238bceSAndroid Build Coastguard Worker static void clearToTextureInitialValue(PixelBufferAccess access)
1127*35238bceSAndroid Build Coastguard Worker {
1128*35238bceSAndroid Build Coastguard Worker const bool hasDepth =
1129*35238bceSAndroid Build Coastguard Worker access.getFormat().order == tcu::TextureFormat::D || access.getFormat().order == tcu::TextureFormat::DS;
1130*35238bceSAndroid Build Coastguard Worker const bool hasStencil =
1131*35238bceSAndroid Build Coastguard Worker access.getFormat().order == tcu::TextureFormat::S || access.getFormat().order == tcu::TextureFormat::DS;
1132*35238bceSAndroid Build Coastguard Worker const bool hasColor = !hasDepth && !hasStencil;
1133*35238bceSAndroid Build Coastguard Worker
1134*35238bceSAndroid Build Coastguard Worker if (hasDepth)
1135*35238bceSAndroid Build Coastguard Worker tcu::clearDepth(access, 0.0f);
1136*35238bceSAndroid Build Coastguard Worker if (hasStencil)
1137*35238bceSAndroid Build Coastguard Worker tcu::clearStencil(access, 0u);
1138*35238bceSAndroid Build Coastguard Worker if (hasColor)
1139*35238bceSAndroid Build Coastguard Worker tcu::clear(access, Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1140*35238bceSAndroid Build Coastguard Worker }
1141*35238bceSAndroid Build Coastguard Worker
texImage3D(uint32_t target,int level,uint32_t internalFormat,int width,int height,int depth,int border,uint32_t format,uint32_t type,const void * data)1142*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texImage3D(uint32_t target, int level, uint32_t internalFormat, int width, int height, int depth,
1143*35238bceSAndroid Build Coastguard Worker int border, uint32_t format, uint32_t type, const void *data)
1144*35238bceSAndroid Build Coastguard Worker {
1145*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1146*35238bceSAndroid Build Coastguard Worker const void *unpackPtr = getPixelUnpackPtr(data);
1147*35238bceSAndroid Build Coastguard Worker const bool isDstFloatDepthFormat =
1148*35238bceSAndroid Build Coastguard Worker (internalFormat == GL_DEPTH_COMPONENT32F ||
1149*35238bceSAndroid Build Coastguard Worker internalFormat == GL_DEPTH32F_STENCIL8); // depth components are limited to [0,1] range
1150*35238bceSAndroid Build Coastguard Worker TextureFormat storageFmt;
1151*35238bceSAndroid Build Coastguard Worker TextureFormat transferFmt;
1152*35238bceSAndroid Build Coastguard Worker
1153*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(border != 0, GL_INVALID_VALUE, RC_RET_VOID);
1154*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || height < 0 || depth < 0 || level < 0, GL_INVALID_VALUE, RC_RET_VOID);
1155*35238bceSAndroid Build Coastguard Worker
1156*35238bceSAndroid Build Coastguard Worker // Map storage format.
1157*35238bceSAndroid Build Coastguard Worker storageFmt = mapInternalFormat(internalFormat);
1158*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt.order == TextureFormat::CHANNELORDER_LAST ||
1159*35238bceSAndroid Build Coastguard Worker storageFmt.type == TextureFormat::CHANNELTYPE_LAST,
1160*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1161*35238bceSAndroid Build Coastguard Worker
1162*35238bceSAndroid Build Coastguard Worker // Map transfer format.
1163*35238bceSAndroid Build Coastguard Worker transferFmt = glu::mapGLTransferFormat(format, type);
1164*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(transferFmt.order == TextureFormat::CHANNELORDER_LAST ||
1165*35238bceSAndroid Build Coastguard Worker transferFmt.type == TextureFormat::CHANNELTYPE_LAST,
1166*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1167*35238bceSAndroid Build Coastguard Worker
1168*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_1D && glu::isContextTypeGLCore(m_limits.contextType))
1169*35238bceSAndroid Build Coastguard Worker {
1170*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1171*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize || height != 1 || depth != 1, GL_INVALID_VALUE, RC_RET_VOID);
1172*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture2DSize), GL_INVALID_VALUE, RC_RET_VOID);
1173*35238bceSAndroid Build Coastguard Worker
1174*35238bceSAndroid Build Coastguard Worker Texture1D *texture = unit.tex1DBinding ? unit.tex1DBinding : &unit.default1DTex;
1175*35238bceSAndroid Build Coastguard Worker
1176*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1177*35238bceSAndroid Build Coastguard Worker {
1178*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1179*35238bceSAndroid Build Coastguard Worker
1180*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1181*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth(), GL_INVALID_OPERATION, RC_RET_VOID);
1182*35238bceSAndroid Build Coastguard Worker }
1183*35238bceSAndroid Build Coastguard Worker else
1184*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width);
1185*35238bceSAndroid Build Coastguard Worker
1186*35238bceSAndroid Build Coastguard Worker if (unpackPtr)
1187*35238bceSAndroid Build Coastguard Worker {
1188*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack2DAccess(transferFmt, width, 1, unpackPtr);
1189*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(texture->getLevel(level));
1190*35238bceSAndroid Build Coastguard Worker
1191*35238bceSAndroid Build Coastguard Worker if (isDstFloatDepthFormat)
1192*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(dst, src);
1193*35238bceSAndroid Build Coastguard Worker else
1194*35238bceSAndroid Build Coastguard Worker tcu::copy(dst, src);
1195*35238bceSAndroid Build Coastguard Worker }
1196*35238bceSAndroid Build Coastguard Worker else
1197*35238bceSAndroid Build Coastguard Worker {
1198*35238bceSAndroid Build Coastguard Worker // No data supplied, clear to initial
1199*35238bceSAndroid Build Coastguard Worker clearToTextureInitialValue(texture->getLevel(level));
1200*35238bceSAndroid Build Coastguard Worker }
1201*35238bceSAndroid Build Coastguard Worker }
1202*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_2D)
1203*35238bceSAndroid Build Coastguard Worker {
1204*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1205*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize || height > m_limits.maxTexture2DSize || depth != 1,
1206*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1207*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture2DSize), GL_INVALID_VALUE, RC_RET_VOID);
1208*35238bceSAndroid Build Coastguard Worker
1209*35238bceSAndroid Build Coastguard Worker Texture2D *texture = unit.tex2DBinding ? unit.tex2DBinding : &unit.default2DTex;
1210*35238bceSAndroid Build Coastguard Worker
1211*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1212*35238bceSAndroid Build Coastguard Worker {
1213*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1214*35238bceSAndroid Build Coastguard Worker
1215*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1216*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight(),
1217*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1218*35238bceSAndroid Build Coastguard Worker }
1219*35238bceSAndroid Build Coastguard Worker else
1220*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width, height);
1221*35238bceSAndroid Build Coastguard Worker
1222*35238bceSAndroid Build Coastguard Worker if (unpackPtr)
1223*35238bceSAndroid Build Coastguard Worker {
1224*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack2DAccess(transferFmt, width, height, unpackPtr);
1225*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(texture->getLevel(level));
1226*35238bceSAndroid Build Coastguard Worker
1227*35238bceSAndroid Build Coastguard Worker if (isDstFloatDepthFormat)
1228*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(dst, src);
1229*35238bceSAndroid Build Coastguard Worker else
1230*35238bceSAndroid Build Coastguard Worker tcu::copy(dst, src);
1231*35238bceSAndroid Build Coastguard Worker }
1232*35238bceSAndroid Build Coastguard Worker else
1233*35238bceSAndroid Build Coastguard Worker {
1234*35238bceSAndroid Build Coastguard Worker // No data supplied, clear to initial
1235*35238bceSAndroid Build Coastguard Worker clearToTextureInitialValue(texture->getLevel(level));
1236*35238bceSAndroid Build Coastguard Worker }
1237*35238bceSAndroid Build Coastguard Worker }
1238*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X || target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
1239*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
1240*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z)
1241*35238bceSAndroid Build Coastguard Worker {
1242*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1243*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width != height || width > m_limits.maxTextureCubeSize || depth != 1, GL_INVALID_VALUE,
1244*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
1245*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTextureCubeSize), GL_INVALID_VALUE, RC_RET_VOID);
1246*35238bceSAndroid Build Coastguard Worker
1247*35238bceSAndroid Build Coastguard Worker TextureCube *texture = unit.texCubeBinding ? unit.texCubeBinding : &unit.defaultCubeTex;
1248*35238bceSAndroid Build Coastguard Worker tcu::CubeFace face = mapGLCubeFace(target);
1249*35238bceSAndroid Build Coastguard Worker
1250*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1251*35238bceSAndroid Build Coastguard Worker {
1252*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasFace(level, face), GL_INVALID_OPERATION, RC_RET_VOID);
1253*35238bceSAndroid Build Coastguard Worker
1254*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getFace(level, face));
1255*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight(),
1256*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1257*35238bceSAndroid Build Coastguard Worker }
1258*35238bceSAndroid Build Coastguard Worker else
1259*35238bceSAndroid Build Coastguard Worker texture->allocFace(level, face, storageFmt, width, height);
1260*35238bceSAndroid Build Coastguard Worker
1261*35238bceSAndroid Build Coastguard Worker if (unpackPtr)
1262*35238bceSAndroid Build Coastguard Worker {
1263*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack2DAccess(transferFmt, width, height, unpackPtr);
1264*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(texture->getFace(level, face));
1265*35238bceSAndroid Build Coastguard Worker
1266*35238bceSAndroid Build Coastguard Worker if (isDstFloatDepthFormat)
1267*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(dst, src);
1268*35238bceSAndroid Build Coastguard Worker else
1269*35238bceSAndroid Build Coastguard Worker tcu::copy(dst, src);
1270*35238bceSAndroid Build Coastguard Worker }
1271*35238bceSAndroid Build Coastguard Worker else
1272*35238bceSAndroid Build Coastguard Worker {
1273*35238bceSAndroid Build Coastguard Worker // No data supplied, clear to initial
1274*35238bceSAndroid Build Coastguard Worker clearToTextureInitialValue(texture->getFace(level, face));
1275*35238bceSAndroid Build Coastguard Worker }
1276*35238bceSAndroid Build Coastguard Worker }
1277*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_2D_ARRAY)
1278*35238bceSAndroid Build Coastguard Worker {
1279*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1280*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize || height > m_limits.maxTexture2DSize ||
1281*35238bceSAndroid Build Coastguard Worker depth > m_limits.maxTexture2DArrayLayers,
1282*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1283*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture2DSize), GL_INVALID_VALUE, RC_RET_VOID);
1284*35238bceSAndroid Build Coastguard Worker
1285*35238bceSAndroid Build Coastguard Worker Texture2DArray *texture = unit.tex2DArrayBinding ? unit.tex2DArrayBinding : &unit.default2DArrayTex;
1286*35238bceSAndroid Build Coastguard Worker
1287*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1288*35238bceSAndroid Build Coastguard Worker {
1289*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1290*35238bceSAndroid Build Coastguard Worker
1291*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1292*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight() ||
1293*35238bceSAndroid Build Coastguard Worker depth != dst.getDepth(),
1294*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1295*35238bceSAndroid Build Coastguard Worker }
1296*35238bceSAndroid Build Coastguard Worker else
1297*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width, height, depth);
1298*35238bceSAndroid Build Coastguard Worker
1299*35238bceSAndroid Build Coastguard Worker if (unpackPtr)
1300*35238bceSAndroid Build Coastguard Worker {
1301*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack3DAccess(transferFmt, width, height, depth, unpackPtr);
1302*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(texture->getLevel(level));
1303*35238bceSAndroid Build Coastguard Worker
1304*35238bceSAndroid Build Coastguard Worker if (isDstFloatDepthFormat)
1305*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(dst, src);
1306*35238bceSAndroid Build Coastguard Worker else
1307*35238bceSAndroid Build Coastguard Worker tcu::copy(dst, src);
1308*35238bceSAndroid Build Coastguard Worker }
1309*35238bceSAndroid Build Coastguard Worker else
1310*35238bceSAndroid Build Coastguard Worker {
1311*35238bceSAndroid Build Coastguard Worker // No data supplied, clear to initial
1312*35238bceSAndroid Build Coastguard Worker clearToTextureInitialValue(texture->getLevel(level));
1313*35238bceSAndroid Build Coastguard Worker }
1314*35238bceSAndroid Build Coastguard Worker }
1315*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_3D)
1316*35238bceSAndroid Build Coastguard Worker {
1317*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1318*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture3DSize || height > m_limits.maxTexture3DSize ||
1319*35238bceSAndroid Build Coastguard Worker depth > m_limits.maxTexture3DSize,
1320*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1321*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture3DSize), GL_INVALID_VALUE, RC_RET_VOID);
1322*35238bceSAndroid Build Coastguard Worker
1323*35238bceSAndroid Build Coastguard Worker Texture3D *texture = unit.tex3DBinding ? unit.tex3DBinding : &unit.default3DTex;
1324*35238bceSAndroid Build Coastguard Worker
1325*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1326*35238bceSAndroid Build Coastguard Worker {
1327*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1328*35238bceSAndroid Build Coastguard Worker
1329*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1330*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight() ||
1331*35238bceSAndroid Build Coastguard Worker depth != dst.getDepth(),
1332*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1333*35238bceSAndroid Build Coastguard Worker }
1334*35238bceSAndroid Build Coastguard Worker else
1335*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width, height, depth);
1336*35238bceSAndroid Build Coastguard Worker
1337*35238bceSAndroid Build Coastguard Worker if (unpackPtr)
1338*35238bceSAndroid Build Coastguard Worker {
1339*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack3DAccess(transferFmt, width, height, depth, unpackPtr);
1340*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(texture->getLevel(level));
1341*35238bceSAndroid Build Coastguard Worker
1342*35238bceSAndroid Build Coastguard Worker if (isDstFloatDepthFormat)
1343*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(dst, src);
1344*35238bceSAndroid Build Coastguard Worker else
1345*35238bceSAndroid Build Coastguard Worker tcu::copy(dst, src);
1346*35238bceSAndroid Build Coastguard Worker }
1347*35238bceSAndroid Build Coastguard Worker else
1348*35238bceSAndroid Build Coastguard Worker {
1349*35238bceSAndroid Build Coastguard Worker // No data supplied, clear to initial
1350*35238bceSAndroid Build Coastguard Worker clearToTextureInitialValue(texture->getLevel(level));
1351*35238bceSAndroid Build Coastguard Worker }
1352*35238bceSAndroid Build Coastguard Worker }
1353*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_ARRAY)
1354*35238bceSAndroid Build Coastguard Worker {
1355*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1356*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width != height || width > m_limits.maxTexture2DSize || depth % 6 != 0 ||
1357*35238bceSAndroid Build Coastguard Worker depth > m_limits.maxTexture2DArrayLayers,
1358*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1359*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture2DSize), GL_INVALID_VALUE, RC_RET_VOID);
1360*35238bceSAndroid Build Coastguard Worker
1361*35238bceSAndroid Build Coastguard Worker TextureCubeArray *texture = unit.texCubeArrayBinding ? unit.texCubeArrayBinding : &unit.defaultCubeArrayTex;
1362*35238bceSAndroid Build Coastguard Worker
1363*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1364*35238bceSAndroid Build Coastguard Worker {
1365*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1366*35238bceSAndroid Build Coastguard Worker
1367*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1368*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight() ||
1369*35238bceSAndroid Build Coastguard Worker depth != dst.getDepth(),
1370*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1371*35238bceSAndroid Build Coastguard Worker }
1372*35238bceSAndroid Build Coastguard Worker else
1373*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width, height, depth);
1374*35238bceSAndroid Build Coastguard Worker
1375*35238bceSAndroid Build Coastguard Worker if (unpackPtr)
1376*35238bceSAndroid Build Coastguard Worker {
1377*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack3DAccess(transferFmt, width, height, depth, unpackPtr);
1378*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(texture->getLevel(level));
1379*35238bceSAndroid Build Coastguard Worker
1380*35238bceSAndroid Build Coastguard Worker if (isDstFloatDepthFormat)
1381*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(dst, src);
1382*35238bceSAndroid Build Coastguard Worker else
1383*35238bceSAndroid Build Coastguard Worker tcu::copy(dst, src);
1384*35238bceSAndroid Build Coastguard Worker }
1385*35238bceSAndroid Build Coastguard Worker else
1386*35238bceSAndroid Build Coastguard Worker {
1387*35238bceSAndroid Build Coastguard Worker // No data supplied, clear to initial
1388*35238bceSAndroid Build Coastguard Worker clearToTextureInitialValue(texture->getLevel(level));
1389*35238bceSAndroid Build Coastguard Worker }
1390*35238bceSAndroid Build Coastguard Worker }
1391*35238bceSAndroid Build Coastguard Worker else
1392*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1393*35238bceSAndroid Build Coastguard Worker }
1394*35238bceSAndroid Build Coastguard Worker
texSubImage1D(uint32_t target,int level,int xoffset,int width,uint32_t format,uint32_t type,const void * data)1395*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texSubImage1D(uint32_t target, int level, int xoffset, int width, uint32_t format, uint32_t type,
1396*35238bceSAndroid Build Coastguard Worker const void *data)
1397*35238bceSAndroid Build Coastguard Worker {
1398*35238bceSAndroid Build Coastguard Worker texSubImage2D(target, level, xoffset, 0, width, 1, format, type, data);
1399*35238bceSAndroid Build Coastguard Worker }
1400*35238bceSAndroid Build Coastguard Worker
texSubImage2D(uint32_t target,int level,int xoffset,int yoffset,int width,int height,uint32_t format,uint32_t type,const void * data)1401*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texSubImage2D(uint32_t target, int level, int xoffset, int yoffset, int width, int height,
1402*35238bceSAndroid Build Coastguard Worker uint32_t format, uint32_t type, const void *data)
1403*35238bceSAndroid Build Coastguard Worker {
1404*35238bceSAndroid Build Coastguard Worker texSubImage3D(target, level, xoffset, yoffset, 0, width, height, 1, format, type, data);
1405*35238bceSAndroid Build Coastguard Worker }
1406*35238bceSAndroid Build Coastguard Worker
texSubImage3D(uint32_t target,int level,int xoffset,int yoffset,int zoffset,int width,int height,int depth,uint32_t format,uint32_t type,const void * data)1407*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texSubImage3D(uint32_t target, int level, int xoffset, int yoffset, int zoffset, int width,
1408*35238bceSAndroid Build Coastguard Worker int height, int depth, uint32_t format, uint32_t type, const void *data)
1409*35238bceSAndroid Build Coastguard Worker {
1410*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1411*35238bceSAndroid Build Coastguard Worker
1412*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset < 0 || yoffset < 0 || zoffset < 0, GL_INVALID_VALUE, RC_RET_VOID);
1413*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || height < 0 || depth < 0, GL_INVALID_VALUE, RC_RET_VOID);
1414*35238bceSAndroid Build Coastguard Worker
1415*35238bceSAndroid Build Coastguard Worker TextureFormat transferFmt = glu::mapGLTransferFormat(format, type);
1416*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(transferFmt.order == TextureFormat::CHANNELORDER_LAST ||
1417*35238bceSAndroid Build Coastguard Worker transferFmt.type == TextureFormat::CHANNELTYPE_LAST,
1418*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1419*35238bceSAndroid Build Coastguard Worker
1420*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess src = getUnpack3DAccess(transferFmt, width, height, depth, getPixelUnpackPtr(data));
1421*35238bceSAndroid Build Coastguard Worker
1422*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_1D && glu::isContextTypeGLCore(m_limits.contextType))
1423*35238bceSAndroid Build Coastguard Worker {
1424*35238bceSAndroid Build Coastguard Worker Texture1D &texture = unit.tex1DBinding ? *unit.tex1DBinding : unit.default1DTex;
1425*35238bceSAndroid Build Coastguard Worker
1426*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1427*35238bceSAndroid Build Coastguard Worker
1428*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1429*35238bceSAndroid Build Coastguard Worker
1430*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight() ||
1431*35238bceSAndroid Build Coastguard Worker zoffset + depth > dst.getDepth(),
1432*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1433*35238bceSAndroid Build Coastguard Worker
1434*35238bceSAndroid Build Coastguard Worker // depth components are limited to [0,1] range
1435*35238bceSAndroid Build Coastguard Worker if (dst.getFormat().order == tcu::TextureFormat::D || dst.getFormat().order == tcu::TextureFormat::DS)
1436*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1437*35238bceSAndroid Build Coastguard Worker else
1438*35238bceSAndroid Build Coastguard Worker tcu::copy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1439*35238bceSAndroid Build Coastguard Worker }
1440*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_2D)
1441*35238bceSAndroid Build Coastguard Worker {
1442*35238bceSAndroid Build Coastguard Worker Texture2D &texture = unit.tex2DBinding ? *unit.tex2DBinding : unit.default2DTex;
1443*35238bceSAndroid Build Coastguard Worker
1444*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1445*35238bceSAndroid Build Coastguard Worker
1446*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1447*35238bceSAndroid Build Coastguard Worker
1448*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight() ||
1449*35238bceSAndroid Build Coastguard Worker zoffset + depth > dst.getDepth(),
1450*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1451*35238bceSAndroid Build Coastguard Worker
1452*35238bceSAndroid Build Coastguard Worker // depth components are limited to [0,1] range
1453*35238bceSAndroid Build Coastguard Worker if (dst.getFormat().order == tcu::TextureFormat::D || dst.getFormat().order == tcu::TextureFormat::DS)
1454*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1455*35238bceSAndroid Build Coastguard Worker else
1456*35238bceSAndroid Build Coastguard Worker tcu::copy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1457*35238bceSAndroid Build Coastguard Worker }
1458*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X || target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
1459*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
1460*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z)
1461*35238bceSAndroid Build Coastguard Worker {
1462*35238bceSAndroid Build Coastguard Worker TextureCube &texture = unit.texCubeBinding ? *unit.texCubeBinding : unit.defaultCubeTex;
1463*35238bceSAndroid Build Coastguard Worker tcu::CubeFace face = mapGLCubeFace(target);
1464*35238bceSAndroid Build Coastguard Worker
1465*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasFace(level, face), GL_INVALID_VALUE, RC_RET_VOID);
1466*35238bceSAndroid Build Coastguard Worker
1467*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getFace(level, face);
1468*35238bceSAndroid Build Coastguard Worker
1469*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight() ||
1470*35238bceSAndroid Build Coastguard Worker zoffset + depth > dst.getDepth(),
1471*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1472*35238bceSAndroid Build Coastguard Worker
1473*35238bceSAndroid Build Coastguard Worker // depth components are limited to [0,1] range
1474*35238bceSAndroid Build Coastguard Worker if (dst.getFormat().order == tcu::TextureFormat::D || dst.getFormat().order == tcu::TextureFormat::DS)
1475*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1476*35238bceSAndroid Build Coastguard Worker else
1477*35238bceSAndroid Build Coastguard Worker tcu::copy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1478*35238bceSAndroid Build Coastguard Worker }
1479*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_3D)
1480*35238bceSAndroid Build Coastguard Worker {
1481*35238bceSAndroid Build Coastguard Worker Texture3D &texture = unit.tex3DBinding ? *unit.tex3DBinding : unit.default3DTex;
1482*35238bceSAndroid Build Coastguard Worker
1483*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1484*35238bceSAndroid Build Coastguard Worker
1485*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1486*35238bceSAndroid Build Coastguard Worker
1487*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight() ||
1488*35238bceSAndroid Build Coastguard Worker zoffset + depth > dst.getDepth(),
1489*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1490*35238bceSAndroid Build Coastguard Worker
1491*35238bceSAndroid Build Coastguard Worker // depth components are limited to [0,1] range
1492*35238bceSAndroid Build Coastguard Worker if (dst.getFormat().order == tcu::TextureFormat::D || dst.getFormat().order == tcu::TextureFormat::DS)
1493*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1494*35238bceSAndroid Build Coastguard Worker else
1495*35238bceSAndroid Build Coastguard Worker tcu::copy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1496*35238bceSAndroid Build Coastguard Worker }
1497*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_2D_ARRAY)
1498*35238bceSAndroid Build Coastguard Worker {
1499*35238bceSAndroid Build Coastguard Worker Texture2DArray &texture = unit.tex2DArrayBinding ? *unit.tex2DArrayBinding : unit.default2DArrayTex;
1500*35238bceSAndroid Build Coastguard Worker
1501*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1502*35238bceSAndroid Build Coastguard Worker
1503*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1504*35238bceSAndroid Build Coastguard Worker
1505*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight() ||
1506*35238bceSAndroid Build Coastguard Worker zoffset + depth > dst.getDepth(),
1507*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1508*35238bceSAndroid Build Coastguard Worker
1509*35238bceSAndroid Build Coastguard Worker // depth components are limited to [0,1] range
1510*35238bceSAndroid Build Coastguard Worker if (dst.getFormat().order == tcu::TextureFormat::D || dst.getFormat().order == tcu::TextureFormat::DS)
1511*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1512*35238bceSAndroid Build Coastguard Worker else
1513*35238bceSAndroid Build Coastguard Worker tcu::copy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1514*35238bceSAndroid Build Coastguard Worker }
1515*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_ARRAY)
1516*35238bceSAndroid Build Coastguard Worker {
1517*35238bceSAndroid Build Coastguard Worker TextureCubeArray &texture = unit.texCubeArrayBinding ? *unit.texCubeArrayBinding : unit.defaultCubeArrayTex;
1518*35238bceSAndroid Build Coastguard Worker
1519*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1520*35238bceSAndroid Build Coastguard Worker
1521*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1522*35238bceSAndroid Build Coastguard Worker
1523*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight() ||
1524*35238bceSAndroid Build Coastguard Worker zoffset + depth > dst.getDepth(),
1525*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1526*35238bceSAndroid Build Coastguard Worker
1527*35238bceSAndroid Build Coastguard Worker // depth components are limited to [0,1] range
1528*35238bceSAndroid Build Coastguard Worker if (dst.getFormat().order == tcu::TextureFormat::D || dst.getFormat().order == tcu::TextureFormat::DS)
1529*35238bceSAndroid Build Coastguard Worker depthValueFloatClampCopy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1530*35238bceSAndroid Build Coastguard Worker else
1531*35238bceSAndroid Build Coastguard Worker tcu::copy(tcu::getSubregion(dst, xoffset, yoffset, zoffset, width, height, depth), src);
1532*35238bceSAndroid Build Coastguard Worker }
1533*35238bceSAndroid Build Coastguard Worker else
1534*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1535*35238bceSAndroid Build Coastguard Worker }
1536*35238bceSAndroid Build Coastguard Worker
copyTexImage1D(uint32_t target,int level,uint32_t internalFormat,int x,int y,int width,int border)1537*35238bceSAndroid Build Coastguard Worker void ReferenceContext::copyTexImage1D(uint32_t target, int level, uint32_t internalFormat, int x, int y, int width,
1538*35238bceSAndroid Build Coastguard Worker int border)
1539*35238bceSAndroid Build Coastguard Worker {
1540*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1541*35238bceSAndroid Build Coastguard Worker TextureFormat storageFmt;
1542*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getReadColorbuffer();
1543*35238bceSAndroid Build Coastguard Worker
1544*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(border != 0, GL_INVALID_VALUE, RC_RET_VOID);
1545*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || level < 0, GL_INVALID_VALUE, RC_RET_VOID);
1546*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(isEmpty(src), GL_INVALID_OPERATION, RC_RET_VOID);
1547*35238bceSAndroid Build Coastguard Worker
1548*35238bceSAndroid Build Coastguard Worker // Map storage format.
1549*35238bceSAndroid Build Coastguard Worker storageFmt = mapInternalFormat(internalFormat);
1550*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt.order == TextureFormat::CHANNELORDER_LAST ||
1551*35238bceSAndroid Build Coastguard Worker storageFmt.type == TextureFormat::CHANNELTYPE_LAST,
1552*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1553*35238bceSAndroid Build Coastguard Worker
1554*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_1D)
1555*35238bceSAndroid Build Coastguard Worker {
1556*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1557*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize, GL_INVALID_VALUE, RC_RET_VOID);
1558*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture2DSize), GL_INVALID_VALUE, RC_RET_VOID);
1559*35238bceSAndroid Build Coastguard Worker
1560*35238bceSAndroid Build Coastguard Worker Texture1D *texture = unit.tex1DBinding ? unit.tex1DBinding : &unit.default1DTex;
1561*35238bceSAndroid Build Coastguard Worker
1562*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1563*35238bceSAndroid Build Coastguard Worker {
1564*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1565*35238bceSAndroid Build Coastguard Worker
1566*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1567*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth(), GL_INVALID_OPERATION, RC_RET_VOID);
1568*35238bceSAndroid Build Coastguard Worker }
1569*35238bceSAndroid Build Coastguard Worker else
1570*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width);
1571*35238bceSAndroid Build Coastguard Worker
1572*35238bceSAndroid Build Coastguard Worker // Copy from current framebuffer.
1573*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture->getLevel(level);
1574*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < width; xo++)
1575*35238bceSAndroid Build Coastguard Worker {
1576*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(x + xo, 0, src.raw().getHeight()))
1577*35238bceSAndroid Build Coastguard Worker continue; // Undefined pixel.
1578*35238bceSAndroid Build Coastguard Worker
1579*35238bceSAndroid Build Coastguard Worker dst.setPixel(rr::resolveMultisamplePixel(src, x + xo, y), xo, 0);
1580*35238bceSAndroid Build Coastguard Worker }
1581*35238bceSAndroid Build Coastguard Worker }
1582*35238bceSAndroid Build Coastguard Worker else
1583*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1584*35238bceSAndroid Build Coastguard Worker }
1585*35238bceSAndroid Build Coastguard Worker
copyTexImage2D(uint32_t target,int level,uint32_t internalFormat,int x,int y,int width,int height,int border)1586*35238bceSAndroid Build Coastguard Worker void ReferenceContext::copyTexImage2D(uint32_t target, int level, uint32_t internalFormat, int x, int y, int width,
1587*35238bceSAndroid Build Coastguard Worker int height, int border)
1588*35238bceSAndroid Build Coastguard Worker {
1589*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1590*35238bceSAndroid Build Coastguard Worker TextureFormat storageFmt;
1591*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getReadColorbuffer();
1592*35238bceSAndroid Build Coastguard Worker
1593*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(border != 0, GL_INVALID_VALUE, RC_RET_VOID);
1594*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || height < 0 || level < 0, GL_INVALID_VALUE, RC_RET_VOID);
1595*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(isEmpty(src), GL_INVALID_OPERATION, RC_RET_VOID);
1596*35238bceSAndroid Build Coastguard Worker
1597*35238bceSAndroid Build Coastguard Worker // Map storage format.
1598*35238bceSAndroid Build Coastguard Worker storageFmt = mapInternalFormat(internalFormat);
1599*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt.order == TextureFormat::CHANNELORDER_LAST ||
1600*35238bceSAndroid Build Coastguard Worker storageFmt.type == TextureFormat::CHANNELTYPE_LAST,
1601*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1602*35238bceSAndroid Build Coastguard Worker
1603*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_2D)
1604*35238bceSAndroid Build Coastguard Worker {
1605*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1606*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize || height > m_limits.maxTexture2DSize, GL_INVALID_VALUE,
1607*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
1608*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTexture2DSize), GL_INVALID_VALUE, RC_RET_VOID);
1609*35238bceSAndroid Build Coastguard Worker
1610*35238bceSAndroid Build Coastguard Worker Texture2D *texture = unit.tex2DBinding ? unit.tex2DBinding : &unit.default2DTex;
1611*35238bceSAndroid Build Coastguard Worker
1612*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1613*35238bceSAndroid Build Coastguard Worker {
1614*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasLevel(level), GL_INVALID_OPERATION, RC_RET_VOID);
1615*35238bceSAndroid Build Coastguard Worker
1616*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getLevel(level));
1617*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight(),
1618*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1619*35238bceSAndroid Build Coastguard Worker }
1620*35238bceSAndroid Build Coastguard Worker else
1621*35238bceSAndroid Build Coastguard Worker texture->allocLevel(level, storageFmt, width, height);
1622*35238bceSAndroid Build Coastguard Worker
1623*35238bceSAndroid Build Coastguard Worker // Copy from current framebuffer.
1624*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture->getLevel(level);
1625*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < height; yo++)
1626*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < width; xo++)
1627*35238bceSAndroid Build Coastguard Worker {
1628*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(x + xo, 0, src.raw().getHeight()) || !de::inBounds(y + yo, 0, src.raw().getDepth()))
1629*35238bceSAndroid Build Coastguard Worker continue; // Undefined pixel.
1630*35238bceSAndroid Build Coastguard Worker
1631*35238bceSAndroid Build Coastguard Worker dst.setPixel(rr::resolveMultisamplePixel(src, x + xo, y + yo), xo, yo);
1632*35238bceSAndroid Build Coastguard Worker }
1633*35238bceSAndroid Build Coastguard Worker }
1634*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X || target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
1635*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
1636*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z)
1637*35238bceSAndroid Build Coastguard Worker {
1638*35238bceSAndroid Build Coastguard Worker // Validate size and level.
1639*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width != height || width > m_limits.maxTextureCubeSize, GL_INVALID_VALUE, RC_RET_VOID);
1640*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level > deLog2Floor32(m_limits.maxTextureCubeSize), GL_INVALID_VALUE, RC_RET_VOID);
1641*35238bceSAndroid Build Coastguard Worker
1642*35238bceSAndroid Build Coastguard Worker TextureCube *texture = unit.texCubeBinding ? unit.texCubeBinding : &unit.defaultCubeTex;
1643*35238bceSAndroid Build Coastguard Worker tcu::CubeFace face = mapGLCubeFace(target);
1644*35238bceSAndroid Build Coastguard Worker
1645*35238bceSAndroid Build Coastguard Worker if (texture->isImmutable())
1646*35238bceSAndroid Build Coastguard Worker {
1647*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture->hasFace(level, face), GL_INVALID_OPERATION, RC_RET_VOID);
1648*35238bceSAndroid Build Coastguard Worker
1649*35238bceSAndroid Build Coastguard Worker ConstPixelBufferAccess dst(texture->getFace(level, face));
1650*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt != dst.getFormat() || width != dst.getWidth() || height != dst.getHeight(),
1651*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
1652*35238bceSAndroid Build Coastguard Worker }
1653*35238bceSAndroid Build Coastguard Worker else
1654*35238bceSAndroid Build Coastguard Worker texture->allocFace(level, face, storageFmt, width, height);
1655*35238bceSAndroid Build Coastguard Worker
1656*35238bceSAndroid Build Coastguard Worker // Copy from current framebuffer.
1657*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture->getFace(level, face);
1658*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < height; yo++)
1659*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < width; xo++)
1660*35238bceSAndroid Build Coastguard Worker {
1661*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(x + xo, 0, src.raw().getHeight()) || !de::inBounds(y + yo, 0, src.raw().getDepth()))
1662*35238bceSAndroid Build Coastguard Worker continue; // Undefined pixel.
1663*35238bceSAndroid Build Coastguard Worker
1664*35238bceSAndroid Build Coastguard Worker dst.setPixel(rr::resolveMultisamplePixel(src, x + xo, y + yo), xo, yo);
1665*35238bceSAndroid Build Coastguard Worker }
1666*35238bceSAndroid Build Coastguard Worker }
1667*35238bceSAndroid Build Coastguard Worker else
1668*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1669*35238bceSAndroid Build Coastguard Worker }
1670*35238bceSAndroid Build Coastguard Worker
copyTexSubImage1D(uint32_t target,int level,int xoffset,int x,int y,int width)1671*35238bceSAndroid Build Coastguard Worker void ReferenceContext::copyTexSubImage1D(uint32_t target, int level, int xoffset, int x, int y, int width)
1672*35238bceSAndroid Build Coastguard Worker {
1673*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1674*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getReadColorbuffer();
1675*35238bceSAndroid Build Coastguard Worker
1676*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset < 0, GL_INVALID_VALUE, RC_RET_VOID);
1677*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0, GL_INVALID_VALUE, RC_RET_VOID);
1678*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(isEmpty(src), GL_INVALID_OPERATION, RC_RET_VOID);
1679*35238bceSAndroid Build Coastguard Worker
1680*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_1D)
1681*35238bceSAndroid Build Coastguard Worker {
1682*35238bceSAndroid Build Coastguard Worker Texture1D &texture = unit.tex1DBinding ? *unit.tex1DBinding : unit.default1DTex;
1683*35238bceSAndroid Build Coastguard Worker
1684*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1685*35238bceSAndroid Build Coastguard Worker
1686*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1687*35238bceSAndroid Build Coastguard Worker
1688*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth(), GL_INVALID_VALUE, RC_RET_VOID);
1689*35238bceSAndroid Build Coastguard Worker
1690*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < width; xo++)
1691*35238bceSAndroid Build Coastguard Worker {
1692*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(x + xo, 0, src.raw().getHeight()))
1693*35238bceSAndroid Build Coastguard Worker continue;
1694*35238bceSAndroid Build Coastguard Worker
1695*35238bceSAndroid Build Coastguard Worker dst.setPixel(rr::resolveMultisamplePixel(src, x + xo, y), xo + xoffset, 0);
1696*35238bceSAndroid Build Coastguard Worker }
1697*35238bceSAndroid Build Coastguard Worker }
1698*35238bceSAndroid Build Coastguard Worker else
1699*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1700*35238bceSAndroid Build Coastguard Worker }
1701*35238bceSAndroid Build Coastguard Worker
copyTexSubImage2D(uint32_t target,int level,int xoffset,int yoffset,int x,int y,int width,int height)1702*35238bceSAndroid Build Coastguard Worker void ReferenceContext::copyTexSubImage2D(uint32_t target, int level, int xoffset, int yoffset, int x, int y, int width,
1703*35238bceSAndroid Build Coastguard Worker int height)
1704*35238bceSAndroid Build Coastguard Worker {
1705*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1706*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getReadColorbuffer();
1707*35238bceSAndroid Build Coastguard Worker
1708*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset < 0 || yoffset < 0, GL_INVALID_VALUE, RC_RET_VOID);
1709*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || height < 0, GL_INVALID_VALUE, RC_RET_VOID);
1710*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(isEmpty(src), GL_INVALID_OPERATION, RC_RET_VOID);
1711*35238bceSAndroid Build Coastguard Worker
1712*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_2D)
1713*35238bceSAndroid Build Coastguard Worker {
1714*35238bceSAndroid Build Coastguard Worker Texture2D &texture = unit.tex2DBinding ? *unit.tex2DBinding : unit.default2DTex;
1715*35238bceSAndroid Build Coastguard Worker
1716*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasLevel(level), GL_INVALID_VALUE, RC_RET_VOID);
1717*35238bceSAndroid Build Coastguard Worker
1718*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getLevel(level);
1719*35238bceSAndroid Build Coastguard Worker
1720*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight(), GL_INVALID_VALUE,
1721*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
1722*35238bceSAndroid Build Coastguard Worker
1723*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < height; yo++)
1724*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < width; xo++)
1725*35238bceSAndroid Build Coastguard Worker {
1726*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(x + xo, 0, src.raw().getHeight()) || !de::inBounds(y + yo, 0, src.raw().getDepth()))
1727*35238bceSAndroid Build Coastguard Worker continue;
1728*35238bceSAndroid Build Coastguard Worker
1729*35238bceSAndroid Build Coastguard Worker dst.setPixel(rr::resolveMultisamplePixel(src, x + xo, y + yo), xo + xoffset, yo + yoffset);
1730*35238bceSAndroid Build Coastguard Worker }
1731*35238bceSAndroid Build Coastguard Worker }
1732*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X || target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
1733*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
1734*35238bceSAndroid Build Coastguard Worker target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z || target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z)
1735*35238bceSAndroid Build Coastguard Worker {
1736*35238bceSAndroid Build Coastguard Worker TextureCube &texture = unit.texCubeBinding ? *unit.texCubeBinding : unit.defaultCubeTex;
1737*35238bceSAndroid Build Coastguard Worker tcu::CubeFace face = mapGLCubeFace(target);
1738*35238bceSAndroid Build Coastguard Worker
1739*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texture.hasFace(level, face), GL_INVALID_VALUE, RC_RET_VOID);
1740*35238bceSAndroid Build Coastguard Worker
1741*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst = texture.getFace(level, face);
1742*35238bceSAndroid Build Coastguard Worker
1743*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(xoffset + width > dst.getWidth() || yoffset + height > dst.getHeight(), GL_INVALID_VALUE,
1744*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
1745*35238bceSAndroid Build Coastguard Worker
1746*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < height; yo++)
1747*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < width; xo++)
1748*35238bceSAndroid Build Coastguard Worker {
1749*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(x + xo, 0, src.raw().getHeight()) || !de::inBounds(y + yo, 0, src.raw().getDepth()))
1750*35238bceSAndroid Build Coastguard Worker continue;
1751*35238bceSAndroid Build Coastguard Worker
1752*35238bceSAndroid Build Coastguard Worker dst.setPixel(rr::resolveMultisamplePixel(src, x + xo, y + yo), xo + xoffset, yo + yoffset);
1753*35238bceSAndroid Build Coastguard Worker }
1754*35238bceSAndroid Build Coastguard Worker }
1755*35238bceSAndroid Build Coastguard Worker else
1756*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1757*35238bceSAndroid Build Coastguard Worker }
1758*35238bceSAndroid Build Coastguard Worker
copyTexSubImage3D(uint32_t target,int level,int xoffset,int yoffset,int zoffset,int x,int y,int width,int height)1759*35238bceSAndroid Build Coastguard Worker void ReferenceContext::copyTexSubImage3D(uint32_t target, int level, int xoffset, int yoffset, int zoffset, int x,
1760*35238bceSAndroid Build Coastguard Worker int y, int width, int height)
1761*35238bceSAndroid Build Coastguard Worker {
1762*35238bceSAndroid Build Coastguard Worker DE_UNREF(target && level && xoffset && yoffset && zoffset && x && y && width && height);
1763*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1764*35238bceSAndroid Build Coastguard Worker }
1765*35238bceSAndroid Build Coastguard Worker
texStorage2D(uint32_t target,int levels,uint32_t internalFormat,int width,int height)1766*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texStorage2D(uint32_t target, int levels, uint32_t internalFormat, int width, int height)
1767*35238bceSAndroid Build Coastguard Worker {
1768*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1769*35238bceSAndroid Build Coastguard Worker TextureFormat storageFmt;
1770*35238bceSAndroid Build Coastguard Worker
1771*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width <= 0 || height <= 0, GL_INVALID_VALUE, RC_RET_VOID);
1772*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!de::inRange(levels, 1, (int)deLog2Floor32(de::max(width, height)) + 1), GL_INVALID_VALUE, RC_RET_VOID);
1773*35238bceSAndroid Build Coastguard Worker
1774*35238bceSAndroid Build Coastguard Worker // Map storage format.
1775*35238bceSAndroid Build Coastguard Worker storageFmt = mapInternalFormat(internalFormat);
1776*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt.order == TextureFormat::CHANNELORDER_LAST ||
1777*35238bceSAndroid Build Coastguard Worker storageFmt.type == TextureFormat::CHANNELTYPE_LAST,
1778*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1779*35238bceSAndroid Build Coastguard Worker
1780*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_2D)
1781*35238bceSAndroid Build Coastguard Worker {
1782*35238bceSAndroid Build Coastguard Worker Texture2D &texture = unit.tex2DBinding ? *unit.tex2DBinding : unit.default2DTex;
1783*35238bceSAndroid Build Coastguard Worker
1784*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize || height >= m_limits.maxTexture2DSize, GL_INVALID_VALUE,
1785*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
1786*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texture.isImmutable(), GL_INVALID_OPERATION, RC_RET_VOID);
1787*35238bceSAndroid Build Coastguard Worker
1788*35238bceSAndroid Build Coastguard Worker texture.clearLevels();
1789*35238bceSAndroid Build Coastguard Worker texture.setImmutable();
1790*35238bceSAndroid Build Coastguard Worker
1791*35238bceSAndroid Build Coastguard Worker for (int level = 0; level < levels; level++)
1792*35238bceSAndroid Build Coastguard Worker {
1793*35238bceSAndroid Build Coastguard Worker int levelW = de::max(1, width >> level);
1794*35238bceSAndroid Build Coastguard Worker int levelH = de::max(1, height >> level);
1795*35238bceSAndroid Build Coastguard Worker
1796*35238bceSAndroid Build Coastguard Worker texture.allocLevel(level, storageFmt, levelW, levelH);
1797*35238bceSAndroid Build Coastguard Worker }
1798*35238bceSAndroid Build Coastguard Worker }
1799*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP)
1800*35238bceSAndroid Build Coastguard Worker {
1801*35238bceSAndroid Build Coastguard Worker TextureCube &texture = unit.texCubeBinding ? *unit.texCubeBinding : unit.defaultCubeTex;
1802*35238bceSAndroid Build Coastguard Worker
1803*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTextureCubeSize || height > m_limits.maxTextureCubeSize, GL_INVALID_VALUE,
1804*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
1805*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texture.isImmutable(), GL_INVALID_OPERATION, RC_RET_VOID);
1806*35238bceSAndroid Build Coastguard Worker
1807*35238bceSAndroid Build Coastguard Worker texture.clearLevels();
1808*35238bceSAndroid Build Coastguard Worker texture.setImmutable();
1809*35238bceSAndroid Build Coastguard Worker
1810*35238bceSAndroid Build Coastguard Worker for (int level = 0; level < levels; level++)
1811*35238bceSAndroid Build Coastguard Worker {
1812*35238bceSAndroid Build Coastguard Worker int levelW = de::max(1, width >> level);
1813*35238bceSAndroid Build Coastguard Worker int levelH = de::max(1, height >> level);
1814*35238bceSAndroid Build Coastguard Worker
1815*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
1816*35238bceSAndroid Build Coastguard Worker texture.allocFace(level, (tcu::CubeFace)face, storageFmt, levelW, levelH);
1817*35238bceSAndroid Build Coastguard Worker }
1818*35238bceSAndroid Build Coastguard Worker }
1819*35238bceSAndroid Build Coastguard Worker else
1820*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1821*35238bceSAndroid Build Coastguard Worker }
1822*35238bceSAndroid Build Coastguard Worker
texStorage3D(uint32_t target,int levels,uint32_t internalFormat,int width,int height,int depth)1823*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texStorage3D(uint32_t target, int levels, uint32_t internalFormat, int width, int height,
1824*35238bceSAndroid Build Coastguard Worker int depth)
1825*35238bceSAndroid Build Coastguard Worker {
1826*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1827*35238bceSAndroid Build Coastguard Worker TextureFormat storageFmt;
1828*35238bceSAndroid Build Coastguard Worker
1829*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width <= 0 || height <= 0, GL_INVALID_VALUE, RC_RET_VOID);
1830*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!de::inRange(levels, 1, (int)deLog2Floor32(de::max(width, height)) + 1), GL_INVALID_VALUE, RC_RET_VOID);
1831*35238bceSAndroid Build Coastguard Worker
1832*35238bceSAndroid Build Coastguard Worker // Map storage format.
1833*35238bceSAndroid Build Coastguard Worker storageFmt = mapInternalFormat(internalFormat);
1834*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(storageFmt.order == TextureFormat::CHANNELORDER_LAST ||
1835*35238bceSAndroid Build Coastguard Worker storageFmt.type == TextureFormat::CHANNELTYPE_LAST,
1836*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
1837*35238bceSAndroid Build Coastguard Worker
1838*35238bceSAndroid Build Coastguard Worker if (target == GL_TEXTURE_2D_ARRAY)
1839*35238bceSAndroid Build Coastguard Worker {
1840*35238bceSAndroid Build Coastguard Worker Texture2DArray &texture = unit.tex2DArrayBinding ? *unit.tex2DArrayBinding : unit.default2DArrayTex;
1841*35238bceSAndroid Build Coastguard Worker
1842*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture2DSize || height >= m_limits.maxTexture2DSize ||
1843*35238bceSAndroid Build Coastguard Worker depth >= m_limits.maxTexture2DArrayLayers,
1844*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1845*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texture.isImmutable(), GL_INVALID_OPERATION, RC_RET_VOID);
1846*35238bceSAndroid Build Coastguard Worker
1847*35238bceSAndroid Build Coastguard Worker texture.clearLevels();
1848*35238bceSAndroid Build Coastguard Worker texture.setImmutable();
1849*35238bceSAndroid Build Coastguard Worker
1850*35238bceSAndroid Build Coastguard Worker for (int level = 0; level < levels; level++)
1851*35238bceSAndroid Build Coastguard Worker {
1852*35238bceSAndroid Build Coastguard Worker int levelW = de::max(1, width >> level);
1853*35238bceSAndroid Build Coastguard Worker int levelH = de::max(1, height >> level);
1854*35238bceSAndroid Build Coastguard Worker
1855*35238bceSAndroid Build Coastguard Worker texture.allocLevel(level, storageFmt, levelW, levelH, depth);
1856*35238bceSAndroid Build Coastguard Worker }
1857*35238bceSAndroid Build Coastguard Worker }
1858*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_3D)
1859*35238bceSAndroid Build Coastguard Worker {
1860*35238bceSAndroid Build Coastguard Worker Texture3D &texture = unit.tex3DBinding ? *unit.tex3DBinding : unit.default3DTex;
1861*35238bceSAndroid Build Coastguard Worker
1862*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width > m_limits.maxTexture3DSize || height > m_limits.maxTexture3DSize ||
1863*35238bceSAndroid Build Coastguard Worker depth > m_limits.maxTexture3DSize,
1864*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1865*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texture.isImmutable(), GL_INVALID_OPERATION, RC_RET_VOID);
1866*35238bceSAndroid Build Coastguard Worker
1867*35238bceSAndroid Build Coastguard Worker texture.clearLevels();
1868*35238bceSAndroid Build Coastguard Worker texture.setImmutable();
1869*35238bceSAndroid Build Coastguard Worker
1870*35238bceSAndroid Build Coastguard Worker for (int level = 0; level < levels; level++)
1871*35238bceSAndroid Build Coastguard Worker {
1872*35238bceSAndroid Build Coastguard Worker int levelW = de::max(1, width >> level);
1873*35238bceSAndroid Build Coastguard Worker int levelH = de::max(1, height >> level);
1874*35238bceSAndroid Build Coastguard Worker int levelD = de::max(1, depth >> level);
1875*35238bceSAndroid Build Coastguard Worker
1876*35238bceSAndroid Build Coastguard Worker texture.allocLevel(level, storageFmt, levelW, levelH, levelD);
1877*35238bceSAndroid Build Coastguard Worker }
1878*35238bceSAndroid Build Coastguard Worker }
1879*35238bceSAndroid Build Coastguard Worker else if (target == GL_TEXTURE_CUBE_MAP_ARRAY)
1880*35238bceSAndroid Build Coastguard Worker {
1881*35238bceSAndroid Build Coastguard Worker TextureCubeArray &texture = unit.texCubeArrayBinding ? *unit.texCubeArrayBinding : unit.defaultCubeArrayTex;
1882*35238bceSAndroid Build Coastguard Worker
1883*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width != height || depth % 6 != 0 || width > m_limits.maxTexture2DSize ||
1884*35238bceSAndroid Build Coastguard Worker depth >= m_limits.maxTexture2DArrayLayers,
1885*35238bceSAndroid Build Coastguard Worker GL_INVALID_VALUE, RC_RET_VOID);
1886*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texture.isImmutable(), GL_INVALID_OPERATION, RC_RET_VOID);
1887*35238bceSAndroid Build Coastguard Worker
1888*35238bceSAndroid Build Coastguard Worker texture.clearLevels();
1889*35238bceSAndroid Build Coastguard Worker texture.setImmutable();
1890*35238bceSAndroid Build Coastguard Worker
1891*35238bceSAndroid Build Coastguard Worker for (int level = 0; level < levels; level++)
1892*35238bceSAndroid Build Coastguard Worker {
1893*35238bceSAndroid Build Coastguard Worker int levelW = de::max(1, width >> level);
1894*35238bceSAndroid Build Coastguard Worker int levelH = de::max(1, height >> level);
1895*35238bceSAndroid Build Coastguard Worker
1896*35238bceSAndroid Build Coastguard Worker texture.allocLevel(level, storageFmt, levelW, levelH, depth);
1897*35238bceSAndroid Build Coastguard Worker }
1898*35238bceSAndroid Build Coastguard Worker }
1899*35238bceSAndroid Build Coastguard Worker else
1900*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1901*35238bceSAndroid Build Coastguard Worker }
1902*35238bceSAndroid Build Coastguard Worker
1903*35238bceSAndroid Build Coastguard Worker // \todo [2014-02-19 pyry] Duplicated with code in gluTextureUtil.hpp
1904*35238bceSAndroid Build Coastguard Worker
mapGLWrapMode(int value)1905*35238bceSAndroid Build Coastguard Worker static inline tcu::Sampler::WrapMode mapGLWrapMode(int value)
1906*35238bceSAndroid Build Coastguard Worker {
1907*35238bceSAndroid Build Coastguard Worker switch (value)
1908*35238bceSAndroid Build Coastguard Worker {
1909*35238bceSAndroid Build Coastguard Worker case GL_CLAMP_TO_EDGE:
1910*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::CLAMP_TO_EDGE;
1911*35238bceSAndroid Build Coastguard Worker case GL_REPEAT:
1912*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::REPEAT_GL;
1913*35238bceSAndroid Build Coastguard Worker case GL_MIRRORED_REPEAT:
1914*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::MIRRORED_REPEAT_GL;
1915*35238bceSAndroid Build Coastguard Worker default:
1916*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::WRAPMODE_LAST;
1917*35238bceSAndroid Build Coastguard Worker }
1918*35238bceSAndroid Build Coastguard Worker }
1919*35238bceSAndroid Build Coastguard Worker
mapGLFilterMode(int value)1920*35238bceSAndroid Build Coastguard Worker static inline tcu::Sampler::FilterMode mapGLFilterMode(int value)
1921*35238bceSAndroid Build Coastguard Worker {
1922*35238bceSAndroid Build Coastguard Worker switch (value)
1923*35238bceSAndroid Build Coastguard Worker {
1924*35238bceSAndroid Build Coastguard Worker case GL_NEAREST:
1925*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::NEAREST;
1926*35238bceSAndroid Build Coastguard Worker case GL_LINEAR:
1927*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::LINEAR;
1928*35238bceSAndroid Build Coastguard Worker case GL_NEAREST_MIPMAP_NEAREST:
1929*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
1930*35238bceSAndroid Build Coastguard Worker case GL_NEAREST_MIPMAP_LINEAR:
1931*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
1932*35238bceSAndroid Build Coastguard Worker case GL_LINEAR_MIPMAP_NEAREST:
1933*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
1934*35238bceSAndroid Build Coastguard Worker case GL_LINEAR_MIPMAP_LINEAR:
1935*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
1936*35238bceSAndroid Build Coastguard Worker default:
1937*35238bceSAndroid Build Coastguard Worker return tcu::Sampler::FILTERMODE_LAST;
1938*35238bceSAndroid Build Coastguard Worker }
1939*35238bceSAndroid Build Coastguard Worker }
1940*35238bceSAndroid Build Coastguard Worker
texParameteri(uint32_t target,uint32_t pname,int value)1941*35238bceSAndroid Build Coastguard Worker void ReferenceContext::texParameteri(uint32_t target, uint32_t pname, int value)
1942*35238bceSAndroid Build Coastguard Worker {
1943*35238bceSAndroid Build Coastguard Worker TextureUnit &unit = m_textureUnits[m_activeTexture];
1944*35238bceSAndroid Build Coastguard Worker Texture *texture = DE_NULL;
1945*35238bceSAndroid Build Coastguard Worker
1946*35238bceSAndroid Build Coastguard Worker switch (target)
1947*35238bceSAndroid Build Coastguard Worker {
1948*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_1D:
1949*35238bceSAndroid Build Coastguard Worker texture = unit.tex1DBinding ? unit.tex1DBinding : &unit.default1DTex;
1950*35238bceSAndroid Build Coastguard Worker break;
1951*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
1952*35238bceSAndroid Build Coastguard Worker texture = unit.tex2DBinding ? unit.tex2DBinding : &unit.default2DTex;
1953*35238bceSAndroid Build Coastguard Worker break;
1954*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP:
1955*35238bceSAndroid Build Coastguard Worker texture = unit.texCubeBinding ? unit.texCubeBinding : &unit.defaultCubeTex;
1956*35238bceSAndroid Build Coastguard Worker break;
1957*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D_ARRAY:
1958*35238bceSAndroid Build Coastguard Worker texture = unit.tex2DArrayBinding ? unit.tex2DArrayBinding : &unit.default2DArrayTex;
1959*35238bceSAndroid Build Coastguard Worker break;
1960*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_3D:
1961*35238bceSAndroid Build Coastguard Worker texture = unit.tex3DBinding ? unit.tex3DBinding : &unit.default3DTex;
1962*35238bceSAndroid Build Coastguard Worker break;
1963*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_ARRAY:
1964*35238bceSAndroid Build Coastguard Worker texture = unit.texCubeArrayBinding ? unit.texCubeArrayBinding : &unit.defaultCubeArrayTex;
1965*35238bceSAndroid Build Coastguard Worker break;
1966*35238bceSAndroid Build Coastguard Worker
1967*35238bceSAndroid Build Coastguard Worker default:
1968*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
1969*35238bceSAndroid Build Coastguard Worker }
1970*35238bceSAndroid Build Coastguard Worker
1971*35238bceSAndroid Build Coastguard Worker switch (pname)
1972*35238bceSAndroid Build Coastguard Worker {
1973*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_WRAP_S:
1974*35238bceSAndroid Build Coastguard Worker {
1975*35238bceSAndroid Build Coastguard Worker tcu::Sampler::WrapMode wrapS = mapGLWrapMode(value);
1976*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(wrapS == tcu::Sampler::WRAPMODE_LAST, GL_INVALID_VALUE, RC_RET_VOID);
1977*35238bceSAndroid Build Coastguard Worker texture->getSampler().wrapS = wrapS;
1978*35238bceSAndroid Build Coastguard Worker break;
1979*35238bceSAndroid Build Coastguard Worker }
1980*35238bceSAndroid Build Coastguard Worker
1981*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_WRAP_T:
1982*35238bceSAndroid Build Coastguard Worker {
1983*35238bceSAndroid Build Coastguard Worker tcu::Sampler::WrapMode wrapT = mapGLWrapMode(value);
1984*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(wrapT == tcu::Sampler::WRAPMODE_LAST, GL_INVALID_VALUE, RC_RET_VOID);
1985*35238bceSAndroid Build Coastguard Worker texture->getSampler().wrapT = wrapT;
1986*35238bceSAndroid Build Coastguard Worker break;
1987*35238bceSAndroid Build Coastguard Worker }
1988*35238bceSAndroid Build Coastguard Worker
1989*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_WRAP_R:
1990*35238bceSAndroid Build Coastguard Worker {
1991*35238bceSAndroid Build Coastguard Worker tcu::Sampler::WrapMode wrapR = mapGLWrapMode(value);
1992*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(wrapR == tcu::Sampler::WRAPMODE_LAST, GL_INVALID_VALUE, RC_RET_VOID);
1993*35238bceSAndroid Build Coastguard Worker texture->getSampler().wrapR = wrapR;
1994*35238bceSAndroid Build Coastguard Worker break;
1995*35238bceSAndroid Build Coastguard Worker }
1996*35238bceSAndroid Build Coastguard Worker
1997*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_MIN_FILTER:
1998*35238bceSAndroid Build Coastguard Worker {
1999*35238bceSAndroid Build Coastguard Worker tcu::Sampler::FilterMode minMode = mapGLFilterMode(value);
2000*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(minMode == tcu::Sampler::FILTERMODE_LAST, GL_INVALID_VALUE, RC_RET_VOID);
2001*35238bceSAndroid Build Coastguard Worker texture->getSampler().minFilter = minMode;
2002*35238bceSAndroid Build Coastguard Worker break;
2003*35238bceSAndroid Build Coastguard Worker }
2004*35238bceSAndroid Build Coastguard Worker
2005*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_MAG_FILTER:
2006*35238bceSAndroid Build Coastguard Worker {
2007*35238bceSAndroid Build Coastguard Worker tcu::Sampler::FilterMode magMode = mapGLFilterMode(value);
2008*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(magMode != tcu::Sampler::LINEAR && magMode != tcu::Sampler::NEAREST, GL_INVALID_VALUE, RC_RET_VOID);
2009*35238bceSAndroid Build Coastguard Worker texture->getSampler().magFilter = magMode;
2010*35238bceSAndroid Build Coastguard Worker break;
2011*35238bceSAndroid Build Coastguard Worker }
2012*35238bceSAndroid Build Coastguard Worker
2013*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_MAX_LEVEL:
2014*35238bceSAndroid Build Coastguard Worker {
2015*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(value < 0, GL_INVALID_VALUE, RC_RET_VOID);
2016*35238bceSAndroid Build Coastguard Worker texture->setMaxLevel(value);
2017*35238bceSAndroid Build Coastguard Worker break;
2018*35238bceSAndroid Build Coastguard Worker }
2019*35238bceSAndroid Build Coastguard Worker
2020*35238bceSAndroid Build Coastguard Worker default:
2021*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
2022*35238bceSAndroid Build Coastguard Worker }
2023*35238bceSAndroid Build Coastguard Worker }
2024*35238bceSAndroid Build Coastguard Worker
mapGLAttachmentPoint(uint32_t attachment)2025*35238bceSAndroid Build Coastguard Worker static inline Framebuffer::AttachmentPoint mapGLAttachmentPoint(uint32_t attachment)
2026*35238bceSAndroid Build Coastguard Worker {
2027*35238bceSAndroid Build Coastguard Worker switch (attachment)
2028*35238bceSAndroid Build Coastguard Worker {
2029*35238bceSAndroid Build Coastguard Worker case GL_COLOR_ATTACHMENT0:
2030*35238bceSAndroid Build Coastguard Worker return Framebuffer::ATTACHMENTPOINT_COLOR0;
2031*35238bceSAndroid Build Coastguard Worker case GL_DEPTH_ATTACHMENT:
2032*35238bceSAndroid Build Coastguard Worker return Framebuffer::ATTACHMENTPOINT_DEPTH;
2033*35238bceSAndroid Build Coastguard Worker case GL_STENCIL_ATTACHMENT:
2034*35238bceSAndroid Build Coastguard Worker return Framebuffer::ATTACHMENTPOINT_STENCIL;
2035*35238bceSAndroid Build Coastguard Worker default:
2036*35238bceSAndroid Build Coastguard Worker return Framebuffer::ATTACHMENTPOINT_LAST;
2037*35238bceSAndroid Build Coastguard Worker }
2038*35238bceSAndroid Build Coastguard Worker }
2039*35238bceSAndroid Build Coastguard Worker
mapGLFboTexTarget(uint32_t target)2040*35238bceSAndroid Build Coastguard Worker static inline Framebuffer::TexTarget mapGLFboTexTarget(uint32_t target)
2041*35238bceSAndroid Build Coastguard Worker {
2042*35238bceSAndroid Build Coastguard Worker switch (target)
2043*35238bceSAndroid Build Coastguard Worker {
2044*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
2045*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_2D;
2046*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2047*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_X;
2048*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2049*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_Y;
2050*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2051*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_Z;
2052*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2053*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_X;
2054*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2055*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_Y;
2056*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
2057*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_Z;
2058*35238bceSAndroid Build Coastguard Worker default:
2059*35238bceSAndroid Build Coastguard Worker return Framebuffer::TEXTARGET_LAST;
2060*35238bceSAndroid Build Coastguard Worker }
2061*35238bceSAndroid Build Coastguard Worker }
2062*35238bceSAndroid Build Coastguard Worker
acquireFboAttachmentReference(const Framebuffer::Attachment & attachment)2063*35238bceSAndroid Build Coastguard Worker void ReferenceContext::acquireFboAttachmentReference(const Framebuffer::Attachment &attachment)
2064*35238bceSAndroid Build Coastguard Worker {
2065*35238bceSAndroid Build Coastguard Worker switch (attachment.type)
2066*35238bceSAndroid Build Coastguard Worker {
2067*35238bceSAndroid Build Coastguard Worker case Framebuffer::ATTACHMENTTYPE_TEXTURE:
2068*35238bceSAndroid Build Coastguard Worker {
2069*35238bceSAndroid Build Coastguard Worker TCU_CHECK(attachment.name != 0);
2070*35238bceSAndroid Build Coastguard Worker Texture *texture = m_textures.find(attachment.name);
2071*35238bceSAndroid Build Coastguard Worker TCU_CHECK(texture);
2072*35238bceSAndroid Build Coastguard Worker m_textures.acquireReference(texture);
2073*35238bceSAndroid Build Coastguard Worker break;
2074*35238bceSAndroid Build Coastguard Worker }
2075*35238bceSAndroid Build Coastguard Worker
2076*35238bceSAndroid Build Coastguard Worker case Framebuffer::ATTACHMENTTYPE_RENDERBUFFER:
2077*35238bceSAndroid Build Coastguard Worker {
2078*35238bceSAndroid Build Coastguard Worker TCU_CHECK(attachment.name != 0);
2079*35238bceSAndroid Build Coastguard Worker Renderbuffer *rbo = m_renderbuffers.find(attachment.name);
2080*35238bceSAndroid Build Coastguard Worker TCU_CHECK(rbo);
2081*35238bceSAndroid Build Coastguard Worker m_renderbuffers.acquireReference(rbo);
2082*35238bceSAndroid Build Coastguard Worker break;
2083*35238bceSAndroid Build Coastguard Worker }
2084*35238bceSAndroid Build Coastguard Worker
2085*35238bceSAndroid Build Coastguard Worker default:
2086*35238bceSAndroid Build Coastguard Worker break; // Silently ignore
2087*35238bceSAndroid Build Coastguard Worker }
2088*35238bceSAndroid Build Coastguard Worker }
2089*35238bceSAndroid Build Coastguard Worker
releaseFboAttachmentReference(const Framebuffer::Attachment & attachment)2090*35238bceSAndroid Build Coastguard Worker void ReferenceContext::releaseFboAttachmentReference(const Framebuffer::Attachment &attachment)
2091*35238bceSAndroid Build Coastguard Worker {
2092*35238bceSAndroid Build Coastguard Worker switch (attachment.type)
2093*35238bceSAndroid Build Coastguard Worker {
2094*35238bceSAndroid Build Coastguard Worker case Framebuffer::ATTACHMENTTYPE_TEXTURE:
2095*35238bceSAndroid Build Coastguard Worker {
2096*35238bceSAndroid Build Coastguard Worker TCU_CHECK(attachment.name != 0);
2097*35238bceSAndroid Build Coastguard Worker Texture *texture = m_textures.find(attachment.name);
2098*35238bceSAndroid Build Coastguard Worker TCU_CHECK(texture);
2099*35238bceSAndroid Build Coastguard Worker m_textures.releaseReference(texture);
2100*35238bceSAndroid Build Coastguard Worker break;
2101*35238bceSAndroid Build Coastguard Worker }
2102*35238bceSAndroid Build Coastguard Worker
2103*35238bceSAndroid Build Coastguard Worker case Framebuffer::ATTACHMENTTYPE_RENDERBUFFER:
2104*35238bceSAndroid Build Coastguard Worker {
2105*35238bceSAndroid Build Coastguard Worker TCU_CHECK(attachment.name != 0);
2106*35238bceSAndroid Build Coastguard Worker Renderbuffer *rbo = m_renderbuffers.find(attachment.name);
2107*35238bceSAndroid Build Coastguard Worker TCU_CHECK(rbo);
2108*35238bceSAndroid Build Coastguard Worker m_renderbuffers.releaseReference(rbo);
2109*35238bceSAndroid Build Coastguard Worker break;
2110*35238bceSAndroid Build Coastguard Worker }
2111*35238bceSAndroid Build Coastguard Worker
2112*35238bceSAndroid Build Coastguard Worker default:
2113*35238bceSAndroid Build Coastguard Worker break; // Silently ignore
2114*35238bceSAndroid Build Coastguard Worker }
2115*35238bceSAndroid Build Coastguard Worker }
2116*35238bceSAndroid Build Coastguard Worker
framebufferTexture2D(uint32_t target,uint32_t attachment,uint32_t textarget,uint32_t texture,int level)2117*35238bceSAndroid Build Coastguard Worker void ReferenceContext::framebufferTexture2D(uint32_t target, uint32_t attachment, uint32_t textarget, uint32_t texture,
2118*35238bceSAndroid Build Coastguard Worker int level)
2119*35238bceSAndroid Build Coastguard Worker {
2120*35238bceSAndroid Build Coastguard Worker if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
2121*35238bceSAndroid Build Coastguard Worker {
2122*35238bceSAndroid Build Coastguard Worker // Attach to both depth and stencil.
2123*35238bceSAndroid Build Coastguard Worker framebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget, texture, level);
2124*35238bceSAndroid Build Coastguard Worker framebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarget, texture, level);
2125*35238bceSAndroid Build Coastguard Worker }
2126*35238bceSAndroid Build Coastguard Worker else
2127*35238bceSAndroid Build Coastguard Worker {
2128*35238bceSAndroid Build Coastguard Worker Framebuffer::AttachmentPoint point = mapGLAttachmentPoint(attachment);
2129*35238bceSAndroid Build Coastguard Worker Texture *texObj = DE_NULL;
2130*35238bceSAndroid Build Coastguard Worker Framebuffer::TexTarget fboTexTarget = mapGLFboTexTarget(textarget);
2131*35238bceSAndroid Build Coastguard Worker
2132*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER,
2133*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
2134*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(point == Framebuffer::ATTACHMENTPOINT_LAST, GL_INVALID_ENUM, RC_RET_VOID);
2135*35238bceSAndroid Build Coastguard Worker
2136*35238bceSAndroid Build Coastguard Worker // Select binding point.
2137*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *framebufferBinding = (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER) ?
2138*35238bceSAndroid Build Coastguard Worker m_drawFramebufferBinding :
2139*35238bceSAndroid Build Coastguard Worker m_readFramebufferBinding;
2140*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!framebufferBinding, GL_INVALID_OPERATION, RC_RET_VOID);
2141*35238bceSAndroid Build Coastguard Worker
2142*35238bceSAndroid Build Coastguard Worker // If framebuffer object is bound for both reading and writing then we need to acquire/release multiple references.
2143*35238bceSAndroid Build Coastguard Worker int bindingRefCount = (framebufferBinding == m_drawFramebufferBinding ? 1 : 0) +
2144*35238bceSAndroid Build Coastguard Worker (framebufferBinding == m_readFramebufferBinding ? 1 : 0);
2145*35238bceSAndroid Build Coastguard Worker
2146*35238bceSAndroid Build Coastguard Worker if (texture != 0)
2147*35238bceSAndroid Build Coastguard Worker {
2148*35238bceSAndroid Build Coastguard Worker texObj = m_textures.find(texture);
2149*35238bceSAndroid Build Coastguard Worker
2150*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texObj, GL_INVALID_OPERATION, RC_RET_VOID);
2151*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level != 0, GL_INVALID_VALUE,
2152*35238bceSAndroid Build Coastguard Worker RC_RET_VOID); // \todo [2012-03-19 pyry] We should allow other levels as well.
2153*35238bceSAndroid Build Coastguard Worker
2154*35238bceSAndroid Build Coastguard Worker if (texObj->getType() == Texture::TYPE_2D)
2155*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(fboTexTarget != Framebuffer::TEXTARGET_2D, GL_INVALID_OPERATION, RC_RET_VOID);
2156*35238bceSAndroid Build Coastguard Worker else
2157*35238bceSAndroid Build Coastguard Worker {
2158*35238bceSAndroid Build Coastguard Worker TCU_CHECK(texObj->getType() == Texture::TYPE_CUBE_MAP);
2159*35238bceSAndroid Build Coastguard Worker if (!deInRange32(fboTexTarget, Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_X,
2160*35238bceSAndroid Build Coastguard Worker Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_Z))
2161*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_OPERATION, RC_RET_VOID);
2162*35238bceSAndroid Build Coastguard Worker }
2163*35238bceSAndroid Build Coastguard Worker }
2164*35238bceSAndroid Build Coastguard Worker
2165*35238bceSAndroid Build Coastguard Worker Framebuffer::Attachment &fboAttachment = framebufferBinding->getAttachment(point);
2166*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < bindingRefCount; ndx++)
2167*35238bceSAndroid Build Coastguard Worker releaseFboAttachmentReference(fboAttachment);
2168*35238bceSAndroid Build Coastguard Worker fboAttachment = Framebuffer::Attachment();
2169*35238bceSAndroid Build Coastguard Worker
2170*35238bceSAndroid Build Coastguard Worker if (texObj)
2171*35238bceSAndroid Build Coastguard Worker {
2172*35238bceSAndroid Build Coastguard Worker fboAttachment.type = Framebuffer::ATTACHMENTTYPE_TEXTURE;
2173*35238bceSAndroid Build Coastguard Worker fboAttachment.name = texObj->getName();
2174*35238bceSAndroid Build Coastguard Worker fboAttachment.texTarget = fboTexTarget;
2175*35238bceSAndroid Build Coastguard Worker fboAttachment.level = level;
2176*35238bceSAndroid Build Coastguard Worker
2177*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < bindingRefCount; ndx++)
2178*35238bceSAndroid Build Coastguard Worker acquireFboAttachmentReference(fboAttachment);
2179*35238bceSAndroid Build Coastguard Worker }
2180*35238bceSAndroid Build Coastguard Worker }
2181*35238bceSAndroid Build Coastguard Worker }
2182*35238bceSAndroid Build Coastguard Worker
framebufferTextureLayer(uint32_t target,uint32_t attachment,uint32_t texture,int level,int layer)2183*35238bceSAndroid Build Coastguard Worker void ReferenceContext::framebufferTextureLayer(uint32_t target, uint32_t attachment, uint32_t texture, int level,
2184*35238bceSAndroid Build Coastguard Worker int layer)
2185*35238bceSAndroid Build Coastguard Worker {
2186*35238bceSAndroid Build Coastguard Worker if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
2187*35238bceSAndroid Build Coastguard Worker {
2188*35238bceSAndroid Build Coastguard Worker // Attach to both depth and stencil.
2189*35238bceSAndroid Build Coastguard Worker framebufferTextureLayer(target, GL_DEPTH_ATTACHMENT, texture, level, layer);
2190*35238bceSAndroid Build Coastguard Worker framebufferTextureLayer(target, GL_STENCIL_ATTACHMENT, texture, level, layer);
2191*35238bceSAndroid Build Coastguard Worker }
2192*35238bceSAndroid Build Coastguard Worker else
2193*35238bceSAndroid Build Coastguard Worker {
2194*35238bceSAndroid Build Coastguard Worker Framebuffer::AttachmentPoint point = mapGLAttachmentPoint(attachment);
2195*35238bceSAndroid Build Coastguard Worker Texture *texObj = DE_NULL;
2196*35238bceSAndroid Build Coastguard Worker
2197*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER,
2198*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
2199*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(point == Framebuffer::ATTACHMENTPOINT_LAST, GL_INVALID_ENUM, RC_RET_VOID);
2200*35238bceSAndroid Build Coastguard Worker
2201*35238bceSAndroid Build Coastguard Worker // Select binding point.
2202*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *framebufferBinding = (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER) ?
2203*35238bceSAndroid Build Coastguard Worker m_drawFramebufferBinding :
2204*35238bceSAndroid Build Coastguard Worker m_readFramebufferBinding;
2205*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!framebufferBinding, GL_INVALID_OPERATION, RC_RET_VOID);
2206*35238bceSAndroid Build Coastguard Worker
2207*35238bceSAndroid Build Coastguard Worker // If framebuffer object is bound for both reading and writing then we need to acquire/release multiple references.
2208*35238bceSAndroid Build Coastguard Worker int bindingRefCount = (framebufferBinding == m_drawFramebufferBinding ? 1 : 0) +
2209*35238bceSAndroid Build Coastguard Worker (framebufferBinding == m_readFramebufferBinding ? 1 : 0);
2210*35238bceSAndroid Build Coastguard Worker
2211*35238bceSAndroid Build Coastguard Worker if (texture != 0)
2212*35238bceSAndroid Build Coastguard Worker {
2213*35238bceSAndroid Build Coastguard Worker texObj = m_textures.find(texture);
2214*35238bceSAndroid Build Coastguard Worker
2215*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!texObj, GL_INVALID_OPERATION, RC_RET_VOID);
2216*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(level != 0, GL_INVALID_VALUE,
2217*35238bceSAndroid Build Coastguard Worker RC_RET_VOID); // \todo [2012-03-19 pyry] We should allow other levels as well.
2218*35238bceSAndroid Build Coastguard Worker
2219*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(texObj->getType() != Texture::TYPE_2D_ARRAY && texObj->getType() != Texture::TYPE_3D &&
2220*35238bceSAndroid Build Coastguard Worker texObj->getType() != Texture::TYPE_CUBE_MAP_ARRAY,
2221*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
2222*35238bceSAndroid Build Coastguard Worker
2223*35238bceSAndroid Build Coastguard Worker if (texObj->getType() == Texture::TYPE_2D_ARRAY || texObj->getType() == Texture::TYPE_CUBE_MAP_ARRAY)
2224*35238bceSAndroid Build Coastguard Worker {
2225*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((layer < 0) || (layer >= GL_MAX_ARRAY_TEXTURE_LAYERS), GL_INVALID_VALUE, RC_RET_VOID);
2226*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((level < 0) || (level > deLog2Floor32(GL_MAX_TEXTURE_SIZE)), GL_INVALID_VALUE, RC_RET_VOID);
2227*35238bceSAndroid Build Coastguard Worker }
2228*35238bceSAndroid Build Coastguard Worker else if (texObj->getType() == Texture::TYPE_3D)
2229*35238bceSAndroid Build Coastguard Worker {
2230*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((layer < 0) || (layer >= GL_MAX_3D_TEXTURE_SIZE), GL_INVALID_VALUE, RC_RET_VOID);
2231*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((level < 0) || (level > deLog2Floor32(GL_MAX_3D_TEXTURE_SIZE)), GL_INVALID_VALUE,
2232*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
2233*35238bceSAndroid Build Coastguard Worker }
2234*35238bceSAndroid Build Coastguard Worker }
2235*35238bceSAndroid Build Coastguard Worker
2236*35238bceSAndroid Build Coastguard Worker Framebuffer::Attachment &fboAttachment = framebufferBinding->getAttachment(point);
2237*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < bindingRefCount; ndx++)
2238*35238bceSAndroid Build Coastguard Worker releaseFboAttachmentReference(fboAttachment);
2239*35238bceSAndroid Build Coastguard Worker fboAttachment = Framebuffer::Attachment();
2240*35238bceSAndroid Build Coastguard Worker
2241*35238bceSAndroid Build Coastguard Worker if (texObj)
2242*35238bceSAndroid Build Coastguard Worker {
2243*35238bceSAndroid Build Coastguard Worker fboAttachment.type = Framebuffer::ATTACHMENTTYPE_TEXTURE;
2244*35238bceSAndroid Build Coastguard Worker fboAttachment.name = texObj->getName();
2245*35238bceSAndroid Build Coastguard Worker fboAttachment.texTarget = texLayeredTypeToTarget(texObj->getType());
2246*35238bceSAndroid Build Coastguard Worker fboAttachment.level = level;
2247*35238bceSAndroid Build Coastguard Worker fboAttachment.layer = layer;
2248*35238bceSAndroid Build Coastguard Worker
2249*35238bceSAndroid Build Coastguard Worker DE_ASSERT(fboAttachment.texTarget != Framebuffer::TEXTARGET_LAST);
2250*35238bceSAndroid Build Coastguard Worker
2251*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < bindingRefCount; ndx++)
2252*35238bceSAndroid Build Coastguard Worker acquireFboAttachmentReference(fboAttachment);
2253*35238bceSAndroid Build Coastguard Worker }
2254*35238bceSAndroid Build Coastguard Worker }
2255*35238bceSAndroid Build Coastguard Worker }
2256*35238bceSAndroid Build Coastguard Worker
framebufferRenderbuffer(uint32_t target,uint32_t attachment,uint32_t renderbuffertarget,uint32_t renderbuffer)2257*35238bceSAndroid Build Coastguard Worker void ReferenceContext::framebufferRenderbuffer(uint32_t target, uint32_t attachment, uint32_t renderbuffertarget,
2258*35238bceSAndroid Build Coastguard Worker uint32_t renderbuffer)
2259*35238bceSAndroid Build Coastguard Worker {
2260*35238bceSAndroid Build Coastguard Worker if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
2261*35238bceSAndroid Build Coastguard Worker {
2262*35238bceSAndroid Build Coastguard Worker // Attach both to depth and stencil.
2263*35238bceSAndroid Build Coastguard Worker framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, renderbuffertarget, renderbuffer);
2264*35238bceSAndroid Build Coastguard Worker framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, renderbuffertarget, renderbuffer);
2265*35238bceSAndroid Build Coastguard Worker }
2266*35238bceSAndroid Build Coastguard Worker else
2267*35238bceSAndroid Build Coastguard Worker {
2268*35238bceSAndroid Build Coastguard Worker Framebuffer::AttachmentPoint point = mapGLAttachmentPoint(attachment);
2269*35238bceSAndroid Build Coastguard Worker Renderbuffer *rbo = DE_NULL;
2270*35238bceSAndroid Build Coastguard Worker
2271*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER,
2272*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
2273*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(point == Framebuffer::ATTACHMENTPOINT_LAST, GL_INVALID_ENUM, RC_RET_VOID);
2274*35238bceSAndroid Build Coastguard Worker
2275*35238bceSAndroid Build Coastguard Worker // Select binding point.
2276*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *framebufferBinding = (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER) ?
2277*35238bceSAndroid Build Coastguard Worker m_drawFramebufferBinding :
2278*35238bceSAndroid Build Coastguard Worker m_readFramebufferBinding;
2279*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!framebufferBinding, GL_INVALID_OPERATION, RC_RET_VOID);
2280*35238bceSAndroid Build Coastguard Worker
2281*35238bceSAndroid Build Coastguard Worker // If framebuffer object is bound for both reading and writing then we need to acquire/release multiple references.
2282*35238bceSAndroid Build Coastguard Worker int bindingRefCount = (framebufferBinding == m_drawFramebufferBinding ? 1 : 0) +
2283*35238bceSAndroid Build Coastguard Worker (framebufferBinding == m_readFramebufferBinding ? 1 : 0);
2284*35238bceSAndroid Build Coastguard Worker
2285*35238bceSAndroid Build Coastguard Worker if (renderbuffer != 0)
2286*35238bceSAndroid Build Coastguard Worker {
2287*35238bceSAndroid Build Coastguard Worker rbo = m_renderbuffers.find(renderbuffer);
2288*35238bceSAndroid Build Coastguard Worker
2289*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(renderbuffertarget != GL_RENDERBUFFER, GL_INVALID_ENUM, RC_RET_VOID);
2290*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!rbo, GL_INVALID_OPERATION, RC_RET_VOID);
2291*35238bceSAndroid Build Coastguard Worker }
2292*35238bceSAndroid Build Coastguard Worker
2293*35238bceSAndroid Build Coastguard Worker Framebuffer::Attachment &fboAttachment = framebufferBinding->getAttachment(point);
2294*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < bindingRefCount; ndx++)
2295*35238bceSAndroid Build Coastguard Worker releaseFboAttachmentReference(fboAttachment);
2296*35238bceSAndroid Build Coastguard Worker fboAttachment = Framebuffer::Attachment();
2297*35238bceSAndroid Build Coastguard Worker
2298*35238bceSAndroid Build Coastguard Worker if (rbo)
2299*35238bceSAndroid Build Coastguard Worker {
2300*35238bceSAndroid Build Coastguard Worker fboAttachment.type = Framebuffer::ATTACHMENTTYPE_RENDERBUFFER;
2301*35238bceSAndroid Build Coastguard Worker fboAttachment.name = rbo->getName();
2302*35238bceSAndroid Build Coastguard Worker
2303*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < bindingRefCount; ndx++)
2304*35238bceSAndroid Build Coastguard Worker acquireFboAttachmentReference(fboAttachment);
2305*35238bceSAndroid Build Coastguard Worker }
2306*35238bceSAndroid Build Coastguard Worker }
2307*35238bceSAndroid Build Coastguard Worker }
2308*35238bceSAndroid Build Coastguard Worker
checkFramebufferStatus(uint32_t target)2309*35238bceSAndroid Build Coastguard Worker uint32_t ReferenceContext::checkFramebufferStatus(uint32_t target)
2310*35238bceSAndroid Build Coastguard Worker {
2311*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER,
2312*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, 0);
2313*35238bceSAndroid Build Coastguard Worker
2314*35238bceSAndroid Build Coastguard Worker // Select binding point.
2315*35238bceSAndroid Build Coastguard Worker rc::Framebuffer *framebufferBinding = (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER) ?
2316*35238bceSAndroid Build Coastguard Worker m_drawFramebufferBinding :
2317*35238bceSAndroid Build Coastguard Worker m_readFramebufferBinding;
2318*35238bceSAndroid Build Coastguard Worker
2319*35238bceSAndroid Build Coastguard Worker // Default framebuffer is always complete.
2320*35238bceSAndroid Build Coastguard Worker if (!framebufferBinding)
2321*35238bceSAndroid Build Coastguard Worker return GL_FRAMEBUFFER_COMPLETE;
2322*35238bceSAndroid Build Coastguard Worker
2323*35238bceSAndroid Build Coastguard Worker int width = -1;
2324*35238bceSAndroid Build Coastguard Worker int height = -1;
2325*35238bceSAndroid Build Coastguard Worker bool hasAttachment = false;
2326*35238bceSAndroid Build Coastguard Worker bool attachmentComplete = true;
2327*35238bceSAndroid Build Coastguard Worker bool dimensionsOk = true;
2328*35238bceSAndroid Build Coastguard Worker
2329*35238bceSAndroid Build Coastguard Worker for (int point = 0; point < Framebuffer::ATTACHMENTPOINT_LAST; point++)
2330*35238bceSAndroid Build Coastguard Worker {
2331*35238bceSAndroid Build Coastguard Worker const Framebuffer::Attachment &attachment =
2332*35238bceSAndroid Build Coastguard Worker framebufferBinding->getAttachment((Framebuffer::AttachmentPoint)point);
2333*35238bceSAndroid Build Coastguard Worker int attachmentWidth = 0;
2334*35238bceSAndroid Build Coastguard Worker int attachmentHeight = 0;
2335*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat attachmentFormat;
2336*35238bceSAndroid Build Coastguard Worker
2337*35238bceSAndroid Build Coastguard Worker if (attachment.type == Framebuffer::ATTACHMENTTYPE_TEXTURE)
2338*35238bceSAndroid Build Coastguard Worker {
2339*35238bceSAndroid Build Coastguard Worker const Texture *texture = m_textures.find(attachment.name);
2340*35238bceSAndroid Build Coastguard Worker tcu::ConstPixelBufferAccess level;
2341*35238bceSAndroid Build Coastguard Worker TCU_CHECK(texture);
2342*35238bceSAndroid Build Coastguard Worker
2343*35238bceSAndroid Build Coastguard Worker if (attachment.texTarget == Framebuffer::TEXTARGET_2D)
2344*35238bceSAndroid Build Coastguard Worker {
2345*35238bceSAndroid Build Coastguard Worker DE_ASSERT(texture->getType() == Texture::TYPE_2D);
2346*35238bceSAndroid Build Coastguard Worker const Texture2D *tex2D = static_cast<const Texture2D *>(texture);
2347*35238bceSAndroid Build Coastguard Worker
2348*35238bceSAndroid Build Coastguard Worker if (tex2D->hasLevel(attachment.level))
2349*35238bceSAndroid Build Coastguard Worker level = tex2D->getLevel(attachment.level);
2350*35238bceSAndroid Build Coastguard Worker }
2351*35238bceSAndroid Build Coastguard Worker else if (deInRange32(attachment.texTarget, Framebuffer::TEXTARGET_CUBE_MAP_POSITIVE_X,
2352*35238bceSAndroid Build Coastguard Worker Framebuffer::TEXTARGET_CUBE_MAP_NEGATIVE_Z))
2353*35238bceSAndroid Build Coastguard Worker {
2354*35238bceSAndroid Build Coastguard Worker DE_ASSERT(texture->getType() == Texture::TYPE_CUBE_MAP);
2355*35238bceSAndroid Build Coastguard Worker
2356*35238bceSAndroid Build Coastguard Worker const TextureCube *texCube = static_cast<const TextureCube *>(texture);
2357*35238bceSAndroid Build Coastguard Worker const tcu::CubeFace face = texTargetToFace(attachment.texTarget);
2358*35238bceSAndroid Build Coastguard Worker TCU_CHECK(de::inBounds<int>(face, 0, tcu::CUBEFACE_LAST));
2359*35238bceSAndroid Build Coastguard Worker
2360*35238bceSAndroid Build Coastguard Worker if (texCube->hasFace(attachment.level, face))
2361*35238bceSAndroid Build Coastguard Worker level = texCube->getFace(attachment.level, face);
2362*35238bceSAndroid Build Coastguard Worker }
2363*35238bceSAndroid Build Coastguard Worker else if (attachment.texTarget == Framebuffer::TEXTARGET_2D_ARRAY)
2364*35238bceSAndroid Build Coastguard Worker {
2365*35238bceSAndroid Build Coastguard Worker DE_ASSERT(texture->getType() == Texture::TYPE_2D_ARRAY);
2366*35238bceSAndroid Build Coastguard Worker const Texture2DArray *tex2DArr = static_cast<const Texture2DArray *>(texture);
2367*35238bceSAndroid Build Coastguard Worker
2368*35238bceSAndroid Build Coastguard Worker if (tex2DArr->hasLevel(attachment.level))
2369*35238bceSAndroid Build Coastguard Worker level = tex2DArr->getLevel(attachment.level); // \note Slice doesn't matter here.
2370*35238bceSAndroid Build Coastguard Worker }
2371*35238bceSAndroid Build Coastguard Worker else if (attachment.texTarget == Framebuffer::TEXTARGET_3D)
2372*35238bceSAndroid Build Coastguard Worker {
2373*35238bceSAndroid Build Coastguard Worker DE_ASSERT(texture->getType() == Texture::TYPE_3D);
2374*35238bceSAndroid Build Coastguard Worker const Texture3D *tex3D = static_cast<const Texture3D *>(texture);
2375*35238bceSAndroid Build Coastguard Worker
2376*35238bceSAndroid Build Coastguard Worker if (tex3D->hasLevel(attachment.level))
2377*35238bceSAndroid Build Coastguard Worker level = tex3D->getLevel(attachment.level); // \note Slice doesn't matter here.
2378*35238bceSAndroid Build Coastguard Worker }
2379*35238bceSAndroid Build Coastguard Worker else if (attachment.texTarget == Framebuffer::TEXTARGET_CUBE_MAP_ARRAY)
2380*35238bceSAndroid Build Coastguard Worker {
2381*35238bceSAndroid Build Coastguard Worker DE_ASSERT(texture->getType() == Texture::TYPE_CUBE_MAP_ARRAY);
2382*35238bceSAndroid Build Coastguard Worker const TextureCubeArray *texCubeArr = static_cast<const TextureCubeArray *>(texture);
2383*35238bceSAndroid Build Coastguard Worker
2384*35238bceSAndroid Build Coastguard Worker if (texCubeArr->hasLevel(attachment.level))
2385*35238bceSAndroid Build Coastguard Worker level = texCubeArr->getLevel(attachment.level); // \note Slice doesn't matter here.
2386*35238bceSAndroid Build Coastguard Worker }
2387*35238bceSAndroid Build Coastguard Worker else
2388*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Framebuffer attached to a texture but no valid target specified");
2389*35238bceSAndroid Build Coastguard Worker
2390*35238bceSAndroid Build Coastguard Worker attachmentWidth = level.getWidth();
2391*35238bceSAndroid Build Coastguard Worker attachmentHeight = level.getHeight();
2392*35238bceSAndroid Build Coastguard Worker attachmentFormat = level.getFormat();
2393*35238bceSAndroid Build Coastguard Worker }
2394*35238bceSAndroid Build Coastguard Worker else if (attachment.type == Framebuffer::ATTACHMENTTYPE_RENDERBUFFER)
2395*35238bceSAndroid Build Coastguard Worker {
2396*35238bceSAndroid Build Coastguard Worker const Renderbuffer *renderbuffer = m_renderbuffers.find(attachment.name);
2397*35238bceSAndroid Build Coastguard Worker TCU_CHECK(renderbuffer);
2398*35238bceSAndroid Build Coastguard Worker
2399*35238bceSAndroid Build Coastguard Worker attachmentWidth = renderbuffer->getWidth();
2400*35238bceSAndroid Build Coastguard Worker attachmentHeight = renderbuffer->getHeight();
2401*35238bceSAndroid Build Coastguard Worker attachmentFormat = renderbuffer->getFormat();
2402*35238bceSAndroid Build Coastguard Worker }
2403*35238bceSAndroid Build Coastguard Worker else
2404*35238bceSAndroid Build Coastguard Worker {
2405*35238bceSAndroid Build Coastguard Worker TCU_CHECK(attachment.type == Framebuffer::ATTACHMENTTYPE_LAST);
2406*35238bceSAndroid Build Coastguard Worker continue; // Skip rest of checks.
2407*35238bceSAndroid Build Coastguard Worker }
2408*35238bceSAndroid Build Coastguard Worker
2409*35238bceSAndroid Build Coastguard Worker if (!hasAttachment && attachmentWidth > 0 && attachmentHeight > 0)
2410*35238bceSAndroid Build Coastguard Worker {
2411*35238bceSAndroid Build Coastguard Worker width = attachmentWidth;
2412*35238bceSAndroid Build Coastguard Worker height = attachmentHeight;
2413*35238bceSAndroid Build Coastguard Worker hasAttachment = true;
2414*35238bceSAndroid Build Coastguard Worker }
2415*35238bceSAndroid Build Coastguard Worker else if (attachmentWidth != width || attachmentHeight != height)
2416*35238bceSAndroid Build Coastguard Worker dimensionsOk = false;
2417*35238bceSAndroid Build Coastguard Worker
2418*35238bceSAndroid Build Coastguard Worker // Validate attachment point compatibility.
2419*35238bceSAndroid Build Coastguard Worker switch (attachmentFormat.order)
2420*35238bceSAndroid Build Coastguard Worker {
2421*35238bceSAndroid Build Coastguard Worker case TextureFormat::R:
2422*35238bceSAndroid Build Coastguard Worker case TextureFormat::RG:
2423*35238bceSAndroid Build Coastguard Worker case TextureFormat::RGB:
2424*35238bceSAndroid Build Coastguard Worker case TextureFormat::RGBA:
2425*35238bceSAndroid Build Coastguard Worker case TextureFormat::sRGB:
2426*35238bceSAndroid Build Coastguard Worker case TextureFormat::sRGBA:
2427*35238bceSAndroid Build Coastguard Worker if (point != Framebuffer::ATTACHMENTPOINT_COLOR0)
2428*35238bceSAndroid Build Coastguard Worker attachmentComplete = false;
2429*35238bceSAndroid Build Coastguard Worker break;
2430*35238bceSAndroid Build Coastguard Worker
2431*35238bceSAndroid Build Coastguard Worker case TextureFormat::D:
2432*35238bceSAndroid Build Coastguard Worker if (point != Framebuffer::ATTACHMENTPOINT_DEPTH)
2433*35238bceSAndroid Build Coastguard Worker attachmentComplete = false;
2434*35238bceSAndroid Build Coastguard Worker break;
2435*35238bceSAndroid Build Coastguard Worker
2436*35238bceSAndroid Build Coastguard Worker case TextureFormat::S:
2437*35238bceSAndroid Build Coastguard Worker if (point != Framebuffer::ATTACHMENTPOINT_STENCIL)
2438*35238bceSAndroid Build Coastguard Worker attachmentComplete = false;
2439*35238bceSAndroid Build Coastguard Worker break;
2440*35238bceSAndroid Build Coastguard Worker
2441*35238bceSAndroid Build Coastguard Worker case TextureFormat::DS:
2442*35238bceSAndroid Build Coastguard Worker if (point != Framebuffer::ATTACHMENTPOINT_DEPTH && point != Framebuffer::ATTACHMENTPOINT_STENCIL)
2443*35238bceSAndroid Build Coastguard Worker attachmentComplete = false;
2444*35238bceSAndroid Build Coastguard Worker break;
2445*35238bceSAndroid Build Coastguard Worker
2446*35238bceSAndroid Build Coastguard Worker default:
2447*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Unsupported attachment channel order");
2448*35238bceSAndroid Build Coastguard Worker }
2449*35238bceSAndroid Build Coastguard Worker }
2450*35238bceSAndroid Build Coastguard Worker
2451*35238bceSAndroid Build Coastguard Worker if (!attachmentComplete)
2452*35238bceSAndroid Build Coastguard Worker return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
2453*35238bceSAndroid Build Coastguard Worker else if (!hasAttachment)
2454*35238bceSAndroid Build Coastguard Worker return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
2455*35238bceSAndroid Build Coastguard Worker else if (!dimensionsOk)
2456*35238bceSAndroid Build Coastguard Worker return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
2457*35238bceSAndroid Build Coastguard Worker else
2458*35238bceSAndroid Build Coastguard Worker return GL_FRAMEBUFFER_COMPLETE;
2459*35238bceSAndroid Build Coastguard Worker }
2460*35238bceSAndroid Build Coastguard Worker
getFramebufferAttachmentParameteriv(uint32_t target,uint32_t attachment,uint32_t pname,int * params)2461*35238bceSAndroid Build Coastguard Worker void ReferenceContext::getFramebufferAttachmentParameteriv(uint32_t target, uint32_t attachment, uint32_t pname,
2462*35238bceSAndroid Build Coastguard Worker int *params)
2463*35238bceSAndroid Build Coastguard Worker {
2464*35238bceSAndroid Build Coastguard Worker DE_UNREF(target && attachment && pname && params);
2465*35238bceSAndroid Build Coastguard Worker TCU_CHECK(false); // \todo [pyry] Implement
2466*35238bceSAndroid Build Coastguard Worker }
2467*35238bceSAndroid Build Coastguard Worker
renderbufferStorage(uint32_t target,uint32_t internalformat,int width,int height)2468*35238bceSAndroid Build Coastguard Worker void ReferenceContext::renderbufferStorage(uint32_t target, uint32_t internalformat, int width, int height)
2469*35238bceSAndroid Build Coastguard Worker {
2470*35238bceSAndroid Build Coastguard Worker TextureFormat format = glu::mapGLInternalFormat(internalformat);
2471*35238bceSAndroid Build Coastguard Worker
2472*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_RENDERBUFFER, GL_INVALID_ENUM, RC_RET_VOID);
2473*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!m_renderbufferBinding, GL_INVALID_OPERATION, RC_RET_VOID);
2474*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!deInRange32(width, 0, m_limits.maxRenderbufferSize) ||
2475*35238bceSAndroid Build Coastguard Worker !deInRange32(height, 0, m_limits.maxRenderbufferSize),
2476*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
2477*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(format.order == TextureFormat::CHANNELORDER_LAST || format.type == TextureFormat::CHANNELTYPE_LAST,
2478*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
2479*35238bceSAndroid Build Coastguard Worker
2480*35238bceSAndroid Build Coastguard Worker m_renderbufferBinding->setStorage(format, (int)width, (int)height);
2481*35238bceSAndroid Build Coastguard Worker }
2482*35238bceSAndroid Build Coastguard Worker
renderbufferStorageMultisample(uint32_t target,int samples,uint32_t internalFormat,int width,int height)2483*35238bceSAndroid Build Coastguard Worker void ReferenceContext::renderbufferStorageMultisample(uint32_t target, int samples, uint32_t internalFormat, int width,
2484*35238bceSAndroid Build Coastguard Worker int height)
2485*35238bceSAndroid Build Coastguard Worker {
2486*35238bceSAndroid Build Coastguard Worker // \todo [2012-04-07 pyry] Implement MSAA support.
2487*35238bceSAndroid Build Coastguard Worker DE_UNREF(samples);
2488*35238bceSAndroid Build Coastguard Worker renderbufferStorage(target, internalFormat, width, height);
2489*35238bceSAndroid Build Coastguard Worker }
2490*35238bceSAndroid Build Coastguard Worker
getFboAttachment(const rc::Framebuffer & framebuffer,rc::Framebuffer::AttachmentPoint point)2491*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess ReferenceContext::getFboAttachment(const rc::Framebuffer &framebuffer,
2492*35238bceSAndroid Build Coastguard Worker rc::Framebuffer::AttachmentPoint point)
2493*35238bceSAndroid Build Coastguard Worker {
2494*35238bceSAndroid Build Coastguard Worker const Framebuffer::Attachment &attachment = framebuffer.getAttachment(point);
2495*35238bceSAndroid Build Coastguard Worker
2496*35238bceSAndroid Build Coastguard Worker switch (attachment.type)
2497*35238bceSAndroid Build Coastguard Worker {
2498*35238bceSAndroid Build Coastguard Worker case Framebuffer::ATTACHMENTTYPE_TEXTURE:
2499*35238bceSAndroid Build Coastguard Worker {
2500*35238bceSAndroid Build Coastguard Worker Texture *texture = m_textures.find(attachment.name);
2501*35238bceSAndroid Build Coastguard Worker TCU_CHECK(texture);
2502*35238bceSAndroid Build Coastguard Worker
2503*35238bceSAndroid Build Coastguard Worker if (texture->getType() == Texture::TYPE_2D)
2504*35238bceSAndroid Build Coastguard Worker {
2505*35238bceSAndroid Build Coastguard Worker if (Texture2D *texture2D = dynamic_cast<Texture2D *>(texture))
2506*35238bceSAndroid Build Coastguard Worker return texture2D->getLevel(attachment.level);
2507*35238bceSAndroid Build Coastguard Worker else
2508*35238bceSAndroid Build Coastguard Worker return nullAccess();
2509*35238bceSAndroid Build Coastguard Worker }
2510*35238bceSAndroid Build Coastguard Worker else if (texture->getType() == Texture::TYPE_CUBE_MAP)
2511*35238bceSAndroid Build Coastguard Worker {
2512*35238bceSAndroid Build Coastguard Worker if (TextureCube *cubeMap = dynamic_cast<TextureCube *>(texture))
2513*35238bceSAndroid Build Coastguard Worker return cubeMap->getFace(attachment.level, texTargetToFace(attachment.texTarget));
2514*35238bceSAndroid Build Coastguard Worker else
2515*35238bceSAndroid Build Coastguard Worker return nullAccess();
2516*35238bceSAndroid Build Coastguard Worker }
2517*35238bceSAndroid Build Coastguard Worker else if (texture->getType() == Texture::TYPE_2D_ARRAY || texture->getType() == Texture::TYPE_3D ||
2518*35238bceSAndroid Build Coastguard Worker texture->getType() == Texture::TYPE_CUBE_MAP_ARRAY)
2519*35238bceSAndroid Build Coastguard Worker {
2520*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess level;
2521*35238bceSAndroid Build Coastguard Worker
2522*35238bceSAndroid Build Coastguard Worker if (texture->getType() == Texture::TYPE_2D_ARRAY)
2523*35238bceSAndroid Build Coastguard Worker {
2524*35238bceSAndroid Build Coastguard Worker if (Texture2DArray *texture2DArray = dynamic_cast<Texture2DArray *>(texture))
2525*35238bceSAndroid Build Coastguard Worker level = texture2DArray->getLevel(attachment.level);
2526*35238bceSAndroid Build Coastguard Worker }
2527*35238bceSAndroid Build Coastguard Worker else if (texture->getType() == Texture::TYPE_3D)
2528*35238bceSAndroid Build Coastguard Worker {
2529*35238bceSAndroid Build Coastguard Worker if (Texture3D *texture3D = dynamic_cast<Texture3D *>(texture))
2530*35238bceSAndroid Build Coastguard Worker level = texture3D->getLevel(attachment.level);
2531*35238bceSAndroid Build Coastguard Worker }
2532*35238bceSAndroid Build Coastguard Worker else if (texture->getType() == Texture::TYPE_CUBE_MAP_ARRAY)
2533*35238bceSAndroid Build Coastguard Worker {
2534*35238bceSAndroid Build Coastguard Worker if (TextureCubeArray *cubeArray = dynamic_cast<TextureCubeArray *>(texture))
2535*35238bceSAndroid Build Coastguard Worker level = cubeArray->getLevel(attachment.level);
2536*35238bceSAndroid Build Coastguard Worker }
2537*35238bceSAndroid Build Coastguard Worker
2538*35238bceSAndroid Build Coastguard Worker void *layerData = static_cast<uint8_t *>(level.getDataPtr()) + level.getSlicePitch() * attachment.layer;
2539*35238bceSAndroid Build Coastguard Worker
2540*35238bceSAndroid Build Coastguard Worker return tcu::PixelBufferAccess(level.getFormat(), level.getWidth(), level.getHeight(), 1,
2541*35238bceSAndroid Build Coastguard Worker level.getRowPitch(), 0, layerData);
2542*35238bceSAndroid Build Coastguard Worker }
2543*35238bceSAndroid Build Coastguard Worker else
2544*35238bceSAndroid Build Coastguard Worker return nullAccess();
2545*35238bceSAndroid Build Coastguard Worker }
2546*35238bceSAndroid Build Coastguard Worker
2547*35238bceSAndroid Build Coastguard Worker case Framebuffer::ATTACHMENTTYPE_RENDERBUFFER:
2548*35238bceSAndroid Build Coastguard Worker {
2549*35238bceSAndroid Build Coastguard Worker Renderbuffer *rbo = m_renderbuffers.find(attachment.name);
2550*35238bceSAndroid Build Coastguard Worker TCU_CHECK(rbo);
2551*35238bceSAndroid Build Coastguard Worker
2552*35238bceSAndroid Build Coastguard Worker return rbo->getAccess();
2553*35238bceSAndroid Build Coastguard Worker }
2554*35238bceSAndroid Build Coastguard Worker
2555*35238bceSAndroid Build Coastguard Worker default:
2556*35238bceSAndroid Build Coastguard Worker return nullAccess();
2557*35238bceSAndroid Build Coastguard Worker }
2558*35238bceSAndroid Build Coastguard Worker }
2559*35238bceSAndroid Build Coastguard Worker
getTexture2D(int unitNdx) const2560*35238bceSAndroid Build Coastguard Worker const Texture2D &ReferenceContext::getTexture2D(int unitNdx) const
2561*35238bceSAndroid Build Coastguard Worker {
2562*35238bceSAndroid Build Coastguard Worker const TextureUnit &unit = m_textureUnits[unitNdx];
2563*35238bceSAndroid Build Coastguard Worker return unit.tex2DBinding ? *unit.tex2DBinding : unit.default2DTex;
2564*35238bceSAndroid Build Coastguard Worker }
2565*35238bceSAndroid Build Coastguard Worker
getTextureCube(int unitNdx) const2566*35238bceSAndroid Build Coastguard Worker const TextureCube &ReferenceContext::getTextureCube(int unitNdx) const
2567*35238bceSAndroid Build Coastguard Worker {
2568*35238bceSAndroid Build Coastguard Worker const TextureUnit &unit = m_textureUnits[unitNdx];
2569*35238bceSAndroid Build Coastguard Worker return unit.texCubeBinding ? *unit.texCubeBinding : unit.defaultCubeTex;
2570*35238bceSAndroid Build Coastguard Worker }
2571*35238bceSAndroid Build Coastguard Worker
isValidBufferTarget(uint32_t target)2572*35238bceSAndroid Build Coastguard Worker static bool isValidBufferTarget(uint32_t target)
2573*35238bceSAndroid Build Coastguard Worker {
2574*35238bceSAndroid Build Coastguard Worker switch (target)
2575*35238bceSAndroid Build Coastguard Worker {
2576*35238bceSAndroid Build Coastguard Worker case GL_ARRAY_BUFFER:
2577*35238bceSAndroid Build Coastguard Worker case GL_COPY_READ_BUFFER:
2578*35238bceSAndroid Build Coastguard Worker case GL_COPY_WRITE_BUFFER:
2579*35238bceSAndroid Build Coastguard Worker case GL_DRAW_INDIRECT_BUFFER:
2580*35238bceSAndroid Build Coastguard Worker case GL_ELEMENT_ARRAY_BUFFER:
2581*35238bceSAndroid Build Coastguard Worker case GL_PIXEL_PACK_BUFFER:
2582*35238bceSAndroid Build Coastguard Worker case GL_PIXEL_UNPACK_BUFFER:
2583*35238bceSAndroid Build Coastguard Worker case GL_TRANSFORM_FEEDBACK_BUFFER:
2584*35238bceSAndroid Build Coastguard Worker case GL_UNIFORM_BUFFER:
2585*35238bceSAndroid Build Coastguard Worker return true;
2586*35238bceSAndroid Build Coastguard Worker
2587*35238bceSAndroid Build Coastguard Worker default:
2588*35238bceSAndroid Build Coastguard Worker return false;
2589*35238bceSAndroid Build Coastguard Worker }
2590*35238bceSAndroid Build Coastguard Worker }
2591*35238bceSAndroid Build Coastguard Worker
setBufferBinding(uint32_t target,DataBuffer * buffer)2592*35238bceSAndroid Build Coastguard Worker void ReferenceContext::setBufferBinding(uint32_t target, DataBuffer *buffer)
2593*35238bceSAndroid Build Coastguard Worker {
2594*35238bceSAndroid Build Coastguard Worker DataBuffer **bindingPoint = DE_NULL;
2595*35238bceSAndroid Build Coastguard Worker VertexArray *vertexArrayObject = (m_vertexArrayBinding) ? (m_vertexArrayBinding) : (&m_clientVertexArray);
2596*35238bceSAndroid Build Coastguard Worker
2597*35238bceSAndroid Build Coastguard Worker switch (target)
2598*35238bceSAndroid Build Coastguard Worker {
2599*35238bceSAndroid Build Coastguard Worker case GL_ARRAY_BUFFER:
2600*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_arrayBufferBinding;
2601*35238bceSAndroid Build Coastguard Worker break;
2602*35238bceSAndroid Build Coastguard Worker case GL_COPY_READ_BUFFER:
2603*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_copyReadBufferBinding;
2604*35238bceSAndroid Build Coastguard Worker break;
2605*35238bceSAndroid Build Coastguard Worker case GL_COPY_WRITE_BUFFER:
2606*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_copyWriteBufferBinding;
2607*35238bceSAndroid Build Coastguard Worker break;
2608*35238bceSAndroid Build Coastguard Worker case GL_DRAW_INDIRECT_BUFFER:
2609*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_drawIndirectBufferBinding;
2610*35238bceSAndroid Build Coastguard Worker break;
2611*35238bceSAndroid Build Coastguard Worker case GL_ELEMENT_ARRAY_BUFFER:
2612*35238bceSAndroid Build Coastguard Worker bindingPoint = &vertexArrayObject->m_elementArrayBufferBinding;
2613*35238bceSAndroid Build Coastguard Worker break;
2614*35238bceSAndroid Build Coastguard Worker case GL_PIXEL_PACK_BUFFER:
2615*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_pixelPackBufferBinding;
2616*35238bceSAndroid Build Coastguard Worker break;
2617*35238bceSAndroid Build Coastguard Worker case GL_PIXEL_UNPACK_BUFFER:
2618*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_pixelUnpackBufferBinding;
2619*35238bceSAndroid Build Coastguard Worker break;
2620*35238bceSAndroid Build Coastguard Worker case GL_TRANSFORM_FEEDBACK_BUFFER:
2621*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_transformFeedbackBufferBinding;
2622*35238bceSAndroid Build Coastguard Worker break;
2623*35238bceSAndroid Build Coastguard Worker case GL_UNIFORM_BUFFER:
2624*35238bceSAndroid Build Coastguard Worker bindingPoint = &m_uniformBufferBinding;
2625*35238bceSAndroid Build Coastguard Worker break;
2626*35238bceSAndroid Build Coastguard Worker default:
2627*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2628*35238bceSAndroid Build Coastguard Worker return;
2629*35238bceSAndroid Build Coastguard Worker }
2630*35238bceSAndroid Build Coastguard Worker
2631*35238bceSAndroid Build Coastguard Worker if (*bindingPoint)
2632*35238bceSAndroid Build Coastguard Worker {
2633*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(*bindingPoint);
2634*35238bceSAndroid Build Coastguard Worker *bindingPoint = DE_NULL;
2635*35238bceSAndroid Build Coastguard Worker }
2636*35238bceSAndroid Build Coastguard Worker
2637*35238bceSAndroid Build Coastguard Worker if (buffer)
2638*35238bceSAndroid Build Coastguard Worker m_buffers.acquireReference(buffer);
2639*35238bceSAndroid Build Coastguard Worker
2640*35238bceSAndroid Build Coastguard Worker *bindingPoint = buffer;
2641*35238bceSAndroid Build Coastguard Worker }
2642*35238bceSAndroid Build Coastguard Worker
getBufferBinding(uint32_t target) const2643*35238bceSAndroid Build Coastguard Worker DataBuffer *ReferenceContext::getBufferBinding(uint32_t target) const
2644*35238bceSAndroid Build Coastguard Worker {
2645*35238bceSAndroid Build Coastguard Worker const VertexArray *vertexArrayObject = (m_vertexArrayBinding) ? (m_vertexArrayBinding) : (&m_clientVertexArray);
2646*35238bceSAndroid Build Coastguard Worker
2647*35238bceSAndroid Build Coastguard Worker switch (target)
2648*35238bceSAndroid Build Coastguard Worker {
2649*35238bceSAndroid Build Coastguard Worker case GL_ARRAY_BUFFER:
2650*35238bceSAndroid Build Coastguard Worker return m_arrayBufferBinding;
2651*35238bceSAndroid Build Coastguard Worker case GL_COPY_READ_BUFFER:
2652*35238bceSAndroid Build Coastguard Worker return m_copyReadBufferBinding;
2653*35238bceSAndroid Build Coastguard Worker case GL_COPY_WRITE_BUFFER:
2654*35238bceSAndroid Build Coastguard Worker return m_copyWriteBufferBinding;
2655*35238bceSAndroid Build Coastguard Worker case GL_DRAW_INDIRECT_BUFFER:
2656*35238bceSAndroid Build Coastguard Worker return m_drawIndirectBufferBinding;
2657*35238bceSAndroid Build Coastguard Worker case GL_ELEMENT_ARRAY_BUFFER:
2658*35238bceSAndroid Build Coastguard Worker return vertexArrayObject->m_elementArrayBufferBinding;
2659*35238bceSAndroid Build Coastguard Worker case GL_PIXEL_PACK_BUFFER:
2660*35238bceSAndroid Build Coastguard Worker return m_pixelPackBufferBinding;
2661*35238bceSAndroid Build Coastguard Worker case GL_PIXEL_UNPACK_BUFFER:
2662*35238bceSAndroid Build Coastguard Worker return m_pixelUnpackBufferBinding;
2663*35238bceSAndroid Build Coastguard Worker case GL_TRANSFORM_FEEDBACK_BUFFER:
2664*35238bceSAndroid Build Coastguard Worker return m_transformFeedbackBufferBinding;
2665*35238bceSAndroid Build Coastguard Worker case GL_UNIFORM_BUFFER:
2666*35238bceSAndroid Build Coastguard Worker return m_uniformBufferBinding;
2667*35238bceSAndroid Build Coastguard Worker default:
2668*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2669*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2670*35238bceSAndroid Build Coastguard Worker }
2671*35238bceSAndroid Build Coastguard Worker }
2672*35238bceSAndroid Build Coastguard Worker
bindBuffer(uint32_t target,uint32_t buffer)2673*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bindBuffer(uint32_t target, uint32_t buffer)
2674*35238bceSAndroid Build Coastguard Worker {
2675*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBufferTarget(target), GL_INVALID_ENUM, RC_RET_VOID);
2676*35238bceSAndroid Build Coastguard Worker
2677*35238bceSAndroid Build Coastguard Worker rc::DataBuffer *bufObj = DE_NULL;
2678*35238bceSAndroid Build Coastguard Worker
2679*35238bceSAndroid Build Coastguard Worker if (buffer != 0)
2680*35238bceSAndroid Build Coastguard Worker {
2681*35238bceSAndroid Build Coastguard Worker bufObj = m_buffers.find(buffer);
2682*35238bceSAndroid Build Coastguard Worker if (!bufObj)
2683*35238bceSAndroid Build Coastguard Worker {
2684*35238bceSAndroid Build Coastguard Worker bufObj = new DataBuffer(buffer);
2685*35238bceSAndroid Build Coastguard Worker m_buffers.insert(bufObj);
2686*35238bceSAndroid Build Coastguard Worker }
2687*35238bceSAndroid Build Coastguard Worker }
2688*35238bceSAndroid Build Coastguard Worker
2689*35238bceSAndroid Build Coastguard Worker setBufferBinding(target, bufObj);
2690*35238bceSAndroid Build Coastguard Worker }
2691*35238bceSAndroid Build Coastguard Worker
genBuffers(int numBuffers,uint32_t * buffers)2692*35238bceSAndroid Build Coastguard Worker void ReferenceContext::genBuffers(int numBuffers, uint32_t *buffers)
2693*35238bceSAndroid Build Coastguard Worker {
2694*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!buffers, GL_INVALID_VALUE, RC_RET_VOID);
2695*35238bceSAndroid Build Coastguard Worker
2696*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numBuffers; ndx++)
2697*35238bceSAndroid Build Coastguard Worker buffers[ndx] = m_buffers.allocateName();
2698*35238bceSAndroid Build Coastguard Worker }
2699*35238bceSAndroid Build Coastguard Worker
deleteBuffers(int numBuffers,const uint32_t * buffers)2700*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteBuffers(int numBuffers, const uint32_t *buffers)
2701*35238bceSAndroid Build Coastguard Worker {
2702*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(numBuffers < 0, GL_INVALID_VALUE, RC_RET_VOID);
2703*35238bceSAndroid Build Coastguard Worker
2704*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numBuffers; ndx++)
2705*35238bceSAndroid Build Coastguard Worker {
2706*35238bceSAndroid Build Coastguard Worker uint32_t buffer = buffers[ndx];
2707*35238bceSAndroid Build Coastguard Worker DataBuffer *bufObj = DE_NULL;
2708*35238bceSAndroid Build Coastguard Worker
2709*35238bceSAndroid Build Coastguard Worker if (buffer == 0)
2710*35238bceSAndroid Build Coastguard Worker continue;
2711*35238bceSAndroid Build Coastguard Worker
2712*35238bceSAndroid Build Coastguard Worker bufObj = m_buffers.find(buffer);
2713*35238bceSAndroid Build Coastguard Worker
2714*35238bceSAndroid Build Coastguard Worker if (bufObj)
2715*35238bceSAndroid Build Coastguard Worker deleteBuffer(bufObj);
2716*35238bceSAndroid Build Coastguard Worker }
2717*35238bceSAndroid Build Coastguard Worker }
2718*35238bceSAndroid Build Coastguard Worker
deleteBuffer(DataBuffer * buffer)2719*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteBuffer(DataBuffer *buffer)
2720*35238bceSAndroid Build Coastguard Worker {
2721*35238bceSAndroid Build Coastguard Worker static const uint32_t bindingPoints[] = {
2722*35238bceSAndroid Build Coastguard Worker GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
2723*35238bceSAndroid Build Coastguard Worker GL_DRAW_INDIRECT_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER,
2724*35238bceSAndroid Build Coastguard Worker GL_PIXEL_UNPACK_BUFFER, GL_TRANSFORM_FEEDBACK_BUFFER, GL_UNIFORM_BUFFER};
2725*35238bceSAndroid Build Coastguard Worker
2726*35238bceSAndroid Build Coastguard Worker for (int bindingNdx = 0; bindingNdx < DE_LENGTH_OF_ARRAY(bindingPoints); bindingNdx++)
2727*35238bceSAndroid Build Coastguard Worker {
2728*35238bceSAndroid Build Coastguard Worker if (getBufferBinding(bindingPoints[bindingNdx]) == buffer)
2729*35238bceSAndroid Build Coastguard Worker setBufferBinding(bindingPoints[bindingNdx], DE_NULL);
2730*35238bceSAndroid Build Coastguard Worker }
2731*35238bceSAndroid Build Coastguard Worker
2732*35238bceSAndroid Build Coastguard Worker {
2733*35238bceSAndroid Build Coastguard Worker vector<VertexArray *> vertexArrays;
2734*35238bceSAndroid Build Coastguard Worker m_vertexArrays.getAll(vertexArrays);
2735*35238bceSAndroid Build Coastguard Worker vertexArrays.push_back(&m_clientVertexArray);
2736*35238bceSAndroid Build Coastguard Worker
2737*35238bceSAndroid Build Coastguard Worker for (vector<VertexArray *>::iterator i = vertexArrays.begin(); i != vertexArrays.end(); i++)
2738*35238bceSAndroid Build Coastguard Worker {
2739*35238bceSAndroid Build Coastguard Worker if ((*i)->m_elementArrayBufferBinding == buffer)
2740*35238bceSAndroid Build Coastguard Worker {
2741*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(buffer);
2742*35238bceSAndroid Build Coastguard Worker (*i)->m_elementArrayBufferBinding = DE_NULL;
2743*35238bceSAndroid Build Coastguard Worker }
2744*35238bceSAndroid Build Coastguard Worker
2745*35238bceSAndroid Build Coastguard Worker for (size_t vertexAttribNdx = 0; vertexAttribNdx < (*i)->m_arrays.size(); ++vertexAttribNdx)
2746*35238bceSAndroid Build Coastguard Worker {
2747*35238bceSAndroid Build Coastguard Worker if ((*i)->m_arrays[vertexAttribNdx].bufferBinding == buffer)
2748*35238bceSAndroid Build Coastguard Worker {
2749*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(buffer);
2750*35238bceSAndroid Build Coastguard Worker (*i)->m_arrays[vertexAttribNdx].bufferDeleted = true;
2751*35238bceSAndroid Build Coastguard Worker (*i)->m_arrays[vertexAttribNdx].bufferBinding = DE_NULL;
2752*35238bceSAndroid Build Coastguard Worker }
2753*35238bceSAndroid Build Coastguard Worker }
2754*35238bceSAndroid Build Coastguard Worker }
2755*35238bceSAndroid Build Coastguard Worker }
2756*35238bceSAndroid Build Coastguard Worker
2757*35238bceSAndroid Build Coastguard Worker DE_ASSERT(buffer->getRefCount() == 1);
2758*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(buffer);
2759*35238bceSAndroid Build Coastguard Worker }
2760*35238bceSAndroid Build Coastguard Worker
bufferData(uint32_t target,intptr_t size,const void * data,uint32_t usage)2761*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bufferData(uint32_t target, intptr_t size, const void *data, uint32_t usage)
2762*35238bceSAndroid Build Coastguard Worker {
2763*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBufferTarget(target), GL_INVALID_ENUM, RC_RET_VOID);
2764*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(size < 0, GL_INVALID_VALUE, RC_RET_VOID);
2765*35238bceSAndroid Build Coastguard Worker
2766*35238bceSAndroid Build Coastguard Worker DE_UNREF(usage);
2767*35238bceSAndroid Build Coastguard Worker
2768*35238bceSAndroid Build Coastguard Worker DataBuffer *buffer = getBufferBinding(target);
2769*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!buffer, GL_INVALID_OPERATION, RC_RET_VOID);
2770*35238bceSAndroid Build Coastguard Worker
2771*35238bceSAndroid Build Coastguard Worker DE_ASSERT((intptr_t)(int)size == size);
2772*35238bceSAndroid Build Coastguard Worker buffer->setStorage((int)size);
2773*35238bceSAndroid Build Coastguard Worker if (data)
2774*35238bceSAndroid Build Coastguard Worker deMemcpy(buffer->getData(), data, (int)size);
2775*35238bceSAndroid Build Coastguard Worker }
2776*35238bceSAndroid Build Coastguard Worker
bufferSubData(uint32_t target,intptr_t offset,intptr_t size,const void * data)2777*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bufferSubData(uint32_t target, intptr_t offset, intptr_t size, const void *data)
2778*35238bceSAndroid Build Coastguard Worker {
2779*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBufferTarget(target), GL_INVALID_ENUM, RC_RET_VOID);
2780*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(offset < 0 || size < 0, GL_INVALID_VALUE, RC_RET_VOID);
2781*35238bceSAndroid Build Coastguard Worker
2782*35238bceSAndroid Build Coastguard Worker DataBuffer *buffer = getBufferBinding(target);
2783*35238bceSAndroid Build Coastguard Worker
2784*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!buffer, GL_INVALID_OPERATION, RC_RET_VOID);
2785*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((int)(offset + size) > buffer->getSize(), GL_INVALID_VALUE, RC_RET_VOID);
2786*35238bceSAndroid Build Coastguard Worker
2787*35238bceSAndroid Build Coastguard Worker deMemcpy(buffer->getData() + offset, data, (int)size);
2788*35238bceSAndroid Build Coastguard Worker }
2789*35238bceSAndroid Build Coastguard Worker
clearColor(float red,float green,float blue,float alpha)2790*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearColor(float red, float green, float blue, float alpha)
2791*35238bceSAndroid Build Coastguard Worker {
2792*35238bceSAndroid Build Coastguard Worker m_clearColor = Vec4(de::clamp(red, 0.0f, 1.0f), de::clamp(green, 0.0f, 1.0f), de::clamp(blue, 0.0f, 1.0f),
2793*35238bceSAndroid Build Coastguard Worker de::clamp(alpha, 0.0f, 1.0f));
2794*35238bceSAndroid Build Coastguard Worker }
2795*35238bceSAndroid Build Coastguard Worker
clearDepthf(float depth)2796*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearDepthf(float depth)
2797*35238bceSAndroid Build Coastguard Worker {
2798*35238bceSAndroid Build Coastguard Worker m_clearDepth = de::clamp(depth, 0.0f, 1.0f);
2799*35238bceSAndroid Build Coastguard Worker }
2800*35238bceSAndroid Build Coastguard Worker
clearStencil(int stencil)2801*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearStencil(int stencil)
2802*35238bceSAndroid Build Coastguard Worker {
2803*35238bceSAndroid Build Coastguard Worker m_clearStencil = stencil;
2804*35238bceSAndroid Build Coastguard Worker }
2805*35238bceSAndroid Build Coastguard Worker
scissor(int x,int y,int width,int height)2806*35238bceSAndroid Build Coastguard Worker void ReferenceContext::scissor(int x, int y, int width, int height)
2807*35238bceSAndroid Build Coastguard Worker {
2808*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || height < 0, GL_INVALID_VALUE, RC_RET_VOID);
2809*35238bceSAndroid Build Coastguard Worker m_scissorBox = IVec4(x, y, width, height);
2810*35238bceSAndroid Build Coastguard Worker }
2811*35238bceSAndroid Build Coastguard Worker
enable(uint32_t cap)2812*35238bceSAndroid Build Coastguard Worker void ReferenceContext::enable(uint32_t cap)
2813*35238bceSAndroid Build Coastguard Worker {
2814*35238bceSAndroid Build Coastguard Worker switch (cap)
2815*35238bceSAndroid Build Coastguard Worker {
2816*35238bceSAndroid Build Coastguard Worker case GL_BLEND:
2817*35238bceSAndroid Build Coastguard Worker m_blendEnabled = true;
2818*35238bceSAndroid Build Coastguard Worker break;
2819*35238bceSAndroid Build Coastguard Worker case GL_SCISSOR_TEST:
2820*35238bceSAndroid Build Coastguard Worker m_scissorEnabled = true;
2821*35238bceSAndroid Build Coastguard Worker break;
2822*35238bceSAndroid Build Coastguard Worker case GL_DEPTH_TEST:
2823*35238bceSAndroid Build Coastguard Worker m_depthTestEnabled = true;
2824*35238bceSAndroid Build Coastguard Worker break;
2825*35238bceSAndroid Build Coastguard Worker case GL_STENCIL_TEST:
2826*35238bceSAndroid Build Coastguard Worker m_stencilTestEnabled = true;
2827*35238bceSAndroid Build Coastguard Worker break;
2828*35238bceSAndroid Build Coastguard Worker case GL_POLYGON_OFFSET_FILL:
2829*35238bceSAndroid Build Coastguard Worker m_polygonOffsetFillEnabled = true;
2830*35238bceSAndroid Build Coastguard Worker break;
2831*35238bceSAndroid Build Coastguard Worker
2832*35238bceSAndroid Build Coastguard Worker case GL_FRAMEBUFFER_SRGB:
2833*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
2834*35238bceSAndroid Build Coastguard Worker {
2835*35238bceSAndroid Build Coastguard Worker m_sRGBUpdateEnabled = true;
2836*35238bceSAndroid Build Coastguard Worker break;
2837*35238bceSAndroid Build Coastguard Worker }
2838*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2839*35238bceSAndroid Build Coastguard Worker break;
2840*35238bceSAndroid Build Coastguard Worker
2841*35238bceSAndroid Build Coastguard Worker case GL_DEPTH_CLAMP:
2842*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
2843*35238bceSAndroid Build Coastguard Worker {
2844*35238bceSAndroid Build Coastguard Worker m_depthClampEnabled = true;
2845*35238bceSAndroid Build Coastguard Worker break;
2846*35238bceSAndroid Build Coastguard Worker }
2847*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2848*35238bceSAndroid Build Coastguard Worker break;
2849*35238bceSAndroid Build Coastguard Worker
2850*35238bceSAndroid Build Coastguard Worker case GL_DITHER:
2851*35238bceSAndroid Build Coastguard Worker // Not implemented - just ignored.
2852*35238bceSAndroid Build Coastguard Worker break;
2853*35238bceSAndroid Build Coastguard Worker
2854*35238bceSAndroid Build Coastguard Worker case GL_PRIMITIVE_RESTART_FIXED_INDEX:
2855*35238bceSAndroid Build Coastguard Worker if (!glu::isContextTypeGLCore(getType()))
2856*35238bceSAndroid Build Coastguard Worker {
2857*35238bceSAndroid Build Coastguard Worker m_primitiveRestartFixedIndex = true;
2858*35238bceSAndroid Build Coastguard Worker break;
2859*35238bceSAndroid Build Coastguard Worker }
2860*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2861*35238bceSAndroid Build Coastguard Worker break;
2862*35238bceSAndroid Build Coastguard Worker
2863*35238bceSAndroid Build Coastguard Worker case GL_PRIMITIVE_RESTART:
2864*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
2865*35238bceSAndroid Build Coastguard Worker {
2866*35238bceSAndroid Build Coastguard Worker m_primitiveRestartSettableIndex = true;
2867*35238bceSAndroid Build Coastguard Worker break;
2868*35238bceSAndroid Build Coastguard Worker }
2869*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2870*35238bceSAndroid Build Coastguard Worker break;
2871*35238bceSAndroid Build Coastguard Worker
2872*35238bceSAndroid Build Coastguard Worker default:
2873*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2874*35238bceSAndroid Build Coastguard Worker break;
2875*35238bceSAndroid Build Coastguard Worker }
2876*35238bceSAndroid Build Coastguard Worker }
2877*35238bceSAndroid Build Coastguard Worker
disable(uint32_t cap)2878*35238bceSAndroid Build Coastguard Worker void ReferenceContext::disable(uint32_t cap)
2879*35238bceSAndroid Build Coastguard Worker {
2880*35238bceSAndroid Build Coastguard Worker switch (cap)
2881*35238bceSAndroid Build Coastguard Worker {
2882*35238bceSAndroid Build Coastguard Worker case GL_BLEND:
2883*35238bceSAndroid Build Coastguard Worker m_blendEnabled = false;
2884*35238bceSAndroid Build Coastguard Worker break;
2885*35238bceSAndroid Build Coastguard Worker case GL_SCISSOR_TEST:
2886*35238bceSAndroid Build Coastguard Worker m_scissorEnabled = false;
2887*35238bceSAndroid Build Coastguard Worker break;
2888*35238bceSAndroid Build Coastguard Worker case GL_DEPTH_TEST:
2889*35238bceSAndroid Build Coastguard Worker m_depthTestEnabled = false;
2890*35238bceSAndroid Build Coastguard Worker break;
2891*35238bceSAndroid Build Coastguard Worker case GL_STENCIL_TEST:
2892*35238bceSAndroid Build Coastguard Worker m_stencilTestEnabled = false;
2893*35238bceSAndroid Build Coastguard Worker break;
2894*35238bceSAndroid Build Coastguard Worker case GL_POLYGON_OFFSET_FILL:
2895*35238bceSAndroid Build Coastguard Worker m_polygonOffsetFillEnabled = false;
2896*35238bceSAndroid Build Coastguard Worker break;
2897*35238bceSAndroid Build Coastguard Worker
2898*35238bceSAndroid Build Coastguard Worker case GL_FRAMEBUFFER_SRGB:
2899*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
2900*35238bceSAndroid Build Coastguard Worker {
2901*35238bceSAndroid Build Coastguard Worker m_sRGBUpdateEnabled = false;
2902*35238bceSAndroid Build Coastguard Worker break;
2903*35238bceSAndroid Build Coastguard Worker }
2904*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2905*35238bceSAndroid Build Coastguard Worker break;
2906*35238bceSAndroid Build Coastguard Worker
2907*35238bceSAndroid Build Coastguard Worker case GL_DEPTH_CLAMP:
2908*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
2909*35238bceSAndroid Build Coastguard Worker {
2910*35238bceSAndroid Build Coastguard Worker m_depthClampEnabled = false;
2911*35238bceSAndroid Build Coastguard Worker break;
2912*35238bceSAndroid Build Coastguard Worker }
2913*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2914*35238bceSAndroid Build Coastguard Worker break;
2915*35238bceSAndroid Build Coastguard Worker
2916*35238bceSAndroid Build Coastguard Worker case GL_DITHER:
2917*35238bceSAndroid Build Coastguard Worker break;
2918*35238bceSAndroid Build Coastguard Worker
2919*35238bceSAndroid Build Coastguard Worker case GL_PRIMITIVE_RESTART_FIXED_INDEX:
2920*35238bceSAndroid Build Coastguard Worker if (!glu::isContextTypeGLCore(getType()))
2921*35238bceSAndroid Build Coastguard Worker {
2922*35238bceSAndroid Build Coastguard Worker m_primitiveRestartFixedIndex = false;
2923*35238bceSAndroid Build Coastguard Worker break;
2924*35238bceSAndroid Build Coastguard Worker }
2925*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2926*35238bceSAndroid Build Coastguard Worker break;
2927*35238bceSAndroid Build Coastguard Worker
2928*35238bceSAndroid Build Coastguard Worker case GL_PRIMITIVE_RESTART:
2929*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(getType()))
2930*35238bceSAndroid Build Coastguard Worker {
2931*35238bceSAndroid Build Coastguard Worker m_primitiveRestartSettableIndex = false;
2932*35238bceSAndroid Build Coastguard Worker break;
2933*35238bceSAndroid Build Coastguard Worker }
2934*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2935*35238bceSAndroid Build Coastguard Worker break;
2936*35238bceSAndroid Build Coastguard Worker
2937*35238bceSAndroid Build Coastguard Worker default:
2938*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
2939*35238bceSAndroid Build Coastguard Worker break;
2940*35238bceSAndroid Build Coastguard Worker }
2941*35238bceSAndroid Build Coastguard Worker }
2942*35238bceSAndroid Build Coastguard Worker
isValidCompareFunc(uint32_t func)2943*35238bceSAndroid Build Coastguard Worker static bool isValidCompareFunc(uint32_t func)
2944*35238bceSAndroid Build Coastguard Worker {
2945*35238bceSAndroid Build Coastguard Worker switch (func)
2946*35238bceSAndroid Build Coastguard Worker {
2947*35238bceSAndroid Build Coastguard Worker case GL_NEVER:
2948*35238bceSAndroid Build Coastguard Worker case GL_LESS:
2949*35238bceSAndroid Build Coastguard Worker case GL_LEQUAL:
2950*35238bceSAndroid Build Coastguard Worker case GL_GREATER:
2951*35238bceSAndroid Build Coastguard Worker case GL_GEQUAL:
2952*35238bceSAndroid Build Coastguard Worker case GL_EQUAL:
2953*35238bceSAndroid Build Coastguard Worker case GL_NOTEQUAL:
2954*35238bceSAndroid Build Coastguard Worker case GL_ALWAYS:
2955*35238bceSAndroid Build Coastguard Worker return true;
2956*35238bceSAndroid Build Coastguard Worker
2957*35238bceSAndroid Build Coastguard Worker default:
2958*35238bceSAndroid Build Coastguard Worker return false;
2959*35238bceSAndroid Build Coastguard Worker }
2960*35238bceSAndroid Build Coastguard Worker }
2961*35238bceSAndroid Build Coastguard Worker
isValidStencilOp(uint32_t op)2962*35238bceSAndroid Build Coastguard Worker static bool isValidStencilOp(uint32_t op)
2963*35238bceSAndroid Build Coastguard Worker {
2964*35238bceSAndroid Build Coastguard Worker switch (op)
2965*35238bceSAndroid Build Coastguard Worker {
2966*35238bceSAndroid Build Coastguard Worker case GL_KEEP:
2967*35238bceSAndroid Build Coastguard Worker case GL_ZERO:
2968*35238bceSAndroid Build Coastguard Worker case GL_REPLACE:
2969*35238bceSAndroid Build Coastguard Worker case GL_INCR:
2970*35238bceSAndroid Build Coastguard Worker case GL_INCR_WRAP:
2971*35238bceSAndroid Build Coastguard Worker case GL_DECR:
2972*35238bceSAndroid Build Coastguard Worker case GL_DECR_WRAP:
2973*35238bceSAndroid Build Coastguard Worker case GL_INVERT:
2974*35238bceSAndroid Build Coastguard Worker return true;
2975*35238bceSAndroid Build Coastguard Worker
2976*35238bceSAndroid Build Coastguard Worker default:
2977*35238bceSAndroid Build Coastguard Worker return false;
2978*35238bceSAndroid Build Coastguard Worker }
2979*35238bceSAndroid Build Coastguard Worker }
2980*35238bceSAndroid Build Coastguard Worker
stencilFunc(uint32_t func,int ref,uint32_t mask)2981*35238bceSAndroid Build Coastguard Worker void ReferenceContext::stencilFunc(uint32_t func, int ref, uint32_t mask)
2982*35238bceSAndroid Build Coastguard Worker {
2983*35238bceSAndroid Build Coastguard Worker stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
2984*35238bceSAndroid Build Coastguard Worker }
2985*35238bceSAndroid Build Coastguard Worker
stencilFuncSeparate(uint32_t face,uint32_t func,int ref,uint32_t mask)2986*35238bceSAndroid Build Coastguard Worker void ReferenceContext::stencilFuncSeparate(uint32_t face, uint32_t func, int ref, uint32_t mask)
2987*35238bceSAndroid Build Coastguard Worker {
2988*35238bceSAndroid Build Coastguard Worker const bool setFront = face == GL_FRONT || face == GL_FRONT_AND_BACK;
2989*35238bceSAndroid Build Coastguard Worker const bool setBack = face == GL_BACK || face == GL_FRONT_AND_BACK;
2990*35238bceSAndroid Build Coastguard Worker
2991*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidCompareFunc(func), GL_INVALID_ENUM, RC_RET_VOID);
2992*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!setFront && !setBack, GL_INVALID_ENUM, RC_RET_VOID);
2993*35238bceSAndroid Build Coastguard Worker
2994*35238bceSAndroid Build Coastguard Worker for (int type = 0; type < rr::FACETYPE_LAST; ++type)
2995*35238bceSAndroid Build Coastguard Worker {
2996*35238bceSAndroid Build Coastguard Worker if ((type == rr::FACETYPE_FRONT && setFront) || (type == rr::FACETYPE_BACK && setBack))
2997*35238bceSAndroid Build Coastguard Worker {
2998*35238bceSAndroid Build Coastguard Worker m_stencil[type].func = func;
2999*35238bceSAndroid Build Coastguard Worker m_stencil[type].ref = ref;
3000*35238bceSAndroid Build Coastguard Worker m_stencil[type].opMask = mask;
3001*35238bceSAndroid Build Coastguard Worker }
3002*35238bceSAndroid Build Coastguard Worker }
3003*35238bceSAndroid Build Coastguard Worker }
3004*35238bceSAndroid Build Coastguard Worker
stencilOp(uint32_t sfail,uint32_t dpfail,uint32_t dppass)3005*35238bceSAndroid Build Coastguard Worker void ReferenceContext::stencilOp(uint32_t sfail, uint32_t dpfail, uint32_t dppass)
3006*35238bceSAndroid Build Coastguard Worker {
3007*35238bceSAndroid Build Coastguard Worker stencilOpSeparate(GL_FRONT_AND_BACK, sfail, dpfail, dppass);
3008*35238bceSAndroid Build Coastguard Worker }
3009*35238bceSAndroid Build Coastguard Worker
stencilOpSeparate(uint32_t face,uint32_t sfail,uint32_t dpfail,uint32_t dppass)3010*35238bceSAndroid Build Coastguard Worker void ReferenceContext::stencilOpSeparate(uint32_t face, uint32_t sfail, uint32_t dpfail, uint32_t dppass)
3011*35238bceSAndroid Build Coastguard Worker {
3012*35238bceSAndroid Build Coastguard Worker const bool setFront = face == GL_FRONT || face == GL_FRONT_AND_BACK;
3013*35238bceSAndroid Build Coastguard Worker const bool setBack = face == GL_BACK || face == GL_FRONT_AND_BACK;
3014*35238bceSAndroid Build Coastguard Worker
3015*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidStencilOp(sfail) || !isValidStencilOp(dpfail) || !isValidStencilOp(dppass), GL_INVALID_ENUM,
3016*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
3017*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!setFront && !setBack, GL_INVALID_ENUM, RC_RET_VOID);
3018*35238bceSAndroid Build Coastguard Worker
3019*35238bceSAndroid Build Coastguard Worker for (int type = 0; type < rr::FACETYPE_LAST; ++type)
3020*35238bceSAndroid Build Coastguard Worker {
3021*35238bceSAndroid Build Coastguard Worker if ((type == rr::FACETYPE_FRONT && setFront) || (type == rr::FACETYPE_BACK && setBack))
3022*35238bceSAndroid Build Coastguard Worker {
3023*35238bceSAndroid Build Coastguard Worker m_stencil[type].opStencilFail = sfail;
3024*35238bceSAndroid Build Coastguard Worker m_stencil[type].opDepthFail = dpfail;
3025*35238bceSAndroid Build Coastguard Worker m_stencil[type].opDepthPass = dppass;
3026*35238bceSAndroid Build Coastguard Worker }
3027*35238bceSAndroid Build Coastguard Worker }
3028*35238bceSAndroid Build Coastguard Worker }
3029*35238bceSAndroid Build Coastguard Worker
depthFunc(uint32_t func)3030*35238bceSAndroid Build Coastguard Worker void ReferenceContext::depthFunc(uint32_t func)
3031*35238bceSAndroid Build Coastguard Worker {
3032*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidCompareFunc(func), GL_INVALID_ENUM, RC_RET_VOID);
3033*35238bceSAndroid Build Coastguard Worker m_depthFunc = func;
3034*35238bceSAndroid Build Coastguard Worker }
3035*35238bceSAndroid Build Coastguard Worker
depthRangef(float n,float f)3036*35238bceSAndroid Build Coastguard Worker void ReferenceContext::depthRangef(float n, float f)
3037*35238bceSAndroid Build Coastguard Worker {
3038*35238bceSAndroid Build Coastguard Worker m_depthRangeNear = de::clamp(n, 0.0f, 1.0f);
3039*35238bceSAndroid Build Coastguard Worker m_depthRangeFar = de::clamp(f, 0.0f, 1.0f);
3040*35238bceSAndroid Build Coastguard Worker }
3041*35238bceSAndroid Build Coastguard Worker
depthRange(double n,double f)3042*35238bceSAndroid Build Coastguard Worker void ReferenceContext::depthRange(double n, double f)
3043*35238bceSAndroid Build Coastguard Worker {
3044*35238bceSAndroid Build Coastguard Worker depthRangef((float)n, (float)f);
3045*35238bceSAndroid Build Coastguard Worker }
3046*35238bceSAndroid Build Coastguard Worker
polygonOffset(float factor,float units)3047*35238bceSAndroid Build Coastguard Worker void ReferenceContext::polygonOffset(float factor, float units)
3048*35238bceSAndroid Build Coastguard Worker {
3049*35238bceSAndroid Build Coastguard Worker m_polygonOffsetFactor = factor;
3050*35238bceSAndroid Build Coastguard Worker m_polygonOffsetUnits = units;
3051*35238bceSAndroid Build Coastguard Worker }
3052*35238bceSAndroid Build Coastguard Worker
provokingVertex(uint32_t convention)3053*35238bceSAndroid Build Coastguard Worker void ReferenceContext::provokingVertex(uint32_t convention)
3054*35238bceSAndroid Build Coastguard Worker {
3055*35238bceSAndroid Build Coastguard Worker // only in core
3056*35238bceSAndroid Build Coastguard Worker DE_ASSERT(glu::isContextTypeGLCore(getType()));
3057*35238bceSAndroid Build Coastguard Worker
3058*35238bceSAndroid Build Coastguard Worker switch (convention)
3059*35238bceSAndroid Build Coastguard Worker {
3060*35238bceSAndroid Build Coastguard Worker case GL_FIRST_VERTEX_CONVENTION:
3061*35238bceSAndroid Build Coastguard Worker m_provokingFirstVertexConvention = true;
3062*35238bceSAndroid Build Coastguard Worker break;
3063*35238bceSAndroid Build Coastguard Worker case GL_LAST_VERTEX_CONVENTION:
3064*35238bceSAndroid Build Coastguard Worker m_provokingFirstVertexConvention = false;
3065*35238bceSAndroid Build Coastguard Worker break;
3066*35238bceSAndroid Build Coastguard Worker
3067*35238bceSAndroid Build Coastguard Worker default:
3068*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_ENUM, RC_RET_VOID);
3069*35238bceSAndroid Build Coastguard Worker }
3070*35238bceSAndroid Build Coastguard Worker }
3071*35238bceSAndroid Build Coastguard Worker
primitiveRestartIndex(uint32_t index)3072*35238bceSAndroid Build Coastguard Worker void ReferenceContext::primitiveRestartIndex(uint32_t index)
3073*35238bceSAndroid Build Coastguard Worker {
3074*35238bceSAndroid Build Coastguard Worker // only in core
3075*35238bceSAndroid Build Coastguard Worker DE_ASSERT(glu::isContextTypeGLCore(getType()));
3076*35238bceSAndroid Build Coastguard Worker m_primitiveRestartIndex = index;
3077*35238bceSAndroid Build Coastguard Worker }
3078*35238bceSAndroid Build Coastguard Worker
isValidBlendEquation(uint32_t mode)3079*35238bceSAndroid Build Coastguard Worker static inline bool isValidBlendEquation(uint32_t mode)
3080*35238bceSAndroid Build Coastguard Worker {
3081*35238bceSAndroid Build Coastguard Worker return mode == GL_FUNC_ADD || mode == GL_FUNC_SUBTRACT || mode == GL_FUNC_REVERSE_SUBTRACT || mode == GL_MIN ||
3082*35238bceSAndroid Build Coastguard Worker mode == GL_MAX;
3083*35238bceSAndroid Build Coastguard Worker }
3084*35238bceSAndroid Build Coastguard Worker
isValidBlendFactor(uint32_t factor)3085*35238bceSAndroid Build Coastguard Worker static bool isValidBlendFactor(uint32_t factor)
3086*35238bceSAndroid Build Coastguard Worker {
3087*35238bceSAndroid Build Coastguard Worker switch (factor)
3088*35238bceSAndroid Build Coastguard Worker {
3089*35238bceSAndroid Build Coastguard Worker case GL_ZERO:
3090*35238bceSAndroid Build Coastguard Worker case GL_ONE:
3091*35238bceSAndroid Build Coastguard Worker case GL_SRC_COLOR:
3092*35238bceSAndroid Build Coastguard Worker case GL_ONE_MINUS_SRC_COLOR:
3093*35238bceSAndroid Build Coastguard Worker case GL_DST_COLOR:
3094*35238bceSAndroid Build Coastguard Worker case GL_ONE_MINUS_DST_COLOR:
3095*35238bceSAndroid Build Coastguard Worker case GL_SRC_ALPHA:
3096*35238bceSAndroid Build Coastguard Worker case GL_ONE_MINUS_SRC_ALPHA:
3097*35238bceSAndroid Build Coastguard Worker case GL_DST_ALPHA:
3098*35238bceSAndroid Build Coastguard Worker case GL_ONE_MINUS_DST_ALPHA:
3099*35238bceSAndroid Build Coastguard Worker case GL_CONSTANT_COLOR:
3100*35238bceSAndroid Build Coastguard Worker case GL_ONE_MINUS_CONSTANT_COLOR:
3101*35238bceSAndroid Build Coastguard Worker case GL_CONSTANT_ALPHA:
3102*35238bceSAndroid Build Coastguard Worker case GL_ONE_MINUS_CONSTANT_ALPHA:
3103*35238bceSAndroid Build Coastguard Worker case GL_SRC_ALPHA_SATURATE:
3104*35238bceSAndroid Build Coastguard Worker return true;
3105*35238bceSAndroid Build Coastguard Worker
3106*35238bceSAndroid Build Coastguard Worker default:
3107*35238bceSAndroid Build Coastguard Worker return false;
3108*35238bceSAndroid Build Coastguard Worker }
3109*35238bceSAndroid Build Coastguard Worker }
3110*35238bceSAndroid Build Coastguard Worker
blendEquation(uint32_t mode)3111*35238bceSAndroid Build Coastguard Worker void ReferenceContext::blendEquation(uint32_t mode)
3112*35238bceSAndroid Build Coastguard Worker {
3113*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBlendEquation(mode), GL_INVALID_ENUM, RC_RET_VOID);
3114*35238bceSAndroid Build Coastguard Worker
3115*35238bceSAndroid Build Coastguard Worker m_blendModeRGB = mode;
3116*35238bceSAndroid Build Coastguard Worker m_blendModeAlpha = mode;
3117*35238bceSAndroid Build Coastguard Worker }
3118*35238bceSAndroid Build Coastguard Worker
blendEquationSeparate(uint32_t modeRGB,uint32_t modeAlpha)3119*35238bceSAndroid Build Coastguard Worker void ReferenceContext::blendEquationSeparate(uint32_t modeRGB, uint32_t modeAlpha)
3120*35238bceSAndroid Build Coastguard Worker {
3121*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBlendEquation(modeRGB) || !isValidBlendEquation(modeAlpha), GL_INVALID_ENUM, RC_RET_VOID);
3122*35238bceSAndroid Build Coastguard Worker
3123*35238bceSAndroid Build Coastguard Worker m_blendModeRGB = modeRGB;
3124*35238bceSAndroid Build Coastguard Worker m_blendModeAlpha = modeAlpha;
3125*35238bceSAndroid Build Coastguard Worker }
3126*35238bceSAndroid Build Coastguard Worker
blendFunc(uint32_t src,uint32_t dst)3127*35238bceSAndroid Build Coastguard Worker void ReferenceContext::blendFunc(uint32_t src, uint32_t dst)
3128*35238bceSAndroid Build Coastguard Worker {
3129*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBlendFactor(src) || !isValidBlendFactor(dst), GL_INVALID_ENUM, RC_RET_VOID);
3130*35238bceSAndroid Build Coastguard Worker
3131*35238bceSAndroid Build Coastguard Worker m_blendFactorSrcRGB = src;
3132*35238bceSAndroid Build Coastguard Worker m_blendFactorSrcAlpha = src;
3133*35238bceSAndroid Build Coastguard Worker m_blendFactorDstRGB = dst;
3134*35238bceSAndroid Build Coastguard Worker m_blendFactorDstAlpha = dst;
3135*35238bceSAndroid Build Coastguard Worker }
3136*35238bceSAndroid Build Coastguard Worker
blendFuncSeparate(uint32_t srcRGB,uint32_t dstRGB,uint32_t srcAlpha,uint32_t dstAlpha)3137*35238bceSAndroid Build Coastguard Worker void ReferenceContext::blendFuncSeparate(uint32_t srcRGB, uint32_t dstRGB, uint32_t srcAlpha, uint32_t dstAlpha)
3138*35238bceSAndroid Build Coastguard Worker {
3139*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isValidBlendFactor(srcRGB) || !isValidBlendFactor(dstRGB) || !isValidBlendFactor(srcAlpha) ||
3140*35238bceSAndroid Build Coastguard Worker !isValidBlendFactor(dstAlpha),
3141*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
3142*35238bceSAndroid Build Coastguard Worker
3143*35238bceSAndroid Build Coastguard Worker m_blendFactorSrcRGB = srcRGB;
3144*35238bceSAndroid Build Coastguard Worker m_blendFactorSrcAlpha = srcAlpha;
3145*35238bceSAndroid Build Coastguard Worker m_blendFactorDstRGB = dstRGB;
3146*35238bceSAndroid Build Coastguard Worker m_blendFactorDstAlpha = dstAlpha;
3147*35238bceSAndroid Build Coastguard Worker }
3148*35238bceSAndroid Build Coastguard Worker
blendColor(float red,float green,float blue,float alpha)3149*35238bceSAndroid Build Coastguard Worker void ReferenceContext::blendColor(float red, float green, float blue, float alpha)
3150*35238bceSAndroid Build Coastguard Worker {
3151*35238bceSAndroid Build Coastguard Worker m_blendColor = Vec4(de::clamp(red, 0.0f, 1.0f), de::clamp(green, 0.0f, 1.0f), de::clamp(blue, 0.0f, 1.0f),
3152*35238bceSAndroid Build Coastguard Worker de::clamp(alpha, 0.0f, 1.0f));
3153*35238bceSAndroid Build Coastguard Worker }
3154*35238bceSAndroid Build Coastguard Worker
colorMask(bool r,bool g,bool b,bool a)3155*35238bceSAndroid Build Coastguard Worker void ReferenceContext::colorMask(bool r, bool g, bool b, bool a)
3156*35238bceSAndroid Build Coastguard Worker {
3157*35238bceSAndroid Build Coastguard Worker m_colorMask = tcu::BVec4(!!r, !!g, !!b, !!a);
3158*35238bceSAndroid Build Coastguard Worker }
3159*35238bceSAndroid Build Coastguard Worker
depthMask(bool mask)3160*35238bceSAndroid Build Coastguard Worker void ReferenceContext::depthMask(bool mask)
3161*35238bceSAndroid Build Coastguard Worker {
3162*35238bceSAndroid Build Coastguard Worker m_depthMask = !!mask;
3163*35238bceSAndroid Build Coastguard Worker }
3164*35238bceSAndroid Build Coastguard Worker
stencilMask(uint32_t mask)3165*35238bceSAndroid Build Coastguard Worker void ReferenceContext::stencilMask(uint32_t mask)
3166*35238bceSAndroid Build Coastguard Worker {
3167*35238bceSAndroid Build Coastguard Worker stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
3168*35238bceSAndroid Build Coastguard Worker }
3169*35238bceSAndroid Build Coastguard Worker
stencilMaskSeparate(uint32_t face,uint32_t mask)3170*35238bceSAndroid Build Coastguard Worker void ReferenceContext::stencilMaskSeparate(uint32_t face, uint32_t mask)
3171*35238bceSAndroid Build Coastguard Worker {
3172*35238bceSAndroid Build Coastguard Worker const bool setFront = face == GL_FRONT || face == GL_FRONT_AND_BACK;
3173*35238bceSAndroid Build Coastguard Worker const bool setBack = face == GL_BACK || face == GL_FRONT_AND_BACK;
3174*35238bceSAndroid Build Coastguard Worker
3175*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!setFront && !setBack, GL_INVALID_ENUM, RC_RET_VOID);
3176*35238bceSAndroid Build Coastguard Worker
3177*35238bceSAndroid Build Coastguard Worker if (setFront)
3178*35238bceSAndroid Build Coastguard Worker m_stencil[rr::FACETYPE_FRONT].writeMask = mask;
3179*35238bceSAndroid Build Coastguard Worker if (setBack)
3180*35238bceSAndroid Build Coastguard Worker m_stencil[rr::FACETYPE_BACK].writeMask = mask;
3181*35238bceSAndroid Build Coastguard Worker }
3182*35238bceSAndroid Build Coastguard Worker
getNumStencilBits(const tcu::TextureFormat & format)3183*35238bceSAndroid Build Coastguard Worker static int getNumStencilBits(const tcu::TextureFormat &format)
3184*35238bceSAndroid Build Coastguard Worker {
3185*35238bceSAndroid Build Coastguard Worker switch (format.order)
3186*35238bceSAndroid Build Coastguard Worker {
3187*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::S:
3188*35238bceSAndroid Build Coastguard Worker switch (format.type)
3189*35238bceSAndroid Build Coastguard Worker {
3190*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::UNSIGNED_INT8:
3191*35238bceSAndroid Build Coastguard Worker return 8;
3192*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::UNSIGNED_INT16:
3193*35238bceSAndroid Build Coastguard Worker return 16;
3194*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::UNSIGNED_INT32:
3195*35238bceSAndroid Build Coastguard Worker return 32;
3196*35238bceSAndroid Build Coastguard Worker default:
3197*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
3198*35238bceSAndroid Build Coastguard Worker return 0;
3199*35238bceSAndroid Build Coastguard Worker }
3200*35238bceSAndroid Build Coastguard Worker
3201*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::DS:
3202*35238bceSAndroid Build Coastguard Worker switch (format.type)
3203*35238bceSAndroid Build Coastguard Worker {
3204*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::UNSIGNED_INT_24_8:
3205*35238bceSAndroid Build Coastguard Worker return 8;
3206*35238bceSAndroid Build Coastguard Worker case tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:
3207*35238bceSAndroid Build Coastguard Worker return 8;
3208*35238bceSAndroid Build Coastguard Worker default:
3209*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
3210*35238bceSAndroid Build Coastguard Worker return 0;
3211*35238bceSAndroid Build Coastguard Worker }
3212*35238bceSAndroid Build Coastguard Worker
3213*35238bceSAndroid Build Coastguard Worker default:
3214*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
3215*35238bceSAndroid Build Coastguard Worker return 0;
3216*35238bceSAndroid Build Coastguard Worker }
3217*35238bceSAndroid Build Coastguard Worker }
3218*35238bceSAndroid Build Coastguard Worker
maskStencil(int numBits,uint32_t s)3219*35238bceSAndroid Build Coastguard Worker static inline uint32_t maskStencil(int numBits, uint32_t s)
3220*35238bceSAndroid Build Coastguard Worker {
3221*35238bceSAndroid Build Coastguard Worker return s & deBitMask32(0, numBits);
3222*35238bceSAndroid Build Coastguard Worker }
3223*35238bceSAndroid Build Coastguard Worker
writeMaskedStencil(const rr::MultisamplePixelBufferAccess & access,int s,int x,int y,uint32_t stencil,uint32_t writeMask)3224*35238bceSAndroid Build Coastguard Worker static inline void writeMaskedStencil(const rr::MultisamplePixelBufferAccess &access, int s, int x, int y,
3225*35238bceSAndroid Build Coastguard Worker uint32_t stencil, uint32_t writeMask)
3226*35238bceSAndroid Build Coastguard Worker {
3227*35238bceSAndroid Build Coastguard Worker DE_ASSERT(access.raw().getFormat().order == tcu::TextureFormat::S);
3228*35238bceSAndroid Build Coastguard Worker
3229*35238bceSAndroid Build Coastguard Worker const uint32_t oldVal = access.raw().getPixelUint(s, x, y).x();
3230*35238bceSAndroid Build Coastguard Worker const uint32_t newVal = (oldVal & ~writeMask) | (stencil & writeMask);
3231*35238bceSAndroid Build Coastguard Worker access.raw().setPixel(tcu::UVec4(newVal, 0u, 0u, 0u), s, x, y);
3232*35238bceSAndroid Build Coastguard Worker }
3233*35238bceSAndroid Build Coastguard Worker
writeDepthOnly(const rr::MultisamplePixelBufferAccess & access,int s,int x,int y,float depth)3234*35238bceSAndroid Build Coastguard Worker static inline void writeDepthOnly(const rr::MultisamplePixelBufferAccess &access, int s, int x, int y, float depth)
3235*35238bceSAndroid Build Coastguard Worker {
3236*35238bceSAndroid Build Coastguard Worker access.raw().setPixDepth(depth, s, x, y);
3237*35238bceSAndroid Build Coastguard Worker }
3238*35238bceSAndroid Build Coastguard Worker
getDepthMultisampleAccess(const rr::MultisamplePixelBufferAccess & combinedDSaccess)3239*35238bceSAndroid Build Coastguard Worker static rr::MultisamplePixelBufferAccess getDepthMultisampleAccess(
3240*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &combinedDSaccess)
3241*35238bceSAndroid Build Coastguard Worker {
3242*35238bceSAndroid Build Coastguard Worker return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(
3243*35238bceSAndroid Build Coastguard Worker tcu::getEffectiveDepthStencilAccess(combinedDSaccess.raw(), tcu::Sampler::MODE_DEPTH));
3244*35238bceSAndroid Build Coastguard Worker }
3245*35238bceSAndroid Build Coastguard Worker
getStencilMultisampleAccess(const rr::MultisamplePixelBufferAccess & combinedDSaccess)3246*35238bceSAndroid Build Coastguard Worker static rr::MultisamplePixelBufferAccess getStencilMultisampleAccess(
3247*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &combinedDSaccess)
3248*35238bceSAndroid Build Coastguard Worker {
3249*35238bceSAndroid Build Coastguard Worker return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(
3250*35238bceSAndroid Build Coastguard Worker tcu::getEffectiveDepthStencilAccess(combinedDSaccess.raw(), tcu::Sampler::MODE_STENCIL));
3251*35238bceSAndroid Build Coastguard Worker }
3252*35238bceSAndroid Build Coastguard Worker
blitResolveMultisampleFramebuffer(uint32_t mask,const IVec4 & srcRect,const IVec4 & dstRect,bool flipX,bool flipY)3253*35238bceSAndroid Build Coastguard Worker uint32_t ReferenceContext::blitResolveMultisampleFramebuffer(uint32_t mask, const IVec4 &srcRect, const IVec4 &dstRect,
3254*35238bceSAndroid Build Coastguard Worker bool flipX, bool flipY)
3255*35238bceSAndroid Build Coastguard Worker {
3256*35238bceSAndroid Build Coastguard Worker if (mask & GL_COLOR_BUFFER_BIT)
3257*35238bceSAndroid Build Coastguard Worker {
3258*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src =
3259*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getReadColorbuffer(), srcRect.x(), srcRect.y(), srcRect.z(), srcRect.w());
3260*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess dst = tcu::getSubregion(getDrawColorbuffer().toSinglesampleAccess(), dstRect.x(),
3261*35238bceSAndroid Build Coastguard Worker dstRect.y(), dstRect.z(), dstRect.w());
3262*35238bceSAndroid Build Coastguard Worker tcu::TextureChannelClass dstClass = tcu::getTextureChannelClass(dst.getFormat().type);
3263*35238bceSAndroid Build Coastguard Worker bool dstIsFloat = dstClass == tcu::TEXTURECHANNELCLASS_FLOATING_POINT ||
3264*35238bceSAndroid Build Coastguard Worker dstClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT ||
3265*35238bceSAndroid Build Coastguard Worker dstClass == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT;
3266*35238bceSAndroid Build Coastguard Worker bool srcIsSRGB = tcu::isSRGB(src.raw().getFormat());
3267*35238bceSAndroid Build Coastguard Worker bool dstIsSRGB = tcu::isSRGB(dst.getFormat());
3268*35238bceSAndroid Build Coastguard Worker const bool convertSRGB = m_sRGBUpdateEnabled && glu::isContextTypeES(getType());
3269*35238bceSAndroid Build Coastguard Worker
3270*35238bceSAndroid Build Coastguard Worker if (!convertSRGB)
3271*35238bceSAndroid Build Coastguard Worker {
3272*35238bceSAndroid Build Coastguard Worker tcu::ConstPixelBufferAccess srcRaw = src.raw();
3273*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat srcFmt = toNonSRGBFormat(srcRaw.getFormat());
3274*35238bceSAndroid Build Coastguard Worker
3275*35238bceSAndroid Build Coastguard Worker srcRaw = tcu::ConstPixelBufferAccess(srcFmt, srcRaw.getWidth(), srcRaw.getHeight(), srcRaw.getDepth(),
3276*35238bceSAndroid Build Coastguard Worker srcRaw.getRowPitch(), srcRaw.getSlicePitch(), srcRaw.getDataPtr());
3277*35238bceSAndroid Build Coastguard Worker src = rr::MultisampleConstPixelBufferAccess::fromMultisampleAccess(srcRaw);
3278*35238bceSAndroid Build Coastguard Worker
3279*35238bceSAndroid Build Coastguard Worker dst = tcu::PixelBufferAccess(toNonSRGBFormat(dst.getFormat()), dst.getWidth(), dst.getHeight(),
3280*35238bceSAndroid Build Coastguard Worker dst.getDepth(), dst.getRowPitch(), dst.getSlicePitch(), dst.getDataPtr());
3281*35238bceSAndroid Build Coastguard Worker }
3282*35238bceSAndroid Build Coastguard Worker
3283*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dstRect.z(); ++x)
3284*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dstRect.w(); ++y)
3285*35238bceSAndroid Build Coastguard Worker {
3286*35238bceSAndroid Build Coastguard Worker int srcX = (flipX) ? (srcRect.z() - x - 1) : (x);
3287*35238bceSAndroid Build Coastguard Worker int srcY = (flipY) ? (srcRect.z() - y - 1) : (y);
3288*35238bceSAndroid Build Coastguard Worker
3289*35238bceSAndroid Build Coastguard Worker if (dstIsFloat || srcIsSRGB)
3290*35238bceSAndroid Build Coastguard Worker {
3291*35238bceSAndroid Build Coastguard Worker Vec4 p = src.raw().getPixel(0, srcX, srcY);
3292*35238bceSAndroid Build Coastguard Worker dst.setPixel((dstIsSRGB && convertSRGB) ? tcu::linearToSRGB(p) : p, x, y);
3293*35238bceSAndroid Build Coastguard Worker }
3294*35238bceSAndroid Build Coastguard Worker else
3295*35238bceSAndroid Build Coastguard Worker dst.setPixel(src.raw().getPixelInt(0, srcX, srcY), x, y);
3296*35238bceSAndroid Build Coastguard Worker }
3297*35238bceSAndroid Build Coastguard Worker }
3298*35238bceSAndroid Build Coastguard Worker
3299*35238bceSAndroid Build Coastguard Worker if (mask & GL_DEPTH_BUFFER_BIT)
3300*35238bceSAndroid Build Coastguard Worker {
3301*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src =
3302*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getReadDepthbuffer(), srcRect.x(), srcRect.y(), srcRect.z(), srcRect.w());
3303*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess dst =
3304*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getDrawDepthbuffer(), dstRect.x(), dstRect.y(), dstRect.z(), dstRect.w());
3305*35238bceSAndroid Build Coastguard Worker
3306*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dstRect.z(); ++x)
3307*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dstRect.w(); ++y)
3308*35238bceSAndroid Build Coastguard Worker {
3309*35238bceSAndroid Build Coastguard Worker int srcX = (flipX) ? (srcRect.z() - x - 1) : (x);
3310*35238bceSAndroid Build Coastguard Worker int srcY = (flipY) ? (srcRect.z() - y - 1) : (y);
3311*35238bceSAndroid Build Coastguard Worker
3312*35238bceSAndroid Build Coastguard Worker writeDepthOnly(dst, 0, x, y, src.raw().getPixel(0, srcX, srcY).x());
3313*35238bceSAndroid Build Coastguard Worker }
3314*35238bceSAndroid Build Coastguard Worker }
3315*35238bceSAndroid Build Coastguard Worker
3316*35238bceSAndroid Build Coastguard Worker if (mask & GL_STENCIL_BUFFER_BIT)
3317*35238bceSAndroid Build Coastguard Worker {
3318*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getStencilMultisampleAccess(
3319*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getReadStencilbuffer(), srcRect.x(), srcRect.y(), srcRect.z(), srcRect.w()));
3320*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess dst = getStencilMultisampleAccess(
3321*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getDrawStencilbuffer(), dstRect.x(), dstRect.y(), dstRect.z(), dstRect.w()));
3322*35238bceSAndroid Build Coastguard Worker
3323*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dstRect.z(); ++x)
3324*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dstRect.w(); ++y)
3325*35238bceSAndroid Build Coastguard Worker {
3326*35238bceSAndroid Build Coastguard Worker int srcX = (flipX) ? (srcRect.z() - x - 1) : (x);
3327*35238bceSAndroid Build Coastguard Worker int srcY = (flipY) ? (srcRect.z() - y - 1) : (y);
3328*35238bceSAndroid Build Coastguard Worker uint32_t srcStencil = src.raw().getPixelUint(0, srcX, srcY).x();
3329*35238bceSAndroid Build Coastguard Worker
3330*35238bceSAndroid Build Coastguard Worker writeMaskedStencil(dst, 0, x, y, srcStencil, m_stencil[rr::FACETYPE_FRONT].writeMask);
3331*35238bceSAndroid Build Coastguard Worker }
3332*35238bceSAndroid Build Coastguard Worker }
3333*35238bceSAndroid Build Coastguard Worker
3334*35238bceSAndroid Build Coastguard Worker return GL_NO_ERROR;
3335*35238bceSAndroid Build Coastguard Worker }
3336*35238bceSAndroid Build Coastguard Worker
blitFramebuffer(int srcX0,int srcY0,int srcX1,int srcY1,int dstX0,int dstY0,int dstX1,int dstY1,uint32_t mask,uint32_t filter)3337*35238bceSAndroid Build Coastguard Worker void ReferenceContext::blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1,
3338*35238bceSAndroid Build Coastguard Worker int dstY1, uint32_t mask, uint32_t filter)
3339*35238bceSAndroid Build Coastguard Worker {
3340*35238bceSAndroid Build Coastguard Worker // p0 in inclusive, p1 exclusive.
3341*35238bceSAndroid Build Coastguard Worker // Negative width/height means swap.
3342*35238bceSAndroid Build Coastguard Worker bool swapSrcX = srcX1 < srcX0;
3343*35238bceSAndroid Build Coastguard Worker bool swapSrcY = srcY1 < srcY0;
3344*35238bceSAndroid Build Coastguard Worker bool swapDstX = dstX1 < dstX0;
3345*35238bceSAndroid Build Coastguard Worker bool swapDstY = dstY1 < dstY0;
3346*35238bceSAndroid Build Coastguard Worker int srcW = de::abs(srcX1 - srcX0);
3347*35238bceSAndroid Build Coastguard Worker int srcH = de::abs(srcY1 - srcY0);
3348*35238bceSAndroid Build Coastguard Worker int dstW = de::abs(dstX1 - dstX0);
3349*35238bceSAndroid Build Coastguard Worker int dstH = de::abs(dstY1 - dstY0);
3350*35238bceSAndroid Build Coastguard Worker bool scale = srcW != dstW || srcH != dstH;
3351*35238bceSAndroid Build Coastguard Worker int srcOriginX = swapSrcX ? srcX1 : srcX0;
3352*35238bceSAndroid Build Coastguard Worker int srcOriginY = swapSrcY ? srcY1 : srcY0;
3353*35238bceSAndroid Build Coastguard Worker int dstOriginX = swapDstX ? dstX1 : dstX0;
3354*35238bceSAndroid Build Coastguard Worker int dstOriginY = swapDstY ? dstY1 : dstY0;
3355*35238bceSAndroid Build Coastguard Worker IVec4 srcRect = IVec4(srcOriginX, srcOriginY, srcW, srcH);
3356*35238bceSAndroid Build Coastguard Worker IVec4 dstRect = IVec4(dstOriginX, dstOriginY, dstW, dstH);
3357*35238bceSAndroid Build Coastguard Worker
3358*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(filter != GL_NEAREST && filter != GL_LINEAR, GL_INVALID_ENUM, RC_RET_VOID);
3359*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0 && filter != GL_NEAREST,
3360*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3361*35238bceSAndroid Build Coastguard Worker
3362*35238bceSAndroid Build Coastguard Worker // Validate that both targets are complete.
3363*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(checkFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE ||
3364*35238bceSAndroid Build Coastguard Worker checkFramebufferStatus(GL_READ_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE,
3365*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3366*35238bceSAndroid Build Coastguard Worker
3367*35238bceSAndroid Build Coastguard Worker // Check samples count is valid
3368*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(getDrawColorbuffer().getNumSamples() != 1, GL_INVALID_OPERATION, RC_RET_VOID);
3369*35238bceSAndroid Build Coastguard Worker
3370*35238bceSAndroid Build Coastguard Worker // Check size restrictions of multisampled case
3371*35238bceSAndroid Build Coastguard Worker if (getReadColorbuffer().getNumSamples() != 1)
3372*35238bceSAndroid Build Coastguard Worker {
3373*35238bceSAndroid Build Coastguard Worker // Src and Dst rect dimensions must be the same
3374*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(srcW != dstW || srcH != dstH, GL_INVALID_OPERATION, RC_RET_VOID);
3375*35238bceSAndroid Build Coastguard Worker
3376*35238bceSAndroid Build Coastguard Worker // Framebuffer formats must match
3377*35238bceSAndroid Build Coastguard Worker if (mask & GL_COLOR_BUFFER_BIT)
3378*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(getReadColorbuffer().raw().getFormat() != getDrawColorbuffer().raw().getFormat(),
3379*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3380*35238bceSAndroid Build Coastguard Worker if (mask & GL_DEPTH_BUFFER_BIT)
3381*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(getReadDepthbuffer().raw().getFormat() != getDrawDepthbuffer().raw().getFormat(),
3382*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3383*35238bceSAndroid Build Coastguard Worker if (mask & GL_STENCIL_BUFFER_BIT)
3384*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(getReadStencilbuffer().raw().getFormat() != getDrawStencilbuffer().raw().getFormat(),
3385*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3386*35238bceSAndroid Build Coastguard Worker }
3387*35238bceSAndroid Build Coastguard Worker
3388*35238bceSAndroid Build Coastguard Worker // Compute actual source rect.
3389*35238bceSAndroid Build Coastguard Worker srcRect = (mask & GL_COLOR_BUFFER_BIT) ? intersect(srcRect, getBufferRect(getReadColorbuffer())) : srcRect;
3390*35238bceSAndroid Build Coastguard Worker srcRect = (mask & GL_DEPTH_BUFFER_BIT) ? intersect(srcRect, getBufferRect(getReadDepthbuffer())) : srcRect;
3391*35238bceSAndroid Build Coastguard Worker srcRect = (mask & GL_STENCIL_BUFFER_BIT) ? intersect(srcRect, getBufferRect(getReadStencilbuffer())) : srcRect;
3392*35238bceSAndroid Build Coastguard Worker
3393*35238bceSAndroid Build Coastguard Worker // Compute destination rect.
3394*35238bceSAndroid Build Coastguard Worker dstRect = (mask & GL_COLOR_BUFFER_BIT) ? intersect(dstRect, getBufferRect(getDrawColorbuffer())) : dstRect;
3395*35238bceSAndroid Build Coastguard Worker dstRect = (mask & GL_DEPTH_BUFFER_BIT) ? intersect(dstRect, getBufferRect(getDrawDepthbuffer())) : dstRect;
3396*35238bceSAndroid Build Coastguard Worker dstRect = (mask & GL_STENCIL_BUFFER_BIT) ? intersect(dstRect, getBufferRect(getDrawStencilbuffer())) : dstRect;
3397*35238bceSAndroid Build Coastguard Worker dstRect = m_scissorEnabled ? intersect(dstRect, m_scissorBox) : dstRect;
3398*35238bceSAndroid Build Coastguard Worker
3399*35238bceSAndroid Build Coastguard Worker if (isEmpty(srcRect) || isEmpty(dstRect))
3400*35238bceSAndroid Build Coastguard Worker return; // Don't attempt copy.
3401*35238bceSAndroid Build Coastguard Worker
3402*35238bceSAndroid Build Coastguard Worker // Multisampled read buffer is a special case
3403*35238bceSAndroid Build Coastguard Worker if (getReadColorbuffer().getNumSamples() != 1)
3404*35238bceSAndroid Build Coastguard Worker {
3405*35238bceSAndroid Build Coastguard Worker uint32_t error =
3406*35238bceSAndroid Build Coastguard Worker blitResolveMultisampleFramebuffer(mask, srcRect, dstRect, swapSrcX ^ swapDstX, swapSrcY ^ swapDstY);
3407*35238bceSAndroid Build Coastguard Worker
3408*35238bceSAndroid Build Coastguard Worker if (error != GL_NO_ERROR)
3409*35238bceSAndroid Build Coastguard Worker setError(error);
3410*35238bceSAndroid Build Coastguard Worker
3411*35238bceSAndroid Build Coastguard Worker return;
3412*35238bceSAndroid Build Coastguard Worker }
3413*35238bceSAndroid Build Coastguard Worker
3414*35238bceSAndroid Build Coastguard Worker // \note Multisample pixel buffers can now be accessed like non-multisampled because multisample read buffer case is already handled. => sample count must be 1
3415*35238bceSAndroid Build Coastguard Worker
3416*35238bceSAndroid Build Coastguard Worker // Coordinate transformation:
3417*35238bceSAndroid Build Coastguard Worker // Dst offset space -> dst rectangle space -> src rectangle space -> src offset space.
3418*35238bceSAndroid Build Coastguard Worker tcu::Mat3 transform = tcu::translationMatrix(Vec2((float)(srcX0 - srcRect.x()), (float)(srcY0 - srcRect.y()))) *
3419*35238bceSAndroid Build Coastguard Worker tcu::Mat3(Vec3((float)(srcX1 - srcX0) / (float)(dstX1 - dstX0),
3420*35238bceSAndroid Build Coastguard Worker (float)(srcY1 - srcY0) / (float)(dstY1 - dstY0), 1.0f)) *
3421*35238bceSAndroid Build Coastguard Worker tcu::translationMatrix(Vec2((float)(dstRect.x() - dstX0), (float)(dstRect.y() - dstY0)));
3422*35238bceSAndroid Build Coastguard Worker
3423*35238bceSAndroid Build Coastguard Worker if (mask & GL_COLOR_BUFFER_BIT)
3424*35238bceSAndroid Build Coastguard Worker {
3425*35238bceSAndroid Build Coastguard Worker tcu::ConstPixelBufferAccess src = tcu::getSubregion(getReadColorbuffer().toSinglesampleAccess(), srcRect.x(),
3426*35238bceSAndroid Build Coastguard Worker srcRect.y(), srcRect.z(), srcRect.w());
3427*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess dst = tcu::getSubregion(getDrawColorbuffer().toSinglesampleAccess(), dstRect.x(),
3428*35238bceSAndroid Build Coastguard Worker dstRect.y(), dstRect.z(), dstRect.w());
3429*35238bceSAndroid Build Coastguard Worker tcu::TextureChannelClass dstClass = tcu::getTextureChannelClass(dst.getFormat().type);
3430*35238bceSAndroid Build Coastguard Worker bool dstIsFloat = dstClass == tcu::TEXTURECHANNELCLASS_FLOATING_POINT ||
3431*35238bceSAndroid Build Coastguard Worker dstClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT ||
3432*35238bceSAndroid Build Coastguard Worker dstClass == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT;
3433*35238bceSAndroid Build Coastguard Worker tcu::Sampler::FilterMode sFilter =
3434*35238bceSAndroid Build Coastguard Worker (scale && filter == GL_LINEAR) ? tcu::Sampler::LINEAR : tcu::Sampler::NEAREST;
3435*35238bceSAndroid Build Coastguard Worker tcu::Sampler sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE,
3436*35238bceSAndroid Build Coastguard Worker sFilter, sFilter, 0.0f /* lod threshold */, false /* non-normalized coords */);
3437*35238bceSAndroid Build Coastguard Worker bool srcIsSRGB = tcu::isSRGB(src.getFormat());
3438*35238bceSAndroid Build Coastguard Worker bool dstIsSRGB = tcu::isSRGB(dst.getFormat());
3439*35238bceSAndroid Build Coastguard Worker const bool convertSRGB = m_sRGBUpdateEnabled && glu::isContextTypeES(getType());
3440*35238bceSAndroid Build Coastguard Worker
3441*35238bceSAndroid Build Coastguard Worker if (!convertSRGB)
3442*35238bceSAndroid Build Coastguard Worker {
3443*35238bceSAndroid Build Coastguard Worker src = tcu::ConstPixelBufferAccess(toNonSRGBFormat(src.getFormat()), src.getWidth(), src.getHeight(),
3444*35238bceSAndroid Build Coastguard Worker src.getDepth(), src.getRowPitch(), src.getSlicePitch(), src.getDataPtr());
3445*35238bceSAndroid Build Coastguard Worker dst = tcu::PixelBufferAccess(toNonSRGBFormat(dst.getFormat()), dst.getWidth(), dst.getHeight(),
3446*35238bceSAndroid Build Coastguard Worker dst.getDepth(), dst.getRowPitch(), dst.getSlicePitch(), dst.getDataPtr());
3447*35238bceSAndroid Build Coastguard Worker }
3448*35238bceSAndroid Build Coastguard Worker
3449*35238bceSAndroid Build Coastguard Worker // \note We don't check for unsupported conversions, unlike spec requires.
3450*35238bceSAndroid Build Coastguard Worker
3451*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < dstRect.w(); yo++)
3452*35238bceSAndroid Build Coastguard Worker {
3453*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < dstRect.z(); xo++)
3454*35238bceSAndroid Build Coastguard Worker {
3455*35238bceSAndroid Build Coastguard Worker float dX = (float)xo + 0.5f;
3456*35238bceSAndroid Build Coastguard Worker float dY = (float)yo + 0.5f;
3457*35238bceSAndroid Build Coastguard Worker
3458*35238bceSAndroid Build Coastguard Worker // \note Only affine part is used.
3459*35238bceSAndroid Build Coastguard Worker float sX = transform(0, 0) * dX + transform(0, 1) * dY + transform(0, 2);
3460*35238bceSAndroid Build Coastguard Worker float sY = transform(1, 0) * dX + transform(1, 1) * dY + transform(1, 2);
3461*35238bceSAndroid Build Coastguard Worker
3462*35238bceSAndroid Build Coastguard Worker // do not copy pixels outside the modified source region (modified by buffer intersection)
3463*35238bceSAndroid Build Coastguard Worker if (sX < 0.0f || sX >= (float)srcRect.z() || sY < 0.0f || sY >= (float)srcRect.w())
3464*35238bceSAndroid Build Coastguard Worker continue;
3465*35238bceSAndroid Build Coastguard Worker
3466*35238bceSAndroid Build Coastguard Worker if (dstIsFloat || srcIsSRGB || filter == tcu::Sampler::LINEAR)
3467*35238bceSAndroid Build Coastguard Worker {
3468*35238bceSAndroid Build Coastguard Worker Vec4 p = src.sample2D(sampler, sampler.minFilter, sX, sY, 0);
3469*35238bceSAndroid Build Coastguard Worker dst.setPixel((dstIsSRGB && convertSRGB) ? tcu::linearToSRGB(p) : p, xo, yo);
3470*35238bceSAndroid Build Coastguard Worker }
3471*35238bceSAndroid Build Coastguard Worker else
3472*35238bceSAndroid Build Coastguard Worker dst.setPixel(src.getPixelInt(deFloorFloatToInt32(sX), deFloorFloatToInt32(sY)), xo, yo);
3473*35238bceSAndroid Build Coastguard Worker }
3474*35238bceSAndroid Build Coastguard Worker }
3475*35238bceSAndroid Build Coastguard Worker }
3476*35238bceSAndroid Build Coastguard Worker
3477*35238bceSAndroid Build Coastguard Worker if ((mask & GL_DEPTH_BUFFER_BIT) && m_depthMask)
3478*35238bceSAndroid Build Coastguard Worker {
3479*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getDepthMultisampleAccess(
3480*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getReadDepthbuffer(), srcRect.x(), srcRect.y(), srcRect.z(), srcRect.w()));
3481*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess dst = getDepthMultisampleAccess(
3482*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getDrawDepthbuffer(), dstRect.x(), dstRect.y(), dstRect.z(), dstRect.w()));
3483*35238bceSAndroid Build Coastguard Worker
3484*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < dstRect.w(); yo++)
3485*35238bceSAndroid Build Coastguard Worker {
3486*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < dstRect.z(); xo++)
3487*35238bceSAndroid Build Coastguard Worker {
3488*35238bceSAndroid Build Coastguard Worker const int sampleNdx = 0; // multisample read buffer case is already handled
3489*35238bceSAndroid Build Coastguard Worker
3490*35238bceSAndroid Build Coastguard Worker float dX = (float)xo + 0.5f;
3491*35238bceSAndroid Build Coastguard Worker float dY = (float)yo + 0.5f;
3492*35238bceSAndroid Build Coastguard Worker float sX = transform(0, 0) * dX + transform(0, 1) * dY + transform(0, 2);
3493*35238bceSAndroid Build Coastguard Worker float sY = transform(1, 0) * dX + transform(1, 1) * dY + transform(1, 2);
3494*35238bceSAndroid Build Coastguard Worker
3495*35238bceSAndroid Build Coastguard Worker writeDepthOnly(dst, sampleNdx, xo, yo,
3496*35238bceSAndroid Build Coastguard Worker src.raw().getPixDepth(sampleNdx, deFloorFloatToInt32(sX), deFloorFloatToInt32(sY)));
3497*35238bceSAndroid Build Coastguard Worker }
3498*35238bceSAndroid Build Coastguard Worker }
3499*35238bceSAndroid Build Coastguard Worker }
3500*35238bceSAndroid Build Coastguard Worker
3501*35238bceSAndroid Build Coastguard Worker if (mask & GL_STENCIL_BUFFER_BIT)
3502*35238bceSAndroid Build Coastguard Worker {
3503*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess src = getStencilMultisampleAccess(
3504*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getReadStencilbuffer(), srcRect.x(), srcRect.y(), srcRect.z(), srcRect.w()));
3505*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess dst = getStencilMultisampleAccess(
3506*35238bceSAndroid Build Coastguard Worker rr::getSubregion(getDrawStencilbuffer(), dstRect.x(), dstRect.y(), dstRect.z(), dstRect.w()));
3507*35238bceSAndroid Build Coastguard Worker
3508*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < dstRect.w(); yo++)
3509*35238bceSAndroid Build Coastguard Worker {
3510*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < dstRect.z(); xo++)
3511*35238bceSAndroid Build Coastguard Worker {
3512*35238bceSAndroid Build Coastguard Worker const int sampleNdx = 0; // multisample read buffer case is already handled
3513*35238bceSAndroid Build Coastguard Worker
3514*35238bceSAndroid Build Coastguard Worker float dX = (float)xo + 0.5f;
3515*35238bceSAndroid Build Coastguard Worker float dY = (float)yo + 0.5f;
3516*35238bceSAndroid Build Coastguard Worker float sX = transform(0, 0) * dX + transform(0, 1) * dY + transform(0, 2);
3517*35238bceSAndroid Build Coastguard Worker float sY = transform(1, 0) * dX + transform(1, 1) * dY + transform(1, 2);
3518*35238bceSAndroid Build Coastguard Worker uint32_t srcStencil =
3519*35238bceSAndroid Build Coastguard Worker src.raw().getPixelUint(sampleNdx, deFloorFloatToInt32(sX), deFloorFloatToInt32(sY)).x();
3520*35238bceSAndroid Build Coastguard Worker
3521*35238bceSAndroid Build Coastguard Worker writeMaskedStencil(dst, sampleNdx, xo, yo, srcStencil, m_stencil[rr::FACETYPE_FRONT].writeMask);
3522*35238bceSAndroid Build Coastguard Worker }
3523*35238bceSAndroid Build Coastguard Worker }
3524*35238bceSAndroid Build Coastguard Worker }
3525*35238bceSAndroid Build Coastguard Worker }
3526*35238bceSAndroid Build Coastguard Worker
invalidateSubFramebuffer(uint32_t target,int numAttachments,const uint32_t * attachments,int x,int y,int width,int height)3527*35238bceSAndroid Build Coastguard Worker void ReferenceContext::invalidateSubFramebuffer(uint32_t target, int numAttachments, const uint32_t *attachments, int x,
3528*35238bceSAndroid Build Coastguard Worker int y, int width, int height)
3529*35238bceSAndroid Build Coastguard Worker {
3530*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(target != GL_FRAMEBUFFER, GL_INVALID_ENUM, RC_RET_VOID);
3531*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((numAttachments < 0) || (numAttachments > 1 && attachments == DE_NULL), GL_INVALID_VALUE, RC_RET_VOID);
3532*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(width < 0 || height < 0, GL_INVALID_VALUE, RC_RET_VOID);
3533*35238bceSAndroid Build Coastguard Worker
3534*35238bceSAndroid Build Coastguard Worker // \todo [2012-07-17 pyry] Support multiple color attachments.
3535*35238bceSAndroid Build Coastguard Worker
3536*35238bceSAndroid Build Coastguard Worker const Vec4 colorClearValue(0.0f);
3537*35238bceSAndroid Build Coastguard Worker const float depthClearValue = 1.0f;
3538*35238bceSAndroid Build Coastguard Worker const int stencilClearValue = 0;
3539*35238bceSAndroid Build Coastguard Worker
3540*35238bceSAndroid Build Coastguard Worker bool isFboBound = m_drawFramebufferBinding != DE_NULL;
3541*35238bceSAndroid Build Coastguard Worker bool discardBuffers[3] = {false, false, false}; // Color, depth, stencil
3542*35238bceSAndroid Build Coastguard Worker
3543*35238bceSAndroid Build Coastguard Worker for (int attNdx = 0; attNdx < numAttachments; attNdx++)
3544*35238bceSAndroid Build Coastguard Worker {
3545*35238bceSAndroid Build Coastguard Worker bool isColor = attachments[attNdx] == (isFboBound ? GL_COLOR_ATTACHMENT0 : GL_COLOR);
3546*35238bceSAndroid Build Coastguard Worker bool isDepth = attachments[attNdx] == (isFboBound ? GL_DEPTH_ATTACHMENT : GL_DEPTH);
3547*35238bceSAndroid Build Coastguard Worker bool isStencil = attachments[attNdx] == (isFboBound ? GL_STENCIL_ATTACHMENT : GL_STENCIL);
3548*35238bceSAndroid Build Coastguard Worker bool isDepthStencil = isFboBound && attachments[attNdx] == GL_DEPTH_STENCIL_ATTACHMENT;
3549*35238bceSAndroid Build Coastguard Worker
3550*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!isColor && !isDepth && !isStencil && !isDepthStencil, GL_INVALID_VALUE, RC_RET_VOID);
3551*35238bceSAndroid Build Coastguard Worker
3552*35238bceSAndroid Build Coastguard Worker if (isColor)
3553*35238bceSAndroid Build Coastguard Worker discardBuffers[0] = true;
3554*35238bceSAndroid Build Coastguard Worker if (isDepth || isDepthStencil)
3555*35238bceSAndroid Build Coastguard Worker discardBuffers[1] = true;
3556*35238bceSAndroid Build Coastguard Worker if (isStencil || isDepthStencil)
3557*35238bceSAndroid Build Coastguard Worker discardBuffers[2] = true;
3558*35238bceSAndroid Build Coastguard Worker }
3559*35238bceSAndroid Build Coastguard Worker
3560*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 3; ndx++)
3561*35238bceSAndroid Build Coastguard Worker {
3562*35238bceSAndroid Build Coastguard Worker if (!discardBuffers[ndx])
3563*35238bceSAndroid Build Coastguard Worker continue;
3564*35238bceSAndroid Build Coastguard Worker
3565*35238bceSAndroid Build Coastguard Worker bool isColor = ndx == 0;
3566*35238bceSAndroid Build Coastguard Worker bool isDepth = ndx == 1;
3567*35238bceSAndroid Build Coastguard Worker bool isStencil = ndx == 2;
3568*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess buf = isColor ? getDrawColorbuffer() :
3569*35238bceSAndroid Build Coastguard Worker isDepth ? getDepthMultisampleAccess(getDrawDepthbuffer()) :
3570*35238bceSAndroid Build Coastguard Worker getStencilMultisampleAccess(getDrawStencilbuffer());
3571*35238bceSAndroid Build Coastguard Worker
3572*35238bceSAndroid Build Coastguard Worker if (isEmpty(buf))
3573*35238bceSAndroid Build Coastguard Worker continue;
3574*35238bceSAndroid Build Coastguard Worker
3575*35238bceSAndroid Build Coastguard Worker tcu::IVec4 area =
3576*35238bceSAndroid Build Coastguard Worker intersect(tcu::IVec4(0, 0, buf.raw().getHeight(), buf.raw().getDepth()), tcu::IVec4(x, y, width, height));
3577*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access = rr::getSubregion(buf, area.x(), area.y(), area.z(), area.w());
3578*35238bceSAndroid Build Coastguard Worker
3579*35238bceSAndroid Build Coastguard Worker if (isColor)
3580*35238bceSAndroid Build Coastguard Worker rr::clear(access, colorClearValue);
3581*35238bceSAndroid Build Coastguard Worker else if (isDepth)
3582*35238bceSAndroid Build Coastguard Worker rr::clear(access, tcu::Vec4(depthClearValue));
3583*35238bceSAndroid Build Coastguard Worker else if (isStencil)
3584*35238bceSAndroid Build Coastguard Worker rr::clear(access, tcu::IVec4(stencilClearValue));
3585*35238bceSAndroid Build Coastguard Worker }
3586*35238bceSAndroid Build Coastguard Worker }
3587*35238bceSAndroid Build Coastguard Worker
invalidateFramebuffer(uint32_t target,int numAttachments,const uint32_t * attachments)3588*35238bceSAndroid Build Coastguard Worker void ReferenceContext::invalidateFramebuffer(uint32_t target, int numAttachments, const uint32_t *attachments)
3589*35238bceSAndroid Build Coastguard Worker {
3590*35238bceSAndroid Build Coastguard Worker // \todo [2012-07-17 pyry] Support multiple color attachments.
3591*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess colorBuf0 = getDrawColorbuffer();
3592*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess depthBuf = getDrawDepthbuffer();
3593*35238bceSAndroid Build Coastguard Worker rr::MultisampleConstPixelBufferAccess stencilBuf = getDrawStencilbuffer();
3594*35238bceSAndroid Build Coastguard Worker int width = 0;
3595*35238bceSAndroid Build Coastguard Worker int height = 0;
3596*35238bceSAndroid Build Coastguard Worker
3597*35238bceSAndroid Build Coastguard Worker width = de::max(width, colorBuf0.raw().getHeight());
3598*35238bceSAndroid Build Coastguard Worker width = de::max(width, depthBuf.raw().getHeight());
3599*35238bceSAndroid Build Coastguard Worker width = de::max(width, stencilBuf.raw().getHeight());
3600*35238bceSAndroid Build Coastguard Worker
3601*35238bceSAndroid Build Coastguard Worker height = de::max(height, colorBuf0.raw().getDepth());
3602*35238bceSAndroid Build Coastguard Worker height = de::max(height, depthBuf.raw().getDepth());
3603*35238bceSAndroid Build Coastguard Worker height = de::max(height, stencilBuf.raw().getDepth());
3604*35238bceSAndroid Build Coastguard Worker
3605*35238bceSAndroid Build Coastguard Worker invalidateSubFramebuffer(target, numAttachments, attachments, 0, 0, width, height);
3606*35238bceSAndroid Build Coastguard Worker }
3607*35238bceSAndroid Build Coastguard Worker
clear(uint32_t buffers)3608*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clear(uint32_t buffers)
3609*35238bceSAndroid Build Coastguard Worker {
3610*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((buffers & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0, GL_INVALID_VALUE,
3611*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
3612*35238bceSAndroid Build Coastguard Worker
3613*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess colorBuf0 = getDrawColorbuffer();
3614*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess depthBuf = getDrawDepthbuffer();
3615*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess stencilBuf = getDrawStencilbuffer();
3616*35238bceSAndroid Build Coastguard Worker IVec4 baseArea = m_scissorEnabled ? m_scissorBox : IVec4(0, 0, 0x7fffffff, 0x7fffffff);
3617*35238bceSAndroid Build Coastguard Worker IVec4 colorArea = intersect(baseArea, getBufferRect(colorBuf0));
3618*35238bceSAndroid Build Coastguard Worker IVec4 depthArea = intersect(baseArea, getBufferRect(depthBuf));
3619*35238bceSAndroid Build Coastguard Worker IVec4 stencilArea = intersect(baseArea, getBufferRect(stencilBuf));
3620*35238bceSAndroid Build Coastguard Worker bool hasColor0 = !isEmpty(colorArea);
3621*35238bceSAndroid Build Coastguard Worker bool hasDepth = !isEmpty(depthArea);
3622*35238bceSAndroid Build Coastguard Worker bool hasStencil = !isEmpty(stencilArea);
3623*35238bceSAndroid Build Coastguard Worker
3624*35238bceSAndroid Build Coastguard Worker if (hasColor0 && (buffers & GL_COLOR_BUFFER_BIT) != 0)
3625*35238bceSAndroid Build Coastguard Worker {
3626*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access =
3627*35238bceSAndroid Build Coastguard Worker rr::getSubregion(colorBuf0, colorArea.x(), colorArea.y(), colorArea.z(), colorArea.w());
3628*35238bceSAndroid Build Coastguard Worker bool isSRGB = tcu::isSRGB(colorBuf0.raw().getFormat());
3629*35238bceSAndroid Build Coastguard Worker Vec4 c = (isSRGB && m_sRGBUpdateEnabled) ? tcu::linearToSRGB(m_clearColor) : m_clearColor;
3630*35238bceSAndroid Build Coastguard Worker bool maskUsed = !m_colorMask[0] || !m_colorMask[1] || !m_colorMask[2] || !m_colorMask[3];
3631*35238bceSAndroid Build Coastguard Worker bool maskZero = !m_colorMask[0] && !m_colorMask[1] && !m_colorMask[2] && !m_colorMask[3];
3632*35238bceSAndroid Build Coastguard Worker
3633*35238bceSAndroid Build Coastguard Worker if (!maskUsed)
3634*35238bceSAndroid Build Coastguard Worker rr::clear(access, c);
3635*35238bceSAndroid Build Coastguard Worker else if (!maskZero)
3636*35238bceSAndroid Build Coastguard Worker {
3637*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.raw().getDepth(); y++)
3638*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.raw().getHeight(); x++)
3639*35238bceSAndroid Build Coastguard Worker for (int s = 0; s < access.getNumSamples(); s++)
3640*35238bceSAndroid Build Coastguard Worker access.raw().setPixel(tcu::select(c, access.raw().getPixel(s, x, y), m_colorMask), s, x, y);
3641*35238bceSAndroid Build Coastguard Worker }
3642*35238bceSAndroid Build Coastguard Worker // else all channels masked out
3643*35238bceSAndroid Build Coastguard Worker }
3644*35238bceSAndroid Build Coastguard Worker
3645*35238bceSAndroid Build Coastguard Worker if (hasDepth && (buffers & GL_DEPTH_BUFFER_BIT) != 0 && m_depthMask)
3646*35238bceSAndroid Build Coastguard Worker {
3647*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access = getDepthMultisampleAccess(
3648*35238bceSAndroid Build Coastguard Worker rr::getSubregion(depthBuf, depthArea.x(), depthArea.y(), depthArea.z(), depthArea.w()));
3649*35238bceSAndroid Build Coastguard Worker rr::clearDepth(access, m_clearDepth);
3650*35238bceSAndroid Build Coastguard Worker }
3651*35238bceSAndroid Build Coastguard Worker
3652*35238bceSAndroid Build Coastguard Worker if (hasStencil && (buffers & GL_STENCIL_BUFFER_BIT) != 0)
3653*35238bceSAndroid Build Coastguard Worker {
3654*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access = getStencilMultisampleAccess(
3655*35238bceSAndroid Build Coastguard Worker rr::getSubregion(stencilBuf, stencilArea.x(), stencilArea.y(), stencilArea.z(), stencilArea.w()));
3656*35238bceSAndroid Build Coastguard Worker int stencilBits = getNumStencilBits(stencilBuf.raw().getFormat());
3657*35238bceSAndroid Build Coastguard Worker int stencil = maskStencil(stencilBits, m_clearStencil);
3658*35238bceSAndroid Build Coastguard Worker
3659*35238bceSAndroid Build Coastguard Worker if ((m_stencil[rr::FACETYPE_FRONT].writeMask & ((1u << stencilBits) - 1u)) != ((1u << stencilBits) - 1u))
3660*35238bceSAndroid Build Coastguard Worker {
3661*35238bceSAndroid Build Coastguard Worker // Slow path where depth or stencil is masked out in write.
3662*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.raw().getDepth(); y++)
3663*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.raw().getHeight(); x++)
3664*35238bceSAndroid Build Coastguard Worker for (int s = 0; s < access.getNumSamples(); s++)
3665*35238bceSAndroid Build Coastguard Worker writeMaskedStencil(access, s, x, y, stencil, m_stencil[rr::FACETYPE_FRONT].writeMask);
3666*35238bceSAndroid Build Coastguard Worker }
3667*35238bceSAndroid Build Coastguard Worker else
3668*35238bceSAndroid Build Coastguard Worker rr::clearStencil(access, stencil);
3669*35238bceSAndroid Build Coastguard Worker }
3670*35238bceSAndroid Build Coastguard Worker }
3671*35238bceSAndroid Build Coastguard Worker
clearBufferiv(uint32_t buffer,int drawbuffer,const int * value)3672*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearBufferiv(uint32_t buffer, int drawbuffer, const int *value)
3673*35238bceSAndroid Build Coastguard Worker {
3674*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(buffer != GL_COLOR && buffer != GL_STENCIL, GL_INVALID_ENUM, RC_RET_VOID);
3675*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(drawbuffer != 0, GL_INVALID_VALUE, RC_RET_VOID); // \todo [2012-04-06 pyry] MRT support.
3676*35238bceSAndroid Build Coastguard Worker
3677*35238bceSAndroid Build Coastguard Worker IVec4 baseArea = m_scissorEnabled ? m_scissorBox : IVec4(0, 0, 0x7fffffff, 0x7fffffff);
3678*35238bceSAndroid Build Coastguard Worker
3679*35238bceSAndroid Build Coastguard Worker if (buffer == GL_COLOR)
3680*35238bceSAndroid Build Coastguard Worker {
3681*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess colorBuf = getDrawColorbuffer();
3682*35238bceSAndroid Build Coastguard Worker bool maskUsed = !m_colorMask[0] || !m_colorMask[1] || !m_colorMask[2] || !m_colorMask[3];
3683*35238bceSAndroid Build Coastguard Worker bool maskZero = !m_colorMask[0] && !m_colorMask[1] && !m_colorMask[2] && !m_colorMask[3];
3684*35238bceSAndroid Build Coastguard Worker IVec4 area = intersect(baseArea, getBufferRect(colorBuf));
3685*35238bceSAndroid Build Coastguard Worker
3686*35238bceSAndroid Build Coastguard Worker if (!isEmpty(area) && !maskZero)
3687*35238bceSAndroid Build Coastguard Worker {
3688*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access =
3689*35238bceSAndroid Build Coastguard Worker rr::getSubregion(colorBuf, area.x(), area.y(), area.z(), area.w());
3690*35238bceSAndroid Build Coastguard Worker IVec4 color(value[0], value[1], value[2], value[3]);
3691*35238bceSAndroid Build Coastguard Worker
3692*35238bceSAndroid Build Coastguard Worker if (!maskUsed)
3693*35238bceSAndroid Build Coastguard Worker rr::clear(access, color);
3694*35238bceSAndroid Build Coastguard Worker else
3695*35238bceSAndroid Build Coastguard Worker {
3696*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.raw().getDepth(); y++)
3697*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.raw().getHeight(); x++)
3698*35238bceSAndroid Build Coastguard Worker for (int s = 0; s < access.getNumSamples(); s++)
3699*35238bceSAndroid Build Coastguard Worker access.raw().setPixel(tcu::select(color, access.raw().getPixelInt(s, x, y), m_colorMask), s,
3700*35238bceSAndroid Build Coastguard Worker x, y);
3701*35238bceSAndroid Build Coastguard Worker }
3702*35238bceSAndroid Build Coastguard Worker }
3703*35238bceSAndroid Build Coastguard Worker }
3704*35238bceSAndroid Build Coastguard Worker else
3705*35238bceSAndroid Build Coastguard Worker {
3706*35238bceSAndroid Build Coastguard Worker TCU_CHECK_INTERNAL(buffer == GL_STENCIL);
3707*35238bceSAndroid Build Coastguard Worker
3708*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess stencilBuf = getDrawStencilbuffer();
3709*35238bceSAndroid Build Coastguard Worker IVec4 area = intersect(baseArea, getBufferRect(stencilBuf));
3710*35238bceSAndroid Build Coastguard Worker
3711*35238bceSAndroid Build Coastguard Worker if (!isEmpty(area) && m_stencil[rr::FACETYPE_FRONT].writeMask != 0)
3712*35238bceSAndroid Build Coastguard Worker {
3713*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access =
3714*35238bceSAndroid Build Coastguard Worker getStencilMultisampleAccess(rr::getSubregion(stencilBuf, area.x(), area.y(), area.z(), area.w()));
3715*35238bceSAndroid Build Coastguard Worker int stencil = value[0];
3716*35238bceSAndroid Build Coastguard Worker
3717*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.raw().getDepth(); y++)
3718*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.raw().getHeight(); x++)
3719*35238bceSAndroid Build Coastguard Worker for (int s = 0; s < access.getNumSamples(); s++)
3720*35238bceSAndroid Build Coastguard Worker writeMaskedStencil(access, s, x, y, stencil, m_stencil[rr::FACETYPE_FRONT].writeMask);
3721*35238bceSAndroid Build Coastguard Worker }
3722*35238bceSAndroid Build Coastguard Worker }
3723*35238bceSAndroid Build Coastguard Worker }
3724*35238bceSAndroid Build Coastguard Worker
clearBufferfv(uint32_t buffer,int drawbuffer,const float * value)3725*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearBufferfv(uint32_t buffer, int drawbuffer, const float *value)
3726*35238bceSAndroid Build Coastguard Worker {
3727*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(buffer != GL_COLOR && buffer != GL_DEPTH, GL_INVALID_ENUM, RC_RET_VOID);
3728*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(drawbuffer != 0, GL_INVALID_VALUE, RC_RET_VOID); // \todo [2012-04-06 pyry] MRT support.
3729*35238bceSAndroid Build Coastguard Worker
3730*35238bceSAndroid Build Coastguard Worker IVec4 baseArea = m_scissorEnabled ? m_scissorBox : IVec4(0, 0, 0x7fffffff, 0x7fffffff);
3731*35238bceSAndroid Build Coastguard Worker
3732*35238bceSAndroid Build Coastguard Worker if (buffer == GL_COLOR)
3733*35238bceSAndroid Build Coastguard Worker {
3734*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess colorBuf = getDrawColorbuffer();
3735*35238bceSAndroid Build Coastguard Worker bool maskUsed = !m_colorMask[0] || !m_colorMask[1] || !m_colorMask[2] || !m_colorMask[3];
3736*35238bceSAndroid Build Coastguard Worker bool maskZero = !m_colorMask[0] && !m_colorMask[1] && !m_colorMask[2] && !m_colorMask[3];
3737*35238bceSAndroid Build Coastguard Worker IVec4 area = intersect(baseArea, getBufferRect(colorBuf));
3738*35238bceSAndroid Build Coastguard Worker
3739*35238bceSAndroid Build Coastguard Worker if (!isEmpty(area) && !maskZero)
3740*35238bceSAndroid Build Coastguard Worker {
3741*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access =
3742*35238bceSAndroid Build Coastguard Worker rr::getSubregion(colorBuf, area.x(), area.y(), area.z(), area.w());
3743*35238bceSAndroid Build Coastguard Worker Vec4 color(value[0], value[1], value[2], value[3]);
3744*35238bceSAndroid Build Coastguard Worker
3745*35238bceSAndroid Build Coastguard Worker if (m_sRGBUpdateEnabled && tcu::isSRGB(access.raw().getFormat()))
3746*35238bceSAndroid Build Coastguard Worker color = tcu::linearToSRGB(color);
3747*35238bceSAndroid Build Coastguard Worker
3748*35238bceSAndroid Build Coastguard Worker if (!maskUsed)
3749*35238bceSAndroid Build Coastguard Worker rr::clear(access, color);
3750*35238bceSAndroid Build Coastguard Worker else
3751*35238bceSAndroid Build Coastguard Worker {
3752*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.raw().getDepth(); y++)
3753*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.raw().getHeight(); x++)
3754*35238bceSAndroid Build Coastguard Worker for (int s = 0; s < access.getNumSamples(); s++)
3755*35238bceSAndroid Build Coastguard Worker access.raw().setPixel(tcu::select(color, access.raw().getPixel(s, x, y), m_colorMask), s, x,
3756*35238bceSAndroid Build Coastguard Worker y);
3757*35238bceSAndroid Build Coastguard Worker }
3758*35238bceSAndroid Build Coastguard Worker }
3759*35238bceSAndroid Build Coastguard Worker }
3760*35238bceSAndroid Build Coastguard Worker else
3761*35238bceSAndroid Build Coastguard Worker {
3762*35238bceSAndroid Build Coastguard Worker TCU_CHECK_INTERNAL(buffer == GL_DEPTH);
3763*35238bceSAndroid Build Coastguard Worker
3764*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess depthBuf = getDrawDepthbuffer();
3765*35238bceSAndroid Build Coastguard Worker IVec4 area = intersect(baseArea, getBufferRect(depthBuf));
3766*35238bceSAndroid Build Coastguard Worker
3767*35238bceSAndroid Build Coastguard Worker if (!isEmpty(area) && m_depthMask)
3768*35238bceSAndroid Build Coastguard Worker {
3769*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access =
3770*35238bceSAndroid Build Coastguard Worker rr::getSubregion(depthBuf, area.x(), area.y(), area.z(), area.w());
3771*35238bceSAndroid Build Coastguard Worker float depth = value[0];
3772*35238bceSAndroid Build Coastguard Worker
3773*35238bceSAndroid Build Coastguard Worker rr::clearDepth(access, depth);
3774*35238bceSAndroid Build Coastguard Worker }
3775*35238bceSAndroid Build Coastguard Worker }
3776*35238bceSAndroid Build Coastguard Worker }
3777*35238bceSAndroid Build Coastguard Worker
clearBufferuiv(uint32_t buffer,int drawbuffer,const uint32_t * value)3778*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearBufferuiv(uint32_t buffer, int drawbuffer, const uint32_t *value)
3779*35238bceSAndroid Build Coastguard Worker {
3780*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(buffer != GL_COLOR, GL_INVALID_ENUM, RC_RET_VOID);
3781*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(drawbuffer != 0, GL_INVALID_VALUE, RC_RET_VOID); // \todo [2012-04-06 pyry] MRT support.
3782*35238bceSAndroid Build Coastguard Worker
3783*35238bceSAndroid Build Coastguard Worker IVec4 baseArea = m_scissorEnabled ? m_scissorBox : IVec4(0, 0, 0x7fffffff, 0x7fffffff);
3784*35238bceSAndroid Build Coastguard Worker
3785*35238bceSAndroid Build Coastguard Worker TCU_CHECK_INTERNAL(buffer == GL_COLOR);
3786*35238bceSAndroid Build Coastguard Worker {
3787*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess colorBuf = getDrawColorbuffer();
3788*35238bceSAndroid Build Coastguard Worker bool maskUsed = !m_colorMask[0] || !m_colorMask[1] || !m_colorMask[2] || !m_colorMask[3];
3789*35238bceSAndroid Build Coastguard Worker bool maskZero = !m_colorMask[0] && !m_colorMask[1] && !m_colorMask[2] && !m_colorMask[3];
3790*35238bceSAndroid Build Coastguard Worker IVec4 area = intersect(baseArea, getBufferRect(colorBuf));
3791*35238bceSAndroid Build Coastguard Worker
3792*35238bceSAndroid Build Coastguard Worker if (!isEmpty(area) && !maskZero)
3793*35238bceSAndroid Build Coastguard Worker {
3794*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess access =
3795*35238bceSAndroid Build Coastguard Worker rr::getSubregion(colorBuf, area.x(), area.y(), area.z(), area.w());
3796*35238bceSAndroid Build Coastguard Worker tcu::UVec4 color(value[0], value[1], value[2], value[3]);
3797*35238bceSAndroid Build Coastguard Worker
3798*35238bceSAndroid Build Coastguard Worker if (!maskUsed)
3799*35238bceSAndroid Build Coastguard Worker rr::clear(access, color.asInt());
3800*35238bceSAndroid Build Coastguard Worker else
3801*35238bceSAndroid Build Coastguard Worker {
3802*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.raw().getDepth(); y++)
3803*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.raw().getHeight(); x++)
3804*35238bceSAndroid Build Coastguard Worker for (int s = 0; s < access.getNumSamples(); s++)
3805*35238bceSAndroid Build Coastguard Worker access.raw().setPixel(tcu::select(color, access.raw().getPixelUint(s, x, y), m_colorMask),
3806*35238bceSAndroid Build Coastguard Worker s, x, y);
3807*35238bceSAndroid Build Coastguard Worker }
3808*35238bceSAndroid Build Coastguard Worker }
3809*35238bceSAndroid Build Coastguard Worker }
3810*35238bceSAndroid Build Coastguard Worker }
3811*35238bceSAndroid Build Coastguard Worker
clearBufferfi(uint32_t buffer,int drawbuffer,float depth,int stencil)3812*35238bceSAndroid Build Coastguard Worker void ReferenceContext::clearBufferfi(uint32_t buffer, int drawbuffer, float depth, int stencil)
3813*35238bceSAndroid Build Coastguard Worker {
3814*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(buffer != GL_DEPTH_STENCIL, GL_INVALID_ENUM, RC_RET_VOID);
3815*35238bceSAndroid Build Coastguard Worker clearBufferfv(GL_DEPTH, drawbuffer, &depth);
3816*35238bceSAndroid Build Coastguard Worker clearBufferiv(GL_STENCIL, drawbuffer, &stencil);
3817*35238bceSAndroid Build Coastguard Worker }
3818*35238bceSAndroid Build Coastguard Worker
bindVertexArray(uint32_t array)3819*35238bceSAndroid Build Coastguard Worker void ReferenceContext::bindVertexArray(uint32_t array)
3820*35238bceSAndroid Build Coastguard Worker {
3821*35238bceSAndroid Build Coastguard Worker rc::VertexArray *vertexArrayObject = DE_NULL;
3822*35238bceSAndroid Build Coastguard Worker
3823*35238bceSAndroid Build Coastguard Worker if (array != 0)
3824*35238bceSAndroid Build Coastguard Worker {
3825*35238bceSAndroid Build Coastguard Worker vertexArrayObject = m_vertexArrays.find(array);
3826*35238bceSAndroid Build Coastguard Worker if (!vertexArrayObject)
3827*35238bceSAndroid Build Coastguard Worker {
3828*35238bceSAndroid Build Coastguard Worker vertexArrayObject = new rc::VertexArray(array, m_limits.maxVertexAttribs);
3829*35238bceSAndroid Build Coastguard Worker m_vertexArrays.insert(vertexArrayObject);
3830*35238bceSAndroid Build Coastguard Worker }
3831*35238bceSAndroid Build Coastguard Worker }
3832*35238bceSAndroid Build Coastguard Worker
3833*35238bceSAndroid Build Coastguard Worker // Create new references
3834*35238bceSAndroid Build Coastguard Worker if (vertexArrayObject)
3835*35238bceSAndroid Build Coastguard Worker m_vertexArrays.acquireReference(vertexArrayObject);
3836*35238bceSAndroid Build Coastguard Worker
3837*35238bceSAndroid Build Coastguard Worker // Remove old references
3838*35238bceSAndroid Build Coastguard Worker if (m_vertexArrayBinding)
3839*35238bceSAndroid Build Coastguard Worker m_vertexArrays.releaseReference(m_vertexArrayBinding);
3840*35238bceSAndroid Build Coastguard Worker
3841*35238bceSAndroid Build Coastguard Worker m_vertexArrayBinding = vertexArrayObject;
3842*35238bceSAndroid Build Coastguard Worker }
3843*35238bceSAndroid Build Coastguard Worker
genVertexArrays(int numArrays,uint32_t * vertexArrays)3844*35238bceSAndroid Build Coastguard Worker void ReferenceContext::genVertexArrays(int numArrays, uint32_t *vertexArrays)
3845*35238bceSAndroid Build Coastguard Worker {
3846*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!vertexArrays, GL_INVALID_VALUE, RC_RET_VOID);
3847*35238bceSAndroid Build Coastguard Worker
3848*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numArrays; ndx++)
3849*35238bceSAndroid Build Coastguard Worker vertexArrays[ndx] = m_vertexArrays.allocateName();
3850*35238bceSAndroid Build Coastguard Worker }
3851*35238bceSAndroid Build Coastguard Worker
deleteVertexArrays(int numArrays,const uint32_t * vertexArrays)3852*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteVertexArrays(int numArrays, const uint32_t *vertexArrays)
3853*35238bceSAndroid Build Coastguard Worker {
3854*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numArrays; i++)
3855*35238bceSAndroid Build Coastguard Worker {
3856*35238bceSAndroid Build Coastguard Worker uint32_t name = vertexArrays[i];
3857*35238bceSAndroid Build Coastguard Worker VertexArray *vertexArray = name ? m_vertexArrays.find(name) : DE_NULL;
3858*35238bceSAndroid Build Coastguard Worker
3859*35238bceSAndroid Build Coastguard Worker if (vertexArray)
3860*35238bceSAndroid Build Coastguard Worker deleteVertexArray(vertexArray);
3861*35238bceSAndroid Build Coastguard Worker }
3862*35238bceSAndroid Build Coastguard Worker }
3863*35238bceSAndroid Build Coastguard Worker
vertexAttribPointer(uint32_t index,int rawSize,uint32_t type,bool normalized,int stride,const void * pointer)3864*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttribPointer(uint32_t index, int rawSize, uint32_t type, bool normalized, int stride,
3865*35238bceSAndroid Build Coastguard Worker const void *pointer)
3866*35238bceSAndroid Build Coastguard Worker {
3867*35238bceSAndroid Build Coastguard Worker const bool allowBGRA = !glu::isContextTypeES(getType());
3868*35238bceSAndroid Build Coastguard Worker const int effectiveSize = (allowBGRA && rawSize == GL_BGRA) ? (4) : (rawSize);
3869*35238bceSAndroid Build Coastguard Worker
3870*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3871*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(effectiveSize <= 0 || effectiveSize > 4, GL_INVALID_VALUE, RC_RET_VOID);
3872*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(type != GL_BYTE && type != GL_UNSIGNED_BYTE && type != GL_SHORT && type != GL_UNSIGNED_SHORT &&
3873*35238bceSAndroid Build Coastguard Worker type != GL_INT && type != GL_UNSIGNED_INT && type != GL_FIXED && type != GL_DOUBLE &&
3874*35238bceSAndroid Build Coastguard Worker type != GL_FLOAT && type != GL_HALF_FLOAT && type != GL_INT_2_10_10_10_REV &&
3875*35238bceSAndroid Build Coastguard Worker type != GL_UNSIGNED_INT_2_10_10_10_REV,
3876*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
3877*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(normalized != GL_TRUE && normalized != GL_FALSE, GL_INVALID_ENUM, RC_RET_VOID);
3878*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(stride < 0, GL_INVALID_VALUE, RC_RET_VOID);
3879*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && effectiveSize != 4,
3880*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3881*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_vertexArrayBinding != DE_NULL && m_arrayBufferBinding == DE_NULL && pointer != DE_NULL,
3882*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3883*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(allowBGRA && rawSize == GL_BGRA && type != GL_INT_2_10_10_10_REV &&
3884*35238bceSAndroid Build Coastguard Worker type != GL_UNSIGNED_INT_2_10_10_10_REV && type != GL_UNSIGNED_BYTE,
3885*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3886*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(allowBGRA && rawSize == GL_BGRA && normalized == GL_FALSE, GL_INVALID_OPERATION, RC_RET_VOID);
3887*35238bceSAndroid Build Coastguard Worker
3888*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
3889*35238bceSAndroid Build Coastguard Worker
3890*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].size = rawSize;
3891*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].stride = stride;
3892*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].type = type;
3893*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].normalized = normalized == GL_TRUE;
3894*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].integer = false;
3895*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].pointer = pointer;
3896*35238bceSAndroid Build Coastguard Worker
3897*35238bceSAndroid Build Coastguard Worker // acquire new reference
3898*35238bceSAndroid Build Coastguard Worker if (m_arrayBufferBinding)
3899*35238bceSAndroid Build Coastguard Worker m_buffers.acquireReference(m_arrayBufferBinding);
3900*35238bceSAndroid Build Coastguard Worker
3901*35238bceSAndroid Build Coastguard Worker // release old reference
3902*35238bceSAndroid Build Coastguard Worker if (vao.m_arrays[index].bufferBinding)
3903*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(vao.m_arrays[index].bufferBinding);
3904*35238bceSAndroid Build Coastguard Worker
3905*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].bufferDeleted = false;
3906*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].bufferBinding = m_arrayBufferBinding;
3907*35238bceSAndroid Build Coastguard Worker }
3908*35238bceSAndroid Build Coastguard Worker
vertexAttribIPointer(uint32_t index,int size,uint32_t type,int stride,const void * pointer)3909*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttribIPointer(uint32_t index, int size, uint32_t type, int stride, const void *pointer)
3910*35238bceSAndroid Build Coastguard Worker {
3911*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3912*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(size <= 0 || size > 4, GL_INVALID_VALUE, RC_RET_VOID);
3913*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(type != GL_BYTE && type != GL_UNSIGNED_BYTE && type != GL_SHORT && type != GL_UNSIGNED_SHORT &&
3914*35238bceSAndroid Build Coastguard Worker type != GL_INT && type != GL_UNSIGNED_INT,
3915*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
3916*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(stride < 0, GL_INVALID_VALUE, RC_RET_VOID);
3917*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_vertexArrayBinding != DE_NULL && m_arrayBufferBinding == DE_NULL && pointer != DE_NULL,
3918*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
3919*35238bceSAndroid Build Coastguard Worker
3920*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
3921*35238bceSAndroid Build Coastguard Worker
3922*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].size = size;
3923*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].stride = stride;
3924*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].type = type;
3925*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].normalized = false;
3926*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].integer = true;
3927*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].pointer = pointer;
3928*35238bceSAndroid Build Coastguard Worker
3929*35238bceSAndroid Build Coastguard Worker // acquire new reference
3930*35238bceSAndroid Build Coastguard Worker if (m_arrayBufferBinding)
3931*35238bceSAndroid Build Coastguard Worker m_buffers.acquireReference(m_arrayBufferBinding);
3932*35238bceSAndroid Build Coastguard Worker
3933*35238bceSAndroid Build Coastguard Worker // release old reference
3934*35238bceSAndroid Build Coastguard Worker if (vao.m_arrays[index].bufferBinding)
3935*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(vao.m_arrays[index].bufferBinding);
3936*35238bceSAndroid Build Coastguard Worker
3937*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].bufferDeleted = false;
3938*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].bufferBinding = m_arrayBufferBinding;
3939*35238bceSAndroid Build Coastguard Worker }
3940*35238bceSAndroid Build Coastguard Worker
enableVertexAttribArray(uint32_t index)3941*35238bceSAndroid Build Coastguard Worker void ReferenceContext::enableVertexAttribArray(uint32_t index)
3942*35238bceSAndroid Build Coastguard Worker {
3943*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3944*35238bceSAndroid Build Coastguard Worker
3945*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
3946*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].enabled = true;
3947*35238bceSAndroid Build Coastguard Worker }
3948*35238bceSAndroid Build Coastguard Worker
disableVertexAttribArray(uint32_t index)3949*35238bceSAndroid Build Coastguard Worker void ReferenceContext::disableVertexAttribArray(uint32_t index)
3950*35238bceSAndroid Build Coastguard Worker {
3951*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3952*35238bceSAndroid Build Coastguard Worker
3953*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
3954*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].enabled = false;
3955*35238bceSAndroid Build Coastguard Worker }
3956*35238bceSAndroid Build Coastguard Worker
vertexAttribDivisor(uint32_t index,uint32_t divisor)3957*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttribDivisor(uint32_t index, uint32_t divisor)
3958*35238bceSAndroid Build Coastguard Worker {
3959*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3960*35238bceSAndroid Build Coastguard Worker
3961*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
3962*35238bceSAndroid Build Coastguard Worker vao.m_arrays[index].divisor = divisor;
3963*35238bceSAndroid Build Coastguard Worker }
3964*35238bceSAndroid Build Coastguard Worker
vertexAttrib1f(uint32_t index,float x)3965*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttrib1f(uint32_t index, float x)
3966*35238bceSAndroid Build Coastguard Worker {
3967*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3968*35238bceSAndroid Build Coastguard Worker
3969*35238bceSAndroid Build Coastguard Worker m_currentAttribs[index] = rr::GenericVec4(tcu::Vec4(x, 0, 0, 1));
3970*35238bceSAndroid Build Coastguard Worker }
3971*35238bceSAndroid Build Coastguard Worker
vertexAttrib2f(uint32_t index,float x,float y)3972*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttrib2f(uint32_t index, float x, float y)
3973*35238bceSAndroid Build Coastguard Worker {
3974*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3975*35238bceSAndroid Build Coastguard Worker
3976*35238bceSAndroid Build Coastguard Worker m_currentAttribs[index] = rr::GenericVec4(tcu::Vec4(x, y, 0, 1));
3977*35238bceSAndroid Build Coastguard Worker }
3978*35238bceSAndroid Build Coastguard Worker
vertexAttrib3f(uint32_t index,float x,float y,float z)3979*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttrib3f(uint32_t index, float x, float y, float z)
3980*35238bceSAndroid Build Coastguard Worker {
3981*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3982*35238bceSAndroid Build Coastguard Worker
3983*35238bceSAndroid Build Coastguard Worker m_currentAttribs[index] = rr::GenericVec4(tcu::Vec4(x, y, z, 1));
3984*35238bceSAndroid Build Coastguard Worker }
3985*35238bceSAndroid Build Coastguard Worker
vertexAttrib4f(uint32_t index,float x,float y,float z,float w)3986*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttrib4f(uint32_t index, float x, float y, float z, float w)
3987*35238bceSAndroid Build Coastguard Worker {
3988*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3989*35238bceSAndroid Build Coastguard Worker
3990*35238bceSAndroid Build Coastguard Worker m_currentAttribs[index] = rr::GenericVec4(tcu::Vec4(x, y, z, w));
3991*35238bceSAndroid Build Coastguard Worker }
3992*35238bceSAndroid Build Coastguard Worker
vertexAttribI4i(uint32_t index,int32_t x,int32_t y,int32_t z,int32_t w)3993*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttribI4i(uint32_t index, int32_t x, int32_t y, int32_t z, int32_t w)
3994*35238bceSAndroid Build Coastguard Worker {
3995*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
3996*35238bceSAndroid Build Coastguard Worker
3997*35238bceSAndroid Build Coastguard Worker m_currentAttribs[index] = rr::GenericVec4(tcu::IVec4(x, y, z, w));
3998*35238bceSAndroid Build Coastguard Worker }
3999*35238bceSAndroid Build Coastguard Worker
vertexAttribI4ui(uint32_t index,uint32_t x,uint32_t y,uint32_t z,uint32_t w)4000*35238bceSAndroid Build Coastguard Worker void ReferenceContext::vertexAttribI4ui(uint32_t index, uint32_t x, uint32_t y, uint32_t z, uint32_t w)
4001*35238bceSAndroid Build Coastguard Worker {
4002*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(index >= (uint32_t)m_limits.maxVertexAttribs, GL_INVALID_VALUE, RC_RET_VOID);
4003*35238bceSAndroid Build Coastguard Worker
4004*35238bceSAndroid Build Coastguard Worker m_currentAttribs[index] = rr::GenericVec4(tcu::UVec4(x, y, z, w));
4005*35238bceSAndroid Build Coastguard Worker }
4006*35238bceSAndroid Build Coastguard Worker
getAttribLocation(uint32_t program,const char * name)4007*35238bceSAndroid Build Coastguard Worker int32_t ReferenceContext::getAttribLocation(uint32_t program, const char *name)
4008*35238bceSAndroid Build Coastguard Worker {
4009*35238bceSAndroid Build Coastguard Worker ShaderProgramObjectContainer *shaderProg = m_programs.find(program);
4010*35238bceSAndroid Build Coastguard Worker
4011*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(shaderProg == DE_NULL, GL_INVALID_OPERATION, -1);
4012*35238bceSAndroid Build Coastguard Worker
4013*35238bceSAndroid Build Coastguard Worker if (name)
4014*35238bceSAndroid Build Coastguard Worker {
4015*35238bceSAndroid Build Coastguard Worker std::string nameString(name);
4016*35238bceSAndroid Build Coastguard Worker
4017*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 0; ndx < shaderProg->m_program->m_attributeNames.size(); ++ndx)
4018*35238bceSAndroid Build Coastguard Worker if (shaderProg->m_program->m_attributeNames[ndx] == nameString)
4019*35238bceSAndroid Build Coastguard Worker return (int)ndx;
4020*35238bceSAndroid Build Coastguard Worker }
4021*35238bceSAndroid Build Coastguard Worker
4022*35238bceSAndroid Build Coastguard Worker return -1;
4023*35238bceSAndroid Build Coastguard Worker }
4024*35238bceSAndroid Build Coastguard Worker
uniformv(int32_t location,glu::DataType type,int32_t count,const void * v)4025*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniformv(int32_t location, glu::DataType type, int32_t count, const void *v)
4026*35238bceSAndroid Build Coastguard Worker {
4027*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram == DE_NULL, GL_INVALID_OPERATION, RC_RET_VOID);
4028*35238bceSAndroid Build Coastguard Worker
4029*35238bceSAndroid Build Coastguard Worker std::vector<sglr::UniformSlot> &uniforms = m_currentProgram->m_program->m_uniforms;
4030*35238bceSAndroid Build Coastguard Worker
4031*35238bceSAndroid Build Coastguard Worker if (location == -1)
4032*35238bceSAndroid Build Coastguard Worker return;
4033*35238bceSAndroid Build Coastguard Worker
4034*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(location < 0 || (size_t)location >= uniforms.size(), GL_INVALID_OPERATION, RC_RET_VOID);
4035*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(uniforms[location].type != type, GL_INVALID_OPERATION, RC_RET_VOID);
4036*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(count != 1, GL_INVALID_OPERATION, RC_RET_VOID); // \todo [2013-12-13 pyry] Array uniforms.
4037*35238bceSAndroid Build Coastguard Worker
4038*35238bceSAndroid Build Coastguard Worker {
4039*35238bceSAndroid Build Coastguard Worker const int scalarSize = glu::getDataTypeScalarSize(type);
4040*35238bceSAndroid Build Coastguard Worker DE_ASSERT(scalarSize * sizeof(uint32_t) <= sizeof(uniforms[location].value));
4041*35238bceSAndroid Build Coastguard Worker deMemcpy(&uniforms[location].value, v, scalarSize * (int)sizeof(uint32_t));
4042*35238bceSAndroid Build Coastguard Worker }
4043*35238bceSAndroid Build Coastguard Worker }
4044*35238bceSAndroid Build Coastguard Worker
uniform1iv(int32_t location,int32_t count,const int32_t * v)4045*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform1iv(int32_t location, int32_t count, const int32_t *v)
4046*35238bceSAndroid Build Coastguard Worker {
4047*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram == DE_NULL, GL_INVALID_OPERATION, RC_RET_VOID);
4048*35238bceSAndroid Build Coastguard Worker
4049*35238bceSAndroid Build Coastguard Worker std::vector<sglr::UniformSlot> &uniforms = m_currentProgram->m_program->m_uniforms;
4050*35238bceSAndroid Build Coastguard Worker
4051*35238bceSAndroid Build Coastguard Worker if (location == -1)
4052*35238bceSAndroid Build Coastguard Worker return;
4053*35238bceSAndroid Build Coastguard Worker
4054*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(location < 0 || (size_t)location >= uniforms.size(), GL_INVALID_OPERATION, RC_RET_VOID);
4055*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(count != 1, GL_INVALID_OPERATION, RC_RET_VOID); // \todo [2013-12-13 pyry] Array uniforms.
4056*35238bceSAndroid Build Coastguard Worker
4057*35238bceSAndroid Build Coastguard Worker switch (uniforms[location].type)
4058*35238bceSAndroid Build Coastguard Worker {
4059*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT:
4060*35238bceSAndroid Build Coastguard Worker uniforms[location].value.i = *v;
4061*35238bceSAndroid Build Coastguard Worker return;
4062*35238bceSAndroid Build Coastguard Worker
4063*35238bceSAndroid Build Coastguard Worker // \note texture unit is stored to value
4064*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_2D:
4065*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_2D:
4066*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_2D:
4067*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_CUBE:
4068*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_CUBE:
4069*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_CUBE:
4070*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_2D_ARRAY:
4071*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_2D_ARRAY:
4072*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_2D_ARRAY:
4073*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_3D:
4074*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_3D:
4075*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_3D:
4076*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_CUBE_ARRAY:
4077*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_CUBE_ARRAY:
4078*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_CUBE_ARRAY:
4079*35238bceSAndroid Build Coastguard Worker uniforms[location].value.i = *v;
4080*35238bceSAndroid Build Coastguard Worker return;
4081*35238bceSAndroid Build Coastguard Worker
4082*35238bceSAndroid Build Coastguard Worker default:
4083*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_OPERATION);
4084*35238bceSAndroid Build Coastguard Worker return;
4085*35238bceSAndroid Build Coastguard Worker }
4086*35238bceSAndroid Build Coastguard Worker }
4087*35238bceSAndroid Build Coastguard Worker
uniform1f(int32_t location,const float v0)4088*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform1f(int32_t location, const float v0)
4089*35238bceSAndroid Build Coastguard Worker {
4090*35238bceSAndroid Build Coastguard Worker uniform1fv(location, 1, &v0);
4091*35238bceSAndroid Build Coastguard Worker }
4092*35238bceSAndroid Build Coastguard Worker
uniform1i(int32_t location,int32_t v0)4093*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform1i(int32_t location, int32_t v0)
4094*35238bceSAndroid Build Coastguard Worker {
4095*35238bceSAndroid Build Coastguard Worker uniform1iv(location, 1, &v0);
4096*35238bceSAndroid Build Coastguard Worker }
4097*35238bceSAndroid Build Coastguard Worker
uniform1fv(int32_t location,int32_t count,const float * v)4098*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform1fv(int32_t location, int32_t count, const float *v)
4099*35238bceSAndroid Build Coastguard Worker {
4100*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_FLOAT, count, v);
4101*35238bceSAndroid Build Coastguard Worker }
4102*35238bceSAndroid Build Coastguard Worker
uniform2fv(int32_t location,int32_t count,const float * v)4103*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform2fv(int32_t location, int32_t count, const float *v)
4104*35238bceSAndroid Build Coastguard Worker {
4105*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_FLOAT_VEC2, count, v);
4106*35238bceSAndroid Build Coastguard Worker }
4107*35238bceSAndroid Build Coastguard Worker
uniform3fv(int32_t location,int32_t count,const float * v)4108*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform3fv(int32_t location, int32_t count, const float *v)
4109*35238bceSAndroid Build Coastguard Worker {
4110*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_FLOAT_VEC3, count, v);
4111*35238bceSAndroid Build Coastguard Worker }
4112*35238bceSAndroid Build Coastguard Worker
uniform4fv(int32_t location,int32_t count,const float * v)4113*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform4fv(int32_t location, int32_t count, const float *v)
4114*35238bceSAndroid Build Coastguard Worker {
4115*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_FLOAT_VEC4, count, v);
4116*35238bceSAndroid Build Coastguard Worker }
4117*35238bceSAndroid Build Coastguard Worker
uniform2iv(int32_t location,int32_t count,const int32_t * v)4118*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform2iv(int32_t location, int32_t count, const int32_t *v)
4119*35238bceSAndroid Build Coastguard Worker {
4120*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_INT_VEC2, count, v);
4121*35238bceSAndroid Build Coastguard Worker }
4122*35238bceSAndroid Build Coastguard Worker
uniform3iv(int32_t location,int32_t count,const int32_t * v)4123*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform3iv(int32_t location, int32_t count, const int32_t *v)
4124*35238bceSAndroid Build Coastguard Worker {
4125*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_INT_VEC3, count, v);
4126*35238bceSAndroid Build Coastguard Worker }
4127*35238bceSAndroid Build Coastguard Worker
uniform4iv(int32_t location,int32_t count,const int32_t * v)4128*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniform4iv(int32_t location, int32_t count, const int32_t *v)
4129*35238bceSAndroid Build Coastguard Worker {
4130*35238bceSAndroid Build Coastguard Worker uniformv(location, glu::TYPE_INT_VEC4, count, v);
4131*35238bceSAndroid Build Coastguard Worker }
4132*35238bceSAndroid Build Coastguard Worker
uniformMatrix3fv(int32_t location,int32_t count,bool transpose,const float * value)4133*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniformMatrix3fv(int32_t location, int32_t count, bool transpose, const float *value)
4134*35238bceSAndroid Build Coastguard Worker {
4135*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram == DE_NULL, GL_INVALID_OPERATION, RC_RET_VOID);
4136*35238bceSAndroid Build Coastguard Worker
4137*35238bceSAndroid Build Coastguard Worker std::vector<sglr::UniformSlot> &uniforms = m_currentProgram->m_program->m_uniforms;
4138*35238bceSAndroid Build Coastguard Worker
4139*35238bceSAndroid Build Coastguard Worker if (location == -1)
4140*35238bceSAndroid Build Coastguard Worker return;
4141*35238bceSAndroid Build Coastguard Worker
4142*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(location < 0 || (size_t)location >= uniforms.size(), GL_INVALID_OPERATION, RC_RET_VOID);
4143*35238bceSAndroid Build Coastguard Worker
4144*35238bceSAndroid Build Coastguard Worker if (count == 0)
4145*35238bceSAndroid Build Coastguard Worker return;
4146*35238bceSAndroid Build Coastguard Worker
4147*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(transpose != GL_TRUE && transpose != GL_FALSE, GL_INVALID_ENUM, RC_RET_VOID);
4148*35238bceSAndroid Build Coastguard Worker
4149*35238bceSAndroid Build Coastguard Worker switch (uniforms[location].type)
4150*35238bceSAndroid Build Coastguard Worker {
4151*35238bceSAndroid Build Coastguard Worker case glu::TYPE_FLOAT_MAT3:
4152*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(count > 1, GL_INVALID_OPERATION, RC_RET_VOID);
4153*35238bceSAndroid Build Coastguard Worker
4154*35238bceSAndroid Build Coastguard Worker if (transpose == GL_FALSE) // input is column major => transpose from column major to internal row major
4155*35238bceSAndroid Build Coastguard Worker for (int row = 0; row < 3; ++row)
4156*35238bceSAndroid Build Coastguard Worker for (int col = 0; col < 3; ++col)
4157*35238bceSAndroid Build Coastguard Worker uniforms[location].value.m3[row * 3 + col] = value[col * 3 + row];
4158*35238bceSAndroid Build Coastguard Worker else // input is row major
4159*35238bceSAndroid Build Coastguard Worker for (int row = 0; row < 3; ++row)
4160*35238bceSAndroid Build Coastguard Worker for (int col = 0; col < 3; ++col)
4161*35238bceSAndroid Build Coastguard Worker uniforms[location].value.m3[row * 3 + col] = value[row * 3 + col];
4162*35238bceSAndroid Build Coastguard Worker
4163*35238bceSAndroid Build Coastguard Worker break;
4164*35238bceSAndroid Build Coastguard Worker
4165*35238bceSAndroid Build Coastguard Worker default:
4166*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_OPERATION);
4167*35238bceSAndroid Build Coastguard Worker return;
4168*35238bceSAndroid Build Coastguard Worker }
4169*35238bceSAndroid Build Coastguard Worker }
4170*35238bceSAndroid Build Coastguard Worker
uniformMatrix4fv(int32_t location,int32_t count,bool transpose,const float * value)4171*35238bceSAndroid Build Coastguard Worker void ReferenceContext::uniformMatrix4fv(int32_t location, int32_t count, bool transpose, const float *value)
4172*35238bceSAndroid Build Coastguard Worker {
4173*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram == DE_NULL, GL_INVALID_OPERATION, RC_RET_VOID);
4174*35238bceSAndroid Build Coastguard Worker
4175*35238bceSAndroid Build Coastguard Worker std::vector<sglr::UniformSlot> &uniforms = m_currentProgram->m_program->m_uniforms;
4176*35238bceSAndroid Build Coastguard Worker
4177*35238bceSAndroid Build Coastguard Worker if (location == -1)
4178*35238bceSAndroid Build Coastguard Worker return;
4179*35238bceSAndroid Build Coastguard Worker
4180*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(location < 0 || (size_t)location >= uniforms.size(), GL_INVALID_OPERATION, RC_RET_VOID);
4181*35238bceSAndroid Build Coastguard Worker
4182*35238bceSAndroid Build Coastguard Worker if (count == 0)
4183*35238bceSAndroid Build Coastguard Worker return;
4184*35238bceSAndroid Build Coastguard Worker
4185*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(transpose != GL_TRUE && transpose != GL_FALSE, GL_INVALID_ENUM, RC_RET_VOID);
4186*35238bceSAndroid Build Coastguard Worker
4187*35238bceSAndroid Build Coastguard Worker switch (uniforms[location].type)
4188*35238bceSAndroid Build Coastguard Worker {
4189*35238bceSAndroid Build Coastguard Worker case glu::TYPE_FLOAT_MAT4:
4190*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(count > 1, GL_INVALID_OPERATION, RC_RET_VOID);
4191*35238bceSAndroid Build Coastguard Worker
4192*35238bceSAndroid Build Coastguard Worker if (transpose == GL_FALSE) // input is column major => transpose from column major to internal row major
4193*35238bceSAndroid Build Coastguard Worker for (int row = 0; row < 4; ++row)
4194*35238bceSAndroid Build Coastguard Worker for (int col = 0; col < 4; ++col)
4195*35238bceSAndroid Build Coastguard Worker uniforms[location].value.m4[row * 3 + col] = value[col * 3 + row];
4196*35238bceSAndroid Build Coastguard Worker else // input is row major
4197*35238bceSAndroid Build Coastguard Worker for (int row = 0; row < 4; ++row)
4198*35238bceSAndroid Build Coastguard Worker for (int col = 0; col < 4; ++col)
4199*35238bceSAndroid Build Coastguard Worker uniforms[location].value.m4[row * 3 + col] = value[row * 3 + col];
4200*35238bceSAndroid Build Coastguard Worker
4201*35238bceSAndroid Build Coastguard Worker break;
4202*35238bceSAndroid Build Coastguard Worker
4203*35238bceSAndroid Build Coastguard Worker default:
4204*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_OPERATION);
4205*35238bceSAndroid Build Coastguard Worker return;
4206*35238bceSAndroid Build Coastguard Worker }
4207*35238bceSAndroid Build Coastguard Worker }
4208*35238bceSAndroid Build Coastguard Worker
getUniformLocation(uint32_t program,const char * name)4209*35238bceSAndroid Build Coastguard Worker int32_t ReferenceContext::getUniformLocation(uint32_t program, const char *name)
4210*35238bceSAndroid Build Coastguard Worker {
4211*35238bceSAndroid Build Coastguard Worker ShaderProgramObjectContainer *shaderProg = m_programs.find(program);
4212*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(shaderProg == DE_NULL, GL_INVALID_OPERATION, -1);
4213*35238bceSAndroid Build Coastguard Worker
4214*35238bceSAndroid Build Coastguard Worker std::vector<sglr::UniformSlot> &uniforms = shaderProg->m_program->m_uniforms;
4215*35238bceSAndroid Build Coastguard Worker
4216*35238bceSAndroid Build Coastguard Worker for (size_t i = 0; i < uniforms.size(); ++i)
4217*35238bceSAndroid Build Coastguard Worker if (name && deStringEqual(uniforms[i].name.c_str(), name))
4218*35238bceSAndroid Build Coastguard Worker return (int)i;
4219*35238bceSAndroid Build Coastguard Worker
4220*35238bceSAndroid Build Coastguard Worker return -1;
4221*35238bceSAndroid Build Coastguard Worker }
4222*35238bceSAndroid Build Coastguard Worker
lineWidth(float w)4223*35238bceSAndroid Build Coastguard Worker void ReferenceContext::lineWidth(float w)
4224*35238bceSAndroid Build Coastguard Worker {
4225*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(w < 0.0f, GL_INVALID_VALUE, RC_RET_VOID);
4226*35238bceSAndroid Build Coastguard Worker m_lineWidth = w;
4227*35238bceSAndroid Build Coastguard Worker }
4228*35238bceSAndroid Build Coastguard Worker
deleteVertexArray(rc::VertexArray * vertexArray)4229*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteVertexArray(rc::VertexArray *vertexArray)
4230*35238bceSAndroid Build Coastguard Worker {
4231*35238bceSAndroid Build Coastguard Worker if (m_vertexArrayBinding == vertexArray)
4232*35238bceSAndroid Build Coastguard Worker bindVertexArray(0);
4233*35238bceSAndroid Build Coastguard Worker
4234*35238bceSAndroid Build Coastguard Worker if (vertexArray->m_elementArrayBufferBinding)
4235*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(vertexArray->m_elementArrayBufferBinding);
4236*35238bceSAndroid Build Coastguard Worker
4237*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 0; ndx < vertexArray->m_arrays.size(); ++ndx)
4238*35238bceSAndroid Build Coastguard Worker if (vertexArray->m_arrays[ndx].bufferBinding)
4239*35238bceSAndroid Build Coastguard Worker m_buffers.releaseReference(vertexArray->m_arrays[ndx].bufferBinding);
4240*35238bceSAndroid Build Coastguard Worker
4241*35238bceSAndroid Build Coastguard Worker DE_ASSERT(vertexArray->getRefCount() == 1);
4242*35238bceSAndroid Build Coastguard Worker m_vertexArrays.releaseReference(vertexArray);
4243*35238bceSAndroid Build Coastguard Worker }
4244*35238bceSAndroid Build Coastguard Worker
deleteProgramObject(rc::ShaderProgramObjectContainer * sp)4245*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteProgramObject(rc::ShaderProgramObjectContainer *sp)
4246*35238bceSAndroid Build Coastguard Worker {
4247*35238bceSAndroid Build Coastguard Worker // Unbinding program will delete it
4248*35238bceSAndroid Build Coastguard Worker if (m_currentProgram == sp && sp->m_deleteFlag)
4249*35238bceSAndroid Build Coastguard Worker {
4250*35238bceSAndroid Build Coastguard Worker useProgram(0);
4251*35238bceSAndroid Build Coastguard Worker return;
4252*35238bceSAndroid Build Coastguard Worker }
4253*35238bceSAndroid Build Coastguard Worker
4254*35238bceSAndroid Build Coastguard Worker // Unbinding program will NOT delete it
4255*35238bceSAndroid Build Coastguard Worker if (m_currentProgram == sp)
4256*35238bceSAndroid Build Coastguard Worker useProgram(0);
4257*35238bceSAndroid Build Coastguard Worker
4258*35238bceSAndroid Build Coastguard Worker DE_ASSERT(sp->getRefCount() == 1);
4259*35238bceSAndroid Build Coastguard Worker m_programs.releaseReference(sp);
4260*35238bceSAndroid Build Coastguard Worker }
4261*35238bceSAndroid Build Coastguard Worker
drawArrays(uint32_t mode,int first,int count)4262*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawArrays(uint32_t mode, int first, int count)
4263*35238bceSAndroid Build Coastguard Worker {
4264*35238bceSAndroid Build Coastguard Worker drawArraysInstanced(mode, first, count, 1);
4265*35238bceSAndroid Build Coastguard Worker }
4266*35238bceSAndroid Build Coastguard Worker
drawArraysInstanced(uint32_t mode,int first,int count,int instanceCount)4267*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawArraysInstanced(uint32_t mode, int first, int count, int instanceCount)
4268*35238bceSAndroid Build Coastguard Worker {
4269*35238bceSAndroid Build Coastguard Worker // Error conditions
4270*35238bceSAndroid Build Coastguard Worker {
4271*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(first < 0 || count < 0 || instanceCount < 0, GL_INVALID_VALUE, RC_RET_VOID);
4272*35238bceSAndroid Build Coastguard Worker
4273*35238bceSAndroid Build Coastguard Worker if (!predrawErrorChecks(mode))
4274*35238bceSAndroid Build Coastguard Worker return;
4275*35238bceSAndroid Build Coastguard Worker }
4276*35238bceSAndroid Build Coastguard Worker
4277*35238bceSAndroid Build Coastguard Worker // All is ok
4278*35238bceSAndroid Build Coastguard Worker {
4279*35238bceSAndroid Build Coastguard Worker const rr::PrimitiveType primitiveType = sglr::rr_util::mapGLPrimitiveType(mode);
4280*35238bceSAndroid Build Coastguard Worker
4281*35238bceSAndroid Build Coastguard Worker drawWithReference(rr::PrimitiveList(primitiveType, count, first), instanceCount);
4282*35238bceSAndroid Build Coastguard Worker }
4283*35238bceSAndroid Build Coastguard Worker }
4284*35238bceSAndroid Build Coastguard Worker
drawElements(uint32_t mode,int count,uint32_t type,const void * indices)4285*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawElements(uint32_t mode, int count, uint32_t type, const void *indices)
4286*35238bceSAndroid Build Coastguard Worker {
4287*35238bceSAndroid Build Coastguard Worker drawElementsInstanced(mode, count, type, indices, 1);
4288*35238bceSAndroid Build Coastguard Worker }
4289*35238bceSAndroid Build Coastguard Worker
drawElementsBaseVertex(uint32_t mode,int count,uint32_t type,const void * indices,int baseVertex)4290*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawElementsBaseVertex(uint32_t mode, int count, uint32_t type, const void *indices,
4291*35238bceSAndroid Build Coastguard Worker int baseVertex)
4292*35238bceSAndroid Build Coastguard Worker {
4293*35238bceSAndroid Build Coastguard Worker drawElementsInstancedBaseVertex(mode, count, type, indices, 1, baseVertex);
4294*35238bceSAndroid Build Coastguard Worker }
4295*35238bceSAndroid Build Coastguard Worker
drawElementsInstanced(uint32_t mode,int count,uint32_t type,const void * indices,int instanceCount)4296*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawElementsInstanced(uint32_t mode, int count, uint32_t type, const void *indices,
4297*35238bceSAndroid Build Coastguard Worker int instanceCount)
4298*35238bceSAndroid Build Coastguard Worker {
4299*35238bceSAndroid Build Coastguard Worker drawElementsInstancedBaseVertex(mode, count, type, indices, instanceCount, 0);
4300*35238bceSAndroid Build Coastguard Worker }
4301*35238bceSAndroid Build Coastguard Worker
drawElementsInstancedBaseVertex(uint32_t mode,int count,uint32_t type,const void * indices,int instanceCount,int baseVertex)4302*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawElementsInstancedBaseVertex(uint32_t mode, int count, uint32_t type, const void *indices,
4303*35238bceSAndroid Build Coastguard Worker int instanceCount, int baseVertex)
4304*35238bceSAndroid Build Coastguard Worker {
4305*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
4306*35238bceSAndroid Build Coastguard Worker
4307*35238bceSAndroid Build Coastguard Worker // Error conditions
4308*35238bceSAndroid Build Coastguard Worker {
4309*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT, GL_INVALID_ENUM,
4310*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
4311*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(count < 0 || instanceCount < 0, GL_INVALID_VALUE, RC_RET_VOID);
4312*35238bceSAndroid Build Coastguard Worker
4313*35238bceSAndroid Build Coastguard Worker if (!predrawErrorChecks(mode))
4314*35238bceSAndroid Build Coastguard Worker return;
4315*35238bceSAndroid Build Coastguard Worker }
4316*35238bceSAndroid Build Coastguard Worker
4317*35238bceSAndroid Build Coastguard Worker // All is ok
4318*35238bceSAndroid Build Coastguard Worker {
4319*35238bceSAndroid Build Coastguard Worker const rr::PrimitiveType primitiveType = sglr::rr_util::mapGLPrimitiveType(mode);
4320*35238bceSAndroid Build Coastguard Worker const void *indicesPtr =
4321*35238bceSAndroid Build Coastguard Worker (vao.m_elementArrayBufferBinding) ?
4322*35238bceSAndroid Build Coastguard Worker (vao.m_elementArrayBufferBinding->getData() + reinterpret_cast<uintptr_t>(indices)) :
4323*35238bceSAndroid Build Coastguard Worker (indices);
4324*35238bceSAndroid Build Coastguard Worker
4325*35238bceSAndroid Build Coastguard Worker drawWithReference(
4326*35238bceSAndroid Build Coastguard Worker rr::PrimitiveList(primitiveType, count,
4327*35238bceSAndroid Build Coastguard Worker rr::DrawIndices(indicesPtr, sglr::rr_util::mapGLIndexType(type), baseVertex)),
4328*35238bceSAndroid Build Coastguard Worker instanceCount);
4329*35238bceSAndroid Build Coastguard Worker }
4330*35238bceSAndroid Build Coastguard Worker }
4331*35238bceSAndroid Build Coastguard Worker
drawRangeElements(uint32_t mode,uint32_t start,uint32_t end,int count,uint32_t type,const void * indices)4332*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawRangeElements(uint32_t mode, uint32_t start, uint32_t end, int count, uint32_t type,
4333*35238bceSAndroid Build Coastguard Worker const void *indices)
4334*35238bceSAndroid Build Coastguard Worker {
4335*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(end < start, GL_INVALID_VALUE, RC_RET_VOID);
4336*35238bceSAndroid Build Coastguard Worker
4337*35238bceSAndroid Build Coastguard Worker drawElements(mode, count, type, indices);
4338*35238bceSAndroid Build Coastguard Worker }
4339*35238bceSAndroid Build Coastguard Worker
drawRangeElementsBaseVertex(uint32_t mode,uint32_t start,uint32_t end,int count,uint32_t type,const void * indices,int baseVertex)4340*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawRangeElementsBaseVertex(uint32_t mode, uint32_t start, uint32_t end, int count,
4341*35238bceSAndroid Build Coastguard Worker uint32_t type, const void *indices, int baseVertex)
4342*35238bceSAndroid Build Coastguard Worker {
4343*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(end < start, GL_INVALID_VALUE, RC_RET_VOID);
4344*35238bceSAndroid Build Coastguard Worker
4345*35238bceSAndroid Build Coastguard Worker drawElementsBaseVertex(mode, count, type, indices, baseVertex);
4346*35238bceSAndroid Build Coastguard Worker }
4347*35238bceSAndroid Build Coastguard Worker
drawArraysIndirect(uint32_t mode,const void * indirect)4348*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawArraysIndirect(uint32_t mode, const void *indirect)
4349*35238bceSAndroid Build Coastguard Worker {
4350*35238bceSAndroid Build Coastguard Worker struct DrawArraysIndirectCommand
4351*35238bceSAndroid Build Coastguard Worker {
4352*35238bceSAndroid Build Coastguard Worker uint32_t count;
4353*35238bceSAndroid Build Coastguard Worker uint32_t primCount;
4354*35238bceSAndroid Build Coastguard Worker uint32_t first;
4355*35238bceSAndroid Build Coastguard Worker uint32_t reservedMustBeZero;
4356*35238bceSAndroid Build Coastguard Worker };
4357*35238bceSAndroid Build Coastguard Worker
4358*35238bceSAndroid Build Coastguard Worker const DrawArraysIndirectCommand *command;
4359*35238bceSAndroid Build Coastguard Worker
4360*35238bceSAndroid Build Coastguard Worker // Check errors
4361*35238bceSAndroid Build Coastguard Worker
4362*35238bceSAndroid Build Coastguard Worker if (!predrawErrorChecks(mode))
4363*35238bceSAndroid Build Coastguard Worker return;
4364*35238bceSAndroid Build Coastguard Worker
4365*35238bceSAndroid Build Coastguard Worker // Check pointer validity
4366*35238bceSAndroid Build Coastguard Worker
4367*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_drawIndirectBufferBinding == DE_NULL, GL_INVALID_OPERATION, RC_RET_VOID);
4368*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!deIsAlignedPtr(indirect, 4), GL_INVALID_OPERATION, RC_RET_VOID);
4369*35238bceSAndroid Build Coastguard Worker
4370*35238bceSAndroid Build Coastguard Worker // \note watch for overflows, indirect might be close to 0xFFFFFFFF and indirect+something might overflow
4371*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((size_t) reinterpret_cast<uintptr_t>(indirect) > (size_t)m_drawIndirectBufferBinding->getSize(),
4372*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
4373*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((size_t) reinterpret_cast<uintptr_t>(indirect) + sizeof(DrawArraysIndirectCommand) >
4374*35238bceSAndroid Build Coastguard Worker (size_t)m_drawIndirectBufferBinding->getSize(),
4375*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
4376*35238bceSAndroid Build Coastguard Worker
4377*35238bceSAndroid Build Coastguard Worker // Check values
4378*35238bceSAndroid Build Coastguard Worker
4379*35238bceSAndroid Build Coastguard Worker command = (const DrawArraysIndirectCommand *)(m_drawIndirectBufferBinding->getData() +
4380*35238bceSAndroid Build Coastguard Worker reinterpret_cast<uintptr_t>(indirect));
4381*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(command->reservedMustBeZero != 0, GL_INVALID_OPERATION, RC_RET_VOID);
4382*35238bceSAndroid Build Coastguard Worker
4383*35238bceSAndroid Build Coastguard Worker // draw
4384*35238bceSAndroid Build Coastguard Worker drawArraysInstanced(mode, command->first, command->count, command->primCount);
4385*35238bceSAndroid Build Coastguard Worker }
4386*35238bceSAndroid Build Coastguard Worker
drawElementsIndirect(uint32_t mode,uint32_t type,const void * indirect)4387*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawElementsIndirect(uint32_t mode, uint32_t type, const void *indirect)
4388*35238bceSAndroid Build Coastguard Worker {
4389*35238bceSAndroid Build Coastguard Worker struct DrawElementsIndirectCommand
4390*35238bceSAndroid Build Coastguard Worker {
4391*35238bceSAndroid Build Coastguard Worker uint32_t count;
4392*35238bceSAndroid Build Coastguard Worker uint32_t primCount;
4393*35238bceSAndroid Build Coastguard Worker uint32_t firstIndex;
4394*35238bceSAndroid Build Coastguard Worker int32_t baseVertex;
4395*35238bceSAndroid Build Coastguard Worker uint32_t reservedMustBeZero;
4396*35238bceSAndroid Build Coastguard Worker };
4397*35238bceSAndroid Build Coastguard Worker
4398*35238bceSAndroid Build Coastguard Worker const DrawElementsIndirectCommand *command;
4399*35238bceSAndroid Build Coastguard Worker
4400*35238bceSAndroid Build Coastguard Worker // Check errors
4401*35238bceSAndroid Build Coastguard Worker
4402*35238bceSAndroid Build Coastguard Worker if (!predrawErrorChecks(mode))
4403*35238bceSAndroid Build Coastguard Worker return;
4404*35238bceSAndroid Build Coastguard Worker
4405*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT, GL_INVALID_ENUM,
4406*35238bceSAndroid Build Coastguard Worker RC_RET_VOID);
4407*35238bceSAndroid Build Coastguard Worker
4408*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!getBufferBinding(GL_ELEMENT_ARRAY_BUFFER), GL_INVALID_OPERATION, RC_RET_VOID);
4409*35238bceSAndroid Build Coastguard Worker
4410*35238bceSAndroid Build Coastguard Worker // Check pointer validity
4411*35238bceSAndroid Build Coastguard Worker
4412*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_drawIndirectBufferBinding == DE_NULL, GL_INVALID_OPERATION, RC_RET_VOID);
4413*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(!deIsAlignedPtr(indirect, 4), GL_INVALID_OPERATION, RC_RET_VOID);
4414*35238bceSAndroid Build Coastguard Worker
4415*35238bceSAndroid Build Coastguard Worker // \note watch for overflows, indirect might be close to 0xFFFFFFFF and indirect+something might overflow
4416*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((size_t) reinterpret_cast<uintptr_t>(indirect) > (size_t)m_drawIndirectBufferBinding->getSize(),
4417*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
4418*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((size_t) reinterpret_cast<uintptr_t>(indirect) + sizeof(DrawElementsIndirectCommand) >
4419*35238bceSAndroid Build Coastguard Worker (size_t)m_drawIndirectBufferBinding->getSize(),
4420*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, RC_RET_VOID);
4421*35238bceSAndroid Build Coastguard Worker
4422*35238bceSAndroid Build Coastguard Worker // Check values
4423*35238bceSAndroid Build Coastguard Worker
4424*35238bceSAndroid Build Coastguard Worker command = (const DrawElementsIndirectCommand *)(m_drawIndirectBufferBinding->getData() +
4425*35238bceSAndroid Build Coastguard Worker reinterpret_cast<uintptr_t>(indirect));
4426*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(command->reservedMustBeZero != 0, GL_INVALID_OPERATION, RC_RET_VOID);
4427*35238bceSAndroid Build Coastguard Worker
4428*35238bceSAndroid Build Coastguard Worker // Check command error conditions
4429*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR((int)command->count < 0 || (int)command->primCount < 0, GL_INVALID_VALUE, RC_RET_VOID);
4430*35238bceSAndroid Build Coastguard Worker
4431*35238bceSAndroid Build Coastguard Worker // Draw
4432*35238bceSAndroid Build Coastguard Worker {
4433*35238bceSAndroid Build Coastguard Worker const size_t sizeOfType = (type == GL_UNSIGNED_BYTE) ? (1) : ((type == GL_UNSIGNED_SHORT) ? (2) : (4));
4434*35238bceSAndroid Build Coastguard Worker const void *indicesPtr = glu::BufferOffsetAsPointer(command->firstIndex * sizeOfType);
4435*35238bceSAndroid Build Coastguard Worker
4436*35238bceSAndroid Build Coastguard Worker drawElementsInstancedBaseVertex(mode, (int)command->count, type, indicesPtr, (int)command->primCount,
4437*35238bceSAndroid Build Coastguard Worker command->baseVertex);
4438*35238bceSAndroid Build Coastguard Worker }
4439*35238bceSAndroid Build Coastguard Worker }
4440*35238bceSAndroid Build Coastguard Worker
multiDrawArrays(uint32_t mode,const int * first,const int * count,int primCount)4441*35238bceSAndroid Build Coastguard Worker void ReferenceContext::multiDrawArrays(uint32_t mode, const int *first, const int *count, int primCount)
4442*35238bceSAndroid Build Coastguard Worker {
4443*35238bceSAndroid Build Coastguard Worker DE_UNREF(mode);
4444*35238bceSAndroid Build Coastguard Worker DE_UNREF(first);
4445*35238bceSAndroid Build Coastguard Worker DE_UNREF(count);
4446*35238bceSAndroid Build Coastguard Worker DE_UNREF(primCount);
4447*35238bceSAndroid Build Coastguard Worker
4448*35238bceSAndroid Build Coastguard Worker // not supported in gles, prevent accidental use
4449*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
4450*35238bceSAndroid Build Coastguard Worker }
4451*35238bceSAndroid Build Coastguard Worker
multiDrawElements(uint32_t mode,const int * count,uint32_t type,const void ** indices,int primCount)4452*35238bceSAndroid Build Coastguard Worker void ReferenceContext::multiDrawElements(uint32_t mode, const int *count, uint32_t type, const void **indices,
4453*35238bceSAndroid Build Coastguard Worker int primCount)
4454*35238bceSAndroid Build Coastguard Worker {
4455*35238bceSAndroid Build Coastguard Worker DE_UNREF(mode);
4456*35238bceSAndroid Build Coastguard Worker DE_UNREF(count);
4457*35238bceSAndroid Build Coastguard Worker DE_UNREF(type);
4458*35238bceSAndroid Build Coastguard Worker DE_UNREF(indices);
4459*35238bceSAndroid Build Coastguard Worker DE_UNREF(primCount);
4460*35238bceSAndroid Build Coastguard Worker
4461*35238bceSAndroid Build Coastguard Worker // not supported in gles, prevent accidental use
4462*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
4463*35238bceSAndroid Build Coastguard Worker }
4464*35238bceSAndroid Build Coastguard Worker
multiDrawElementsBaseVertex(uint32_t mode,const int * count,uint32_t type,const void ** indices,int primCount,const int * baseVertex)4465*35238bceSAndroid Build Coastguard Worker void ReferenceContext::multiDrawElementsBaseVertex(uint32_t mode, const int *count, uint32_t type, const void **indices,
4466*35238bceSAndroid Build Coastguard Worker int primCount, const int *baseVertex)
4467*35238bceSAndroid Build Coastguard Worker {
4468*35238bceSAndroid Build Coastguard Worker DE_UNREF(mode);
4469*35238bceSAndroid Build Coastguard Worker DE_UNREF(count);
4470*35238bceSAndroid Build Coastguard Worker DE_UNREF(type);
4471*35238bceSAndroid Build Coastguard Worker DE_UNREF(indices);
4472*35238bceSAndroid Build Coastguard Worker DE_UNREF(primCount);
4473*35238bceSAndroid Build Coastguard Worker DE_UNREF(baseVertex);
4474*35238bceSAndroid Build Coastguard Worker
4475*35238bceSAndroid Build Coastguard Worker // not supported in gles, prevent accidental use
4476*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
4477*35238bceSAndroid Build Coastguard Worker }
4478*35238bceSAndroid Build Coastguard Worker
predrawErrorChecks(uint32_t mode)4479*35238bceSAndroid Build Coastguard Worker bool ReferenceContext::predrawErrorChecks(uint32_t mode)
4480*35238bceSAndroid Build Coastguard Worker {
4481*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(mode != GL_POINTS && mode != GL_LINE_STRIP && mode != GL_LINE_LOOP && mode != GL_LINES &&
4482*35238bceSAndroid Build Coastguard Worker mode != GL_TRIANGLE_STRIP && mode != GL_TRIANGLE_FAN && mode != GL_TRIANGLES &&
4483*35238bceSAndroid Build Coastguard Worker mode != GL_LINES_ADJACENCY && mode != GL_LINE_STRIP_ADJACENCY && mode != GL_TRIANGLES_ADJACENCY &&
4484*35238bceSAndroid Build Coastguard Worker mode != GL_TRIANGLE_STRIP_ADJACENCY,
4485*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, false);
4486*35238bceSAndroid Build Coastguard Worker
4487*35238bceSAndroid Build Coastguard Worker // \todo [jarkko] Uncomment following code when the buffer mapping support is added
4488*35238bceSAndroid Build Coastguard Worker //for (size_t ndx = 0; ndx < vao.m_arrays.size(); ++ndx)
4489*35238bceSAndroid Build Coastguard Worker // if (vao.m_arrays[ndx].enabled && vao.m_arrays[ndx].bufferBinding && vao.m_arrays[ndx].bufferBinding->isMapped)
4490*35238bceSAndroid Build Coastguard Worker // RC_ERROR_RET(GL_INVALID_OPERATION, RC_RET_VOID);
4491*35238bceSAndroid Build Coastguard Worker
4492*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(checkFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE,
4493*35238bceSAndroid Build Coastguard Worker GL_INVALID_FRAMEBUFFER_OPERATION, false);
4494*35238bceSAndroid Build Coastguard Worker
4495*35238bceSAndroid Build Coastguard Worker // Geometry shader checks
4496*35238bceSAndroid Build Coastguard Worker if (m_currentProgram && m_currentProgram->m_program->m_hasGeometryShader)
4497*35238bceSAndroid Build Coastguard Worker {
4498*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram->m_program->rr::GeometryShader::getInputType() ==
4499*35238bceSAndroid Build Coastguard Worker rr::GEOMETRYSHADERINPUTTYPE_POINTS &&
4500*35238bceSAndroid Build Coastguard Worker mode != GL_POINTS,
4501*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, false);
4502*35238bceSAndroid Build Coastguard Worker
4503*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram->m_program->rr::GeometryShader::getInputType() ==
4504*35238bceSAndroid Build Coastguard Worker rr::GEOMETRYSHADERINPUTTYPE_LINES &&
4505*35238bceSAndroid Build Coastguard Worker (mode != GL_LINES && mode != GL_LINE_STRIP && mode != GL_LINE_LOOP),
4506*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, false);
4507*35238bceSAndroid Build Coastguard Worker
4508*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram->m_program->rr::GeometryShader::getInputType() ==
4509*35238bceSAndroid Build Coastguard Worker rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES &&
4510*35238bceSAndroid Build Coastguard Worker (mode != GL_TRIANGLES && mode != GL_TRIANGLE_STRIP && mode != GL_TRIANGLE_FAN),
4511*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, false);
4512*35238bceSAndroid Build Coastguard Worker
4513*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram->m_program->rr::GeometryShader::getInputType() ==
4514*35238bceSAndroid Build Coastguard Worker rr::GEOMETRYSHADERINPUTTYPE_LINES_ADJACENCY &&
4515*35238bceSAndroid Build Coastguard Worker (mode != GL_LINES_ADJACENCY && mode != GL_LINE_STRIP_ADJACENCY),
4516*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, false);
4517*35238bceSAndroid Build Coastguard Worker
4518*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(m_currentProgram->m_program->rr::GeometryShader::getInputType() ==
4519*35238bceSAndroid Build Coastguard Worker rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES_ADJACENCY &&
4520*35238bceSAndroid Build Coastguard Worker (mode != GL_TRIANGLES_ADJACENCY && mode != GL_TRIANGLE_STRIP_ADJACENCY),
4521*35238bceSAndroid Build Coastguard Worker GL_INVALID_OPERATION, false);
4522*35238bceSAndroid Build Coastguard Worker }
4523*35238bceSAndroid Build Coastguard Worker
4524*35238bceSAndroid Build Coastguard Worker return true;
4525*35238bceSAndroid Build Coastguard Worker }
4526*35238bceSAndroid Build Coastguard Worker
getPrimitiveBaseType(rr::PrimitiveType derivedType)4527*35238bceSAndroid Build Coastguard Worker static rr::PrimitiveType getPrimitiveBaseType(rr::PrimitiveType derivedType)
4528*35238bceSAndroid Build Coastguard Worker {
4529*35238bceSAndroid Build Coastguard Worker switch (derivedType)
4530*35238bceSAndroid Build Coastguard Worker {
4531*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_TRIANGLES:
4532*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_TRIANGLE_STRIP:
4533*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_TRIANGLE_FAN:
4534*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_TRIANGLES_ADJACENCY:
4535*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_TRIANGLE_STRIP_ADJACENCY:
4536*35238bceSAndroid Build Coastguard Worker return rr::PRIMITIVETYPE_TRIANGLES;
4537*35238bceSAndroid Build Coastguard Worker
4538*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_LINES:
4539*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_LINE_STRIP:
4540*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_LINE_LOOP:
4541*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_LINES_ADJACENCY:
4542*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_LINE_STRIP_ADJACENCY:
4543*35238bceSAndroid Build Coastguard Worker return rr::PRIMITIVETYPE_LINES;
4544*35238bceSAndroid Build Coastguard Worker
4545*35238bceSAndroid Build Coastguard Worker case rr::PRIMITIVETYPE_POINTS:
4546*35238bceSAndroid Build Coastguard Worker return rr::PRIMITIVETYPE_POINTS;
4547*35238bceSAndroid Build Coastguard Worker
4548*35238bceSAndroid Build Coastguard Worker default:
4549*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
4550*35238bceSAndroid Build Coastguard Worker return rr::PRIMITIVETYPE_LAST;
4551*35238bceSAndroid Build Coastguard Worker }
4552*35238bceSAndroid Build Coastguard Worker }
4553*35238bceSAndroid Build Coastguard Worker
getFixedRestartIndex(rr::IndexType indexType)4554*35238bceSAndroid Build Coastguard Worker static uint32_t getFixedRestartIndex(rr::IndexType indexType)
4555*35238bceSAndroid Build Coastguard Worker {
4556*35238bceSAndroid Build Coastguard Worker switch (indexType)
4557*35238bceSAndroid Build Coastguard Worker {
4558*35238bceSAndroid Build Coastguard Worker case rr::INDEXTYPE_UINT8:
4559*35238bceSAndroid Build Coastguard Worker return 0xFF;
4560*35238bceSAndroid Build Coastguard Worker case rr::INDEXTYPE_UINT16:
4561*35238bceSAndroid Build Coastguard Worker return 0xFFFF;
4562*35238bceSAndroid Build Coastguard Worker case rr::INDEXTYPE_UINT32:
4563*35238bceSAndroid Build Coastguard Worker return 0xFFFFFFFFul;
4564*35238bceSAndroid Build Coastguard Worker
4565*35238bceSAndroid Build Coastguard Worker case rr::INDEXTYPE_LAST:
4566*35238bceSAndroid Build Coastguard Worker default:
4567*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
4568*35238bceSAndroid Build Coastguard Worker return 0;
4569*35238bceSAndroid Build Coastguard Worker }
4570*35238bceSAndroid Build Coastguard Worker }
4571*35238bceSAndroid Build Coastguard Worker
drawWithReference(const rr::PrimitiveList & primitives,int instanceCount)4572*35238bceSAndroid Build Coastguard Worker void ReferenceContext::drawWithReference(const rr::PrimitiveList &primitives, int instanceCount)
4573*35238bceSAndroid Build Coastguard Worker {
4574*35238bceSAndroid Build Coastguard Worker // undefined results
4575*35238bceSAndroid Build Coastguard Worker if (m_currentProgram == DE_NULL)
4576*35238bceSAndroid Build Coastguard Worker return;
4577*35238bceSAndroid Build Coastguard Worker
4578*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess colorBuf0 = getDrawColorbuffer();
4579*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess depthBuf = getDepthMultisampleAccess(getDrawDepthbuffer());
4580*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess stencilBuf = getStencilMultisampleAccess(getDrawStencilbuffer());
4581*35238bceSAndroid Build Coastguard Worker const bool hasStencil = !isEmpty(stencilBuf);
4582*35238bceSAndroid Build Coastguard Worker const int stencilBits = (hasStencil) ? (getNumStencilBits(stencilBuf.raw().getFormat())) : (0);
4583*35238bceSAndroid Build Coastguard Worker
4584*35238bceSAndroid Build Coastguard Worker const rr::RenderTarget renderTarget(colorBuf0, depthBuf, stencilBuf);
4585*35238bceSAndroid Build Coastguard Worker const rr::Program program(
4586*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->getVertexShader(), m_currentProgram->m_program->getFragmentShader(),
4587*35238bceSAndroid Build Coastguard Worker (m_currentProgram->m_program->m_hasGeometryShader) ? (m_currentProgram->m_program->getGeometryShader()) :
4588*35238bceSAndroid Build Coastguard Worker (DE_NULL));
4589*35238bceSAndroid Build Coastguard Worker rr::RenderState state((rr::ViewportState)(colorBuf0), m_limits.subpixelBits);
4590*35238bceSAndroid Build Coastguard Worker
4591*35238bceSAndroid Build Coastguard Worker const rr::Renderer referenceRenderer;
4592*35238bceSAndroid Build Coastguard Worker std::vector<rr::VertexAttrib> vertexAttribs;
4593*35238bceSAndroid Build Coastguard Worker
4594*35238bceSAndroid Build Coastguard Worker // Gen state
4595*35238bceSAndroid Build Coastguard Worker {
4596*35238bceSAndroid Build Coastguard Worker const rr::PrimitiveType baseType = getPrimitiveBaseType(primitives.getPrimitiveType());
4597*35238bceSAndroid Build Coastguard Worker const bool polygonOffsetEnabled =
4598*35238bceSAndroid Build Coastguard Worker (baseType == rr::PRIMITIVETYPE_TRIANGLES) ? (m_polygonOffsetFillEnabled) : (false);
4599*35238bceSAndroid Build Coastguard Worker
4600*35238bceSAndroid Build Coastguard Worker //state.cullMode = m_cullMode
4601*35238bceSAndroid Build Coastguard Worker
4602*35238bceSAndroid Build Coastguard Worker state.fragOps.scissorTestEnabled = m_scissorEnabled;
4603*35238bceSAndroid Build Coastguard Worker state.fragOps.scissorRectangle =
4604*35238bceSAndroid Build Coastguard Worker rr::WindowRectangle(m_scissorBox.x(), m_scissorBox.y(), m_scissorBox.z(), m_scissorBox.w());
4605*35238bceSAndroid Build Coastguard Worker
4606*35238bceSAndroid Build Coastguard Worker state.fragOps.numStencilBits = stencilBits;
4607*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilTestEnabled = m_stencilTestEnabled;
4608*35238bceSAndroid Build Coastguard Worker
4609*35238bceSAndroid Build Coastguard Worker for (int faceType = 0; faceType < rr::FACETYPE_LAST; faceType++)
4610*35238bceSAndroid Build Coastguard Worker {
4611*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].compMask = m_stencil[faceType].opMask;
4612*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].writeMask = m_stencil[faceType].writeMask;
4613*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].ref = m_stencil[faceType].ref;
4614*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].func = sglr::rr_util::mapGLTestFunc(m_stencil[faceType].func);
4615*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].sFail =
4616*35238bceSAndroid Build Coastguard Worker sglr::rr_util::mapGLStencilOp(m_stencil[faceType].opStencilFail);
4617*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].dpFail =
4618*35238bceSAndroid Build Coastguard Worker sglr::rr_util::mapGLStencilOp(m_stencil[faceType].opDepthFail);
4619*35238bceSAndroid Build Coastguard Worker state.fragOps.stencilStates[faceType].dpPass =
4620*35238bceSAndroid Build Coastguard Worker sglr::rr_util::mapGLStencilOp(m_stencil[faceType].opDepthPass);
4621*35238bceSAndroid Build Coastguard Worker }
4622*35238bceSAndroid Build Coastguard Worker
4623*35238bceSAndroid Build Coastguard Worker state.fragOps.depthTestEnabled = m_depthTestEnabled;
4624*35238bceSAndroid Build Coastguard Worker state.fragOps.depthFunc = sglr::rr_util::mapGLTestFunc(m_depthFunc);
4625*35238bceSAndroid Build Coastguard Worker state.fragOps.depthMask = m_depthMask;
4626*35238bceSAndroid Build Coastguard Worker
4627*35238bceSAndroid Build Coastguard Worker state.fragOps.blendMode = m_blendEnabled ? rr::BLENDMODE_STANDARD : rr::BLENDMODE_NONE;
4628*35238bceSAndroid Build Coastguard Worker state.fragOps.blendRGBState.equation = sglr::rr_util::mapGLBlendEquation(m_blendModeRGB);
4629*35238bceSAndroid Build Coastguard Worker state.fragOps.blendRGBState.srcFunc = sglr::rr_util::mapGLBlendFunc(m_blendFactorSrcRGB);
4630*35238bceSAndroid Build Coastguard Worker state.fragOps.blendRGBState.dstFunc = sglr::rr_util::mapGLBlendFunc(m_blendFactorDstRGB);
4631*35238bceSAndroid Build Coastguard Worker state.fragOps.blendAState.equation = sglr::rr_util::mapGLBlendEquation(m_blendModeAlpha);
4632*35238bceSAndroid Build Coastguard Worker state.fragOps.blendAState.srcFunc = sglr::rr_util::mapGLBlendFunc(m_blendFactorSrcAlpha);
4633*35238bceSAndroid Build Coastguard Worker state.fragOps.blendAState.dstFunc = sglr::rr_util::mapGLBlendFunc(m_blendFactorDstAlpha);
4634*35238bceSAndroid Build Coastguard Worker state.fragOps.blendColor = m_blendColor;
4635*35238bceSAndroid Build Coastguard Worker
4636*35238bceSAndroid Build Coastguard Worker state.fragOps.sRGBEnabled = m_sRGBUpdateEnabled;
4637*35238bceSAndroid Build Coastguard Worker
4638*35238bceSAndroid Build Coastguard Worker state.fragOps.colorMask = m_colorMask;
4639*35238bceSAndroid Build Coastguard Worker
4640*35238bceSAndroid Build Coastguard Worker state.fragOps.depthClampEnabled = m_depthClampEnabled;
4641*35238bceSAndroid Build Coastguard Worker
4642*35238bceSAndroid Build Coastguard Worker state.viewport.rect = rr::WindowRectangle(m_viewport.x(), m_viewport.y(), m_viewport.z(), m_viewport.w());
4643*35238bceSAndroid Build Coastguard Worker state.viewport.zn = m_depthRangeNear;
4644*35238bceSAndroid Build Coastguard Worker state.viewport.zf = m_depthRangeFar;
4645*35238bceSAndroid Build Coastguard Worker
4646*35238bceSAndroid Build Coastguard Worker //state.point.pointSize = m_pointSize;
4647*35238bceSAndroid Build Coastguard Worker state.line.lineWidth = m_lineWidth;
4648*35238bceSAndroid Build Coastguard Worker
4649*35238bceSAndroid Build Coastguard Worker state.fragOps.polygonOffsetEnabled = polygonOffsetEnabled;
4650*35238bceSAndroid Build Coastguard Worker state.fragOps.polygonOffsetFactor = m_polygonOffsetFactor;
4651*35238bceSAndroid Build Coastguard Worker state.fragOps.polygonOffsetUnits = m_polygonOffsetUnits;
4652*35238bceSAndroid Build Coastguard Worker
4653*35238bceSAndroid Build Coastguard Worker {
4654*35238bceSAndroid Build Coastguard Worker const rr::IndexType indexType = primitives.getIndexType();
4655*35238bceSAndroid Build Coastguard Worker
4656*35238bceSAndroid Build Coastguard Worker if (m_primitiveRestartFixedIndex && indexType != rr::INDEXTYPE_LAST)
4657*35238bceSAndroid Build Coastguard Worker {
4658*35238bceSAndroid Build Coastguard Worker state.restart.enabled = true;
4659*35238bceSAndroid Build Coastguard Worker state.restart.restartIndex = getFixedRestartIndex(indexType);
4660*35238bceSAndroid Build Coastguard Worker }
4661*35238bceSAndroid Build Coastguard Worker else if (m_primitiveRestartSettableIndex)
4662*35238bceSAndroid Build Coastguard Worker {
4663*35238bceSAndroid Build Coastguard Worker // \note PRIMITIVE_RESTART is active for non-indexed (DrawArrays) operations too.
4664*35238bceSAndroid Build Coastguard Worker state.restart.enabled = true;
4665*35238bceSAndroid Build Coastguard Worker state.restart.restartIndex = m_primitiveRestartIndex;
4666*35238bceSAndroid Build Coastguard Worker }
4667*35238bceSAndroid Build Coastguard Worker else
4668*35238bceSAndroid Build Coastguard Worker {
4669*35238bceSAndroid Build Coastguard Worker state.restart.enabled = false;
4670*35238bceSAndroid Build Coastguard Worker }
4671*35238bceSAndroid Build Coastguard Worker }
4672*35238bceSAndroid Build Coastguard Worker
4673*35238bceSAndroid Build Coastguard Worker state.provokingVertexConvention =
4674*35238bceSAndroid Build Coastguard Worker (m_provokingFirstVertexConvention) ? (rr::PROVOKINGVERTEX_FIRST) : (rr::PROVOKINGVERTEX_LAST);
4675*35238bceSAndroid Build Coastguard Worker }
4676*35238bceSAndroid Build Coastguard Worker
4677*35238bceSAndroid Build Coastguard Worker // gen attributes
4678*35238bceSAndroid Build Coastguard Worker {
4679*35238bceSAndroid Build Coastguard Worker rc::VertexArray &vao = (m_vertexArrayBinding) ? (*m_vertexArrayBinding) : (m_clientVertexArray);
4680*35238bceSAndroid Build Coastguard Worker
4681*35238bceSAndroid Build Coastguard Worker vertexAttribs.resize(vao.m_arrays.size());
4682*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 0; ndx < vao.m_arrays.size(); ++ndx)
4683*35238bceSAndroid Build Coastguard Worker {
4684*35238bceSAndroid Build Coastguard Worker if (!vao.m_arrays[ndx].enabled)
4685*35238bceSAndroid Build Coastguard Worker {
4686*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].type =
4687*35238bceSAndroid Build Coastguard Worker rr::VERTEXATTRIBTYPE_DONT_CARE; // reading with wrong type is allowed, but results are undefined
4688*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].generic = m_currentAttribs[ndx];
4689*35238bceSAndroid Build Coastguard Worker }
4690*35238bceSAndroid Build Coastguard Worker else if (vao.m_arrays[ndx].bufferDeleted)
4691*35238bceSAndroid Build Coastguard Worker {
4692*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].type = rr::VERTEXATTRIBTYPE_DONT_CARE; // reading from deleted buffer, output zeros
4693*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].generic = tcu::Vec4(0, 0, 0, 0);
4694*35238bceSAndroid Build Coastguard Worker }
4695*35238bceSAndroid Build Coastguard Worker else
4696*35238bceSAndroid Build Coastguard Worker {
4697*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].type =
4698*35238bceSAndroid Build Coastguard Worker (vao.m_arrays[ndx].integer) ?
4699*35238bceSAndroid Build Coastguard Worker (sglr::rr_util::mapGLPureIntegerVertexAttributeType(vao.m_arrays[ndx].type)) :
4700*35238bceSAndroid Build Coastguard Worker (sglr::rr_util::mapGLFloatVertexAttributeType(vao.m_arrays[ndx].type,
4701*35238bceSAndroid Build Coastguard Worker vao.m_arrays[ndx].normalized,
4702*35238bceSAndroid Build Coastguard Worker vao.m_arrays[ndx].size, this->getType()));
4703*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].size = sglr::rr_util::mapGLSize(vao.m_arrays[ndx].size);
4704*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].stride = vao.m_arrays[ndx].stride;
4705*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].instanceDivisor = vao.m_arrays[ndx].divisor;
4706*35238bceSAndroid Build Coastguard Worker vertexAttribs[ndx].pointer = (vao.m_arrays[ndx].bufferBinding) ?
4707*35238bceSAndroid Build Coastguard Worker (vao.m_arrays[ndx].bufferBinding->getData() +
4708*35238bceSAndroid Build Coastguard Worker reinterpret_cast<uintptr_t>(vao.m_arrays[ndx].pointer)) :
4709*35238bceSAndroid Build Coastguard Worker (vao.m_arrays[ndx].pointer);
4710*35238bceSAndroid Build Coastguard Worker }
4711*35238bceSAndroid Build Coastguard Worker }
4712*35238bceSAndroid Build Coastguard Worker }
4713*35238bceSAndroid Build Coastguard Worker
4714*35238bceSAndroid Build Coastguard Worker // Set shader samplers
4715*35238bceSAndroid Build Coastguard Worker for (size_t uniformNdx = 0; uniformNdx < m_currentProgram->m_program->m_uniforms.size(); ++uniformNdx)
4716*35238bceSAndroid Build Coastguard Worker {
4717*35238bceSAndroid Build Coastguard Worker const tcu::Sampler::DepthStencilMode depthStencilMode =
4718*35238bceSAndroid Build Coastguard Worker tcu::Sampler::MODE_DEPTH; // \todo[jarkko] support sampler state
4719*35238bceSAndroid Build Coastguard Worker const int texNdx = m_currentProgram->m_program->m_uniforms[uniformNdx].value.i;
4720*35238bceSAndroid Build Coastguard Worker
4721*35238bceSAndroid Build Coastguard Worker switch (m_currentProgram->m_program->m_uniforms[uniformNdx].type)
4722*35238bceSAndroid Build Coastguard Worker {
4723*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_1D:
4724*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_1D:
4725*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_1D:
4726*35238bceSAndroid Build Coastguard Worker {
4727*35238bceSAndroid Build Coastguard Worker rc::Texture1D *tex = DE_NULL;
4728*35238bceSAndroid Build Coastguard Worker
4729*35238bceSAndroid Build Coastguard Worker if (texNdx >= 0 && (size_t)texNdx < m_textureUnits.size())
4730*35238bceSAndroid Build Coastguard Worker tex = (m_textureUnits[texNdx].tex1DBinding) ? (m_textureUnits[texNdx].tex1DBinding) :
4731*35238bceSAndroid Build Coastguard Worker (&m_textureUnits[texNdx].default1DTex);
4732*35238bceSAndroid Build Coastguard Worker
4733*35238bceSAndroid Build Coastguard Worker if (tex && tex->isComplete())
4734*35238bceSAndroid Build Coastguard Worker {
4735*35238bceSAndroid Build Coastguard Worker tex->updateView(depthStencilMode);
4736*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex1D = tex;
4737*35238bceSAndroid Build Coastguard Worker }
4738*35238bceSAndroid Build Coastguard Worker else
4739*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex1D = &m_emptyTex1D;
4740*35238bceSAndroid Build Coastguard Worker
4741*35238bceSAndroid Build Coastguard Worker break;
4742*35238bceSAndroid Build Coastguard Worker }
4743*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_2D:
4744*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_2D:
4745*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_2D:
4746*35238bceSAndroid Build Coastguard Worker {
4747*35238bceSAndroid Build Coastguard Worker rc::Texture2D *tex = DE_NULL;
4748*35238bceSAndroid Build Coastguard Worker
4749*35238bceSAndroid Build Coastguard Worker if (texNdx >= 0 && (size_t)texNdx < m_textureUnits.size())
4750*35238bceSAndroid Build Coastguard Worker tex = (m_textureUnits[texNdx].tex2DBinding) ? (m_textureUnits[texNdx].tex2DBinding) :
4751*35238bceSAndroid Build Coastguard Worker (&m_textureUnits[texNdx].default2DTex);
4752*35238bceSAndroid Build Coastguard Worker
4753*35238bceSAndroid Build Coastguard Worker if (tex && tex->isComplete())
4754*35238bceSAndroid Build Coastguard Worker {
4755*35238bceSAndroid Build Coastguard Worker tex->updateView(depthStencilMode);
4756*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex2D = tex;
4757*35238bceSAndroid Build Coastguard Worker }
4758*35238bceSAndroid Build Coastguard Worker else
4759*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex2D = &m_emptyTex2D;
4760*35238bceSAndroid Build Coastguard Worker
4761*35238bceSAndroid Build Coastguard Worker break;
4762*35238bceSAndroid Build Coastguard Worker }
4763*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_CUBE:
4764*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_CUBE:
4765*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_CUBE:
4766*35238bceSAndroid Build Coastguard Worker {
4767*35238bceSAndroid Build Coastguard Worker rc::TextureCube *tex = DE_NULL;
4768*35238bceSAndroid Build Coastguard Worker
4769*35238bceSAndroid Build Coastguard Worker if (texNdx >= 0 && (size_t)texNdx < m_textureUnits.size())
4770*35238bceSAndroid Build Coastguard Worker tex = (m_textureUnits[texNdx].texCubeBinding) ? (m_textureUnits[texNdx].texCubeBinding) :
4771*35238bceSAndroid Build Coastguard Worker (&m_textureUnits[texNdx].defaultCubeTex);
4772*35238bceSAndroid Build Coastguard Worker
4773*35238bceSAndroid Build Coastguard Worker if (tex && tex->isComplete())
4774*35238bceSAndroid Build Coastguard Worker {
4775*35238bceSAndroid Build Coastguard Worker tex->updateView(depthStencilMode);
4776*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.texCube = tex;
4777*35238bceSAndroid Build Coastguard Worker }
4778*35238bceSAndroid Build Coastguard Worker else
4779*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.texCube = &m_emptyTexCube;
4780*35238bceSAndroid Build Coastguard Worker
4781*35238bceSAndroid Build Coastguard Worker break;
4782*35238bceSAndroid Build Coastguard Worker }
4783*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_2D_ARRAY:
4784*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_2D_ARRAY:
4785*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_2D_ARRAY:
4786*35238bceSAndroid Build Coastguard Worker {
4787*35238bceSAndroid Build Coastguard Worker rc::Texture2DArray *tex = DE_NULL;
4788*35238bceSAndroid Build Coastguard Worker
4789*35238bceSAndroid Build Coastguard Worker if (texNdx >= 0 && (size_t)texNdx < m_textureUnits.size())
4790*35238bceSAndroid Build Coastguard Worker tex = (m_textureUnits[texNdx].tex2DArrayBinding) ? (m_textureUnits[texNdx].tex2DArrayBinding) :
4791*35238bceSAndroid Build Coastguard Worker (&m_textureUnits[texNdx].default2DArrayTex);
4792*35238bceSAndroid Build Coastguard Worker
4793*35238bceSAndroid Build Coastguard Worker if (tex && tex->isComplete())
4794*35238bceSAndroid Build Coastguard Worker {
4795*35238bceSAndroid Build Coastguard Worker tex->updateView(depthStencilMode);
4796*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex2DArray = tex;
4797*35238bceSAndroid Build Coastguard Worker }
4798*35238bceSAndroid Build Coastguard Worker else
4799*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex2DArray = &m_emptyTex2DArray;
4800*35238bceSAndroid Build Coastguard Worker
4801*35238bceSAndroid Build Coastguard Worker break;
4802*35238bceSAndroid Build Coastguard Worker }
4803*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_3D:
4804*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_3D:
4805*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_3D:
4806*35238bceSAndroid Build Coastguard Worker {
4807*35238bceSAndroid Build Coastguard Worker rc::Texture3D *tex = DE_NULL;
4808*35238bceSAndroid Build Coastguard Worker
4809*35238bceSAndroid Build Coastguard Worker if (texNdx >= 0 && (size_t)texNdx < m_textureUnits.size())
4810*35238bceSAndroid Build Coastguard Worker tex = (m_textureUnits[texNdx].tex3DBinding) ? (m_textureUnits[texNdx].tex3DBinding) :
4811*35238bceSAndroid Build Coastguard Worker (&m_textureUnits[texNdx].default3DTex);
4812*35238bceSAndroid Build Coastguard Worker
4813*35238bceSAndroid Build Coastguard Worker if (tex && tex->isComplete())
4814*35238bceSAndroid Build Coastguard Worker {
4815*35238bceSAndroid Build Coastguard Worker tex->updateView(depthStencilMode);
4816*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex3D = tex;
4817*35238bceSAndroid Build Coastguard Worker }
4818*35238bceSAndroid Build Coastguard Worker else
4819*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.tex3D = &m_emptyTex3D;
4820*35238bceSAndroid Build Coastguard Worker
4821*35238bceSAndroid Build Coastguard Worker break;
4822*35238bceSAndroid Build Coastguard Worker }
4823*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_CUBE_ARRAY:
4824*35238bceSAndroid Build Coastguard Worker case glu::TYPE_UINT_SAMPLER_CUBE_ARRAY:
4825*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT_SAMPLER_CUBE_ARRAY:
4826*35238bceSAndroid Build Coastguard Worker {
4827*35238bceSAndroid Build Coastguard Worker rc::TextureCubeArray *tex = DE_NULL;
4828*35238bceSAndroid Build Coastguard Worker
4829*35238bceSAndroid Build Coastguard Worker if (texNdx >= 0 && (size_t)texNdx < m_textureUnits.size())
4830*35238bceSAndroid Build Coastguard Worker tex = (m_textureUnits[texNdx].texCubeArrayBinding) ? (m_textureUnits[texNdx].texCubeArrayBinding) :
4831*35238bceSAndroid Build Coastguard Worker (&m_textureUnits[texNdx].defaultCubeArrayTex);
4832*35238bceSAndroid Build Coastguard Worker
4833*35238bceSAndroid Build Coastguard Worker if (tex && tex->isComplete())
4834*35238bceSAndroid Build Coastguard Worker {
4835*35238bceSAndroid Build Coastguard Worker tex->updateView(depthStencilMode);
4836*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.texCubeArray = tex;
4837*35238bceSAndroid Build Coastguard Worker }
4838*35238bceSAndroid Build Coastguard Worker else
4839*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_program->m_uniforms[uniformNdx].sampler.texCubeArray = &m_emptyTexCubeArray;
4840*35238bceSAndroid Build Coastguard Worker
4841*35238bceSAndroid Build Coastguard Worker break;
4842*35238bceSAndroid Build Coastguard Worker }
4843*35238bceSAndroid Build Coastguard Worker default:
4844*35238bceSAndroid Build Coastguard Worker // nothing
4845*35238bceSAndroid Build Coastguard Worker break;
4846*35238bceSAndroid Build Coastguard Worker }
4847*35238bceSAndroid Build Coastguard Worker }
4848*35238bceSAndroid Build Coastguard Worker
4849*35238bceSAndroid Build Coastguard Worker referenceRenderer.drawInstanced(
4850*35238bceSAndroid Build Coastguard Worker rr::DrawCommand(state, renderTarget, program, (int)vertexAttribs.size(), &vertexAttribs[0], primitives),
4851*35238bceSAndroid Build Coastguard Worker instanceCount);
4852*35238bceSAndroid Build Coastguard Worker }
4853*35238bceSAndroid Build Coastguard Worker
createProgram(ShaderProgram * program)4854*35238bceSAndroid Build Coastguard Worker uint32_t ReferenceContext::createProgram(ShaderProgram *program)
4855*35238bceSAndroid Build Coastguard Worker {
4856*35238bceSAndroid Build Coastguard Worker int name = m_programs.allocateName();
4857*35238bceSAndroid Build Coastguard Worker
4858*35238bceSAndroid Build Coastguard Worker m_programs.insert(new rc::ShaderProgramObjectContainer(name, program));
4859*35238bceSAndroid Build Coastguard Worker
4860*35238bceSAndroid Build Coastguard Worker return name;
4861*35238bceSAndroid Build Coastguard Worker }
4862*35238bceSAndroid Build Coastguard Worker
useProgram(uint32_t program)4863*35238bceSAndroid Build Coastguard Worker void ReferenceContext::useProgram(uint32_t program)
4864*35238bceSAndroid Build Coastguard Worker {
4865*35238bceSAndroid Build Coastguard Worker rc::ShaderProgramObjectContainer *shaderProg = DE_NULL;
4866*35238bceSAndroid Build Coastguard Worker rc::ShaderProgramObjectContainer *programToBeDeleted = DE_NULL;
4867*35238bceSAndroid Build Coastguard Worker
4868*35238bceSAndroid Build Coastguard Worker if (program)
4869*35238bceSAndroid Build Coastguard Worker {
4870*35238bceSAndroid Build Coastguard Worker shaderProg = m_programs.find(program);
4871*35238bceSAndroid Build Coastguard Worker
4872*35238bceSAndroid Build Coastguard Worker // shader has not been linked
4873*35238bceSAndroid Build Coastguard Worker if (!shaderProg || shaderProg->m_deleteFlag)
4874*35238bceSAndroid Build Coastguard Worker RC_ERROR_RET(GL_INVALID_OPERATION, RC_RET_VOID);
4875*35238bceSAndroid Build Coastguard Worker }
4876*35238bceSAndroid Build Coastguard Worker
4877*35238bceSAndroid Build Coastguard Worker if (m_currentProgram && m_currentProgram->m_deleteFlag)
4878*35238bceSAndroid Build Coastguard Worker programToBeDeleted = m_currentProgram;
4879*35238bceSAndroid Build Coastguard Worker
4880*35238bceSAndroid Build Coastguard Worker m_currentProgram = shaderProg;
4881*35238bceSAndroid Build Coastguard Worker
4882*35238bceSAndroid Build Coastguard Worker if (programToBeDeleted)
4883*35238bceSAndroid Build Coastguard Worker {
4884*35238bceSAndroid Build Coastguard Worker DE_ASSERT(programToBeDeleted->getRefCount() == 1);
4885*35238bceSAndroid Build Coastguard Worker deleteProgramObject(programToBeDeleted);
4886*35238bceSAndroid Build Coastguard Worker }
4887*35238bceSAndroid Build Coastguard Worker }
4888*35238bceSAndroid Build Coastguard Worker
deleteProgram(uint32_t program)4889*35238bceSAndroid Build Coastguard Worker void ReferenceContext::deleteProgram(uint32_t program)
4890*35238bceSAndroid Build Coastguard Worker {
4891*35238bceSAndroid Build Coastguard Worker if (!program)
4892*35238bceSAndroid Build Coastguard Worker return;
4893*35238bceSAndroid Build Coastguard Worker
4894*35238bceSAndroid Build Coastguard Worker rc::ShaderProgramObjectContainer *shaderProg = m_programs.find(program);
4895*35238bceSAndroid Build Coastguard Worker if (shaderProg)
4896*35238bceSAndroid Build Coastguard Worker {
4897*35238bceSAndroid Build Coastguard Worker if (shaderProg == m_currentProgram)
4898*35238bceSAndroid Build Coastguard Worker {
4899*35238bceSAndroid Build Coastguard Worker m_currentProgram->m_deleteFlag = true;
4900*35238bceSAndroid Build Coastguard Worker }
4901*35238bceSAndroid Build Coastguard Worker else
4902*35238bceSAndroid Build Coastguard Worker {
4903*35238bceSAndroid Build Coastguard Worker DE_ASSERT(shaderProg->getRefCount() == 1);
4904*35238bceSAndroid Build Coastguard Worker m_programs.releaseReference(shaderProg);
4905*35238bceSAndroid Build Coastguard Worker }
4906*35238bceSAndroid Build Coastguard Worker }
4907*35238bceSAndroid Build Coastguard Worker }
4908*35238bceSAndroid Build Coastguard Worker
readPixels(int x,int y,int width,int height,uint32_t format,uint32_t type,void * data)4909*35238bceSAndroid Build Coastguard Worker void ReferenceContext::readPixels(int x, int y, int width, int height, uint32_t format, uint32_t type, void *data)
4910*35238bceSAndroid Build Coastguard Worker {
4911*35238bceSAndroid Build Coastguard Worker rr::MultisamplePixelBufferAccess src = getReadColorbuffer();
4912*35238bceSAndroid Build Coastguard Worker TextureFormat transferFmt;
4913*35238bceSAndroid Build Coastguard Worker
4914*35238bceSAndroid Build Coastguard Worker // Map transfer format.
4915*35238bceSAndroid Build Coastguard Worker transferFmt = glu::mapGLTransferFormat(format, type);
4916*35238bceSAndroid Build Coastguard Worker RC_IF_ERROR(transferFmt.order == TextureFormat::CHANNELORDER_LAST ||
4917*35238bceSAndroid Build Coastguard Worker transferFmt.type == TextureFormat::CHANNELTYPE_LAST,
4918*35238bceSAndroid Build Coastguard Worker GL_INVALID_ENUM, RC_RET_VOID);
4919*35238bceSAndroid Build Coastguard Worker
4920*35238bceSAndroid Build Coastguard Worker // Clamp input values
4921*35238bceSAndroid Build Coastguard Worker const int copyX = deClamp32(x, 0, src.raw().getHeight());
4922*35238bceSAndroid Build Coastguard Worker const int copyY = deClamp32(y, 0, src.raw().getDepth());
4923*35238bceSAndroid Build Coastguard Worker const int copyWidth = deClamp32(width, 0, src.raw().getHeight() - x);
4924*35238bceSAndroid Build Coastguard Worker const int copyHeight = deClamp32(height, 0, src.raw().getDepth() - y);
4925*35238bceSAndroid Build Coastguard Worker
4926*35238bceSAndroid Build Coastguard Worker PixelBufferAccess dst(transferFmt, width, height, 1,
4927*35238bceSAndroid Build Coastguard Worker deAlign32(width * transferFmt.getPixelSize(), m_pixelPackAlignment), 0,
4928*35238bceSAndroid Build Coastguard Worker getPixelPackPtr(data));
4929*35238bceSAndroid Build Coastguard Worker rr::resolveMultisampleColorBuffer(tcu::getSubregion(dst, 0, 0, copyWidth, copyHeight),
4930*35238bceSAndroid Build Coastguard Worker rr::getSubregion(src, copyX, copyY, copyWidth, copyHeight));
4931*35238bceSAndroid Build Coastguard Worker }
4932*35238bceSAndroid Build Coastguard Worker
getError(void)4933*35238bceSAndroid Build Coastguard Worker uint32_t ReferenceContext::getError(void)
4934*35238bceSAndroid Build Coastguard Worker {
4935*35238bceSAndroid Build Coastguard Worker uint32_t err = m_lastError;
4936*35238bceSAndroid Build Coastguard Worker m_lastError = GL_NO_ERROR;
4937*35238bceSAndroid Build Coastguard Worker return err;
4938*35238bceSAndroid Build Coastguard Worker }
4939*35238bceSAndroid Build Coastguard Worker
finish(void)4940*35238bceSAndroid Build Coastguard Worker void ReferenceContext::finish(void)
4941*35238bceSAndroid Build Coastguard Worker {
4942*35238bceSAndroid Build Coastguard Worker }
4943*35238bceSAndroid Build Coastguard Worker
setError(uint32_t error)4944*35238bceSAndroid Build Coastguard Worker inline void ReferenceContext::setError(uint32_t error)
4945*35238bceSAndroid Build Coastguard Worker {
4946*35238bceSAndroid Build Coastguard Worker if (m_lastError == GL_NO_ERROR)
4947*35238bceSAndroid Build Coastguard Worker m_lastError = error;
4948*35238bceSAndroid Build Coastguard Worker }
4949*35238bceSAndroid Build Coastguard Worker
getIntegerv(uint32_t pname,int * param)4950*35238bceSAndroid Build Coastguard Worker void ReferenceContext::getIntegerv(uint32_t pname, int *param)
4951*35238bceSAndroid Build Coastguard Worker {
4952*35238bceSAndroid Build Coastguard Worker switch (pname)
4953*35238bceSAndroid Build Coastguard Worker {
4954*35238bceSAndroid Build Coastguard Worker case GL_MAX_TEXTURE_SIZE:
4955*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxTexture2DSize;
4956*35238bceSAndroid Build Coastguard Worker break;
4957*35238bceSAndroid Build Coastguard Worker case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
4958*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxTextureCubeSize;
4959*35238bceSAndroid Build Coastguard Worker break;
4960*35238bceSAndroid Build Coastguard Worker case GL_MAX_ARRAY_TEXTURE_LAYERS:
4961*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxTexture2DArrayLayers;
4962*35238bceSAndroid Build Coastguard Worker break;
4963*35238bceSAndroid Build Coastguard Worker case GL_MAX_3D_TEXTURE_SIZE:
4964*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxTexture3DSize;
4965*35238bceSAndroid Build Coastguard Worker break;
4966*35238bceSAndroid Build Coastguard Worker case GL_MAX_RENDERBUFFER_SIZE:
4967*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxRenderbufferSize;
4968*35238bceSAndroid Build Coastguard Worker break;
4969*35238bceSAndroid Build Coastguard Worker case GL_MAX_TEXTURE_IMAGE_UNITS:
4970*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxTextureImageUnits;
4971*35238bceSAndroid Build Coastguard Worker break;
4972*35238bceSAndroid Build Coastguard Worker case GL_MAX_VERTEX_ATTRIBS:
4973*35238bceSAndroid Build Coastguard Worker *param = m_limits.maxVertexAttribs;
4974*35238bceSAndroid Build Coastguard Worker break;
4975*35238bceSAndroid Build Coastguard Worker
4976*35238bceSAndroid Build Coastguard Worker default:
4977*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
4978*35238bceSAndroid Build Coastguard Worker break;
4979*35238bceSAndroid Build Coastguard Worker }
4980*35238bceSAndroid Build Coastguard Worker }
4981*35238bceSAndroid Build Coastguard Worker
getString(uint32_t pname)4982*35238bceSAndroid Build Coastguard Worker const char *ReferenceContext::getString(uint32_t pname)
4983*35238bceSAndroid Build Coastguard Worker {
4984*35238bceSAndroid Build Coastguard Worker switch (pname)
4985*35238bceSAndroid Build Coastguard Worker {
4986*35238bceSAndroid Build Coastguard Worker case GL_EXTENSIONS:
4987*35238bceSAndroid Build Coastguard Worker return m_limits.extensionStr.c_str();
4988*35238bceSAndroid Build Coastguard Worker
4989*35238bceSAndroid Build Coastguard Worker default:
4990*35238bceSAndroid Build Coastguard Worker setError(GL_INVALID_ENUM);
4991*35238bceSAndroid Build Coastguard Worker return DE_NULL;
4992*35238bceSAndroid Build Coastguard Worker }
4993*35238bceSAndroid Build Coastguard Worker }
4994*35238bceSAndroid Build Coastguard Worker
4995*35238bceSAndroid Build Coastguard Worker namespace rc
4996*35238bceSAndroid Build Coastguard Worker {
4997*35238bceSAndroid Build Coastguard Worker
TextureLevelArray(void)4998*35238bceSAndroid Build Coastguard Worker TextureLevelArray::TextureLevelArray(void)
4999*35238bceSAndroid Build Coastguard Worker {
5000*35238bceSAndroid Build Coastguard Worker }
5001*35238bceSAndroid Build Coastguard Worker
~TextureLevelArray(void)5002*35238bceSAndroid Build Coastguard Worker TextureLevelArray::~TextureLevelArray(void)
5003*35238bceSAndroid Build Coastguard Worker {
5004*35238bceSAndroid Build Coastguard Worker clear();
5005*35238bceSAndroid Build Coastguard Worker }
5006*35238bceSAndroid Build Coastguard Worker
clear(void)5007*35238bceSAndroid Build Coastguard Worker void TextureLevelArray::clear(void)
5008*35238bceSAndroid Build Coastguard Worker {
5009*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(m_data) == DE_LENGTH_OF_ARRAY(m_access));
5010*35238bceSAndroid Build Coastguard Worker
5011*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(m_data); ndx++)
5012*35238bceSAndroid Build Coastguard Worker {
5013*35238bceSAndroid Build Coastguard Worker m_data[ndx].clear();
5014*35238bceSAndroid Build Coastguard Worker m_access[ndx] = PixelBufferAccess();
5015*35238bceSAndroid Build Coastguard Worker }
5016*35238bceSAndroid Build Coastguard Worker }
5017*35238bceSAndroid Build Coastguard Worker
allocLevel(int level,const tcu::TextureFormat & format,int width,int height,int depth)5018*35238bceSAndroid Build Coastguard Worker void TextureLevelArray::allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int depth)
5019*35238bceSAndroid Build Coastguard Worker {
5020*35238bceSAndroid Build Coastguard Worker const int dataSize = format.getPixelSize() * width * height * depth;
5021*35238bceSAndroid Build Coastguard Worker
5022*35238bceSAndroid Build Coastguard Worker DE_ASSERT(deInBounds32(level, 0, DE_LENGTH_OF_ARRAY(m_data)));
5023*35238bceSAndroid Build Coastguard Worker
5024*35238bceSAndroid Build Coastguard Worker if (hasLevel(level))
5025*35238bceSAndroid Build Coastguard Worker clearLevel(level);
5026*35238bceSAndroid Build Coastguard Worker
5027*35238bceSAndroid Build Coastguard Worker m_data[level].setStorage(dataSize);
5028*35238bceSAndroid Build Coastguard Worker m_access[level] = PixelBufferAccess(format, width, height, depth, m_data[level].getPtr());
5029*35238bceSAndroid Build Coastguard Worker }
5030*35238bceSAndroid Build Coastguard Worker
clearLevel(int level)5031*35238bceSAndroid Build Coastguard Worker void TextureLevelArray::clearLevel(int level)
5032*35238bceSAndroid Build Coastguard Worker {
5033*35238bceSAndroid Build Coastguard Worker DE_ASSERT(deInBounds32(level, 0, DE_LENGTH_OF_ARRAY(m_data)));
5034*35238bceSAndroid Build Coastguard Worker
5035*35238bceSAndroid Build Coastguard Worker m_data[level].clear();
5036*35238bceSAndroid Build Coastguard Worker m_access[level] = PixelBufferAccess();
5037*35238bceSAndroid Build Coastguard Worker }
5038*35238bceSAndroid Build Coastguard Worker
updateSamplerMode(tcu::Sampler::DepthStencilMode mode)5039*35238bceSAndroid Build Coastguard Worker void TextureLevelArray::updateSamplerMode(tcu::Sampler::DepthStencilMode mode)
5040*35238bceSAndroid Build Coastguard Worker {
5041*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 0; hasLevel(levelNdx); ++levelNdx)
5042*35238bceSAndroid Build Coastguard Worker m_effectiveAccess[levelNdx] = tcu::getEffectiveDepthStencilAccess(m_access[levelNdx], mode);
5043*35238bceSAndroid Build Coastguard Worker }
5044*35238bceSAndroid Build Coastguard Worker
Texture(uint32_t name,Type type,bool seamless)5045*35238bceSAndroid Build Coastguard Worker Texture::Texture(uint32_t name, Type type, bool seamless)
5046*35238bceSAndroid Build Coastguard Worker : NamedObject(name)
5047*35238bceSAndroid Build Coastguard Worker , m_type(type)
5048*35238bceSAndroid Build Coastguard Worker , m_immutable(false)
5049*35238bceSAndroid Build Coastguard Worker , m_sampler(tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL, tcu::Sampler::REPEAT_GL,
5050*35238bceSAndroid Build Coastguard Worker tcu::Sampler::NEAREST_MIPMAP_LINEAR, tcu::Sampler::LINEAR,
5051*35238bceSAndroid Build Coastguard Worker 0.0f, // LOD threshold
5052*35238bceSAndroid Build Coastguard Worker true, // normalized coords
5053*35238bceSAndroid Build Coastguard Worker tcu::Sampler::COMPAREMODE_NONE,
5054*35238bceSAndroid Build Coastguard Worker 0, // cmp channel ndx
5055*35238bceSAndroid Build Coastguard Worker tcu::Vec4(0.0f), // border color
5056*35238bceSAndroid Build Coastguard Worker seamless // seamless cube map, Default value is True.
5057*35238bceSAndroid Build Coastguard Worker )
5058*35238bceSAndroid Build Coastguard Worker , m_baseLevel(0)
5059*35238bceSAndroid Build Coastguard Worker , m_maxLevel(1000)
5060*35238bceSAndroid Build Coastguard Worker {
5061*35238bceSAndroid Build Coastguard Worker }
5062*35238bceSAndroid Build Coastguard Worker
Texture1D(uint32_t name)5063*35238bceSAndroid Build Coastguard Worker Texture1D::Texture1D(uint32_t name) : Texture(name, TYPE_1D), m_view(0, DE_NULL)
5064*35238bceSAndroid Build Coastguard Worker {
5065*35238bceSAndroid Build Coastguard Worker }
5066*35238bceSAndroid Build Coastguard Worker
~Texture1D(void)5067*35238bceSAndroid Build Coastguard Worker Texture1D::~Texture1D(void)
5068*35238bceSAndroid Build Coastguard Worker {
5069*35238bceSAndroid Build Coastguard Worker }
5070*35238bceSAndroid Build Coastguard Worker
allocLevel(int level,const tcu::TextureFormat & format,int width)5071*35238bceSAndroid Build Coastguard Worker void Texture1D::allocLevel(int level, const tcu::TextureFormat &format, int width)
5072*35238bceSAndroid Build Coastguard Worker {
5073*35238bceSAndroid Build Coastguard Worker m_levels.allocLevel(level, format, width, 1, 1);
5074*35238bceSAndroid Build Coastguard Worker }
5075*35238bceSAndroid Build Coastguard Worker
isComplete(void) const5076*35238bceSAndroid Build Coastguard Worker bool Texture1D::isComplete(void) const
5077*35238bceSAndroid Build Coastguard Worker {
5078*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5079*35238bceSAndroid Build Coastguard Worker
5080*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel))
5081*35238bceSAndroid Build Coastguard Worker {
5082*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level0 = getLevel(baseLevel);
5083*35238bceSAndroid Build Coastguard Worker const bool mipmap = isMipmapFilter(getSampler().minFilter);
5084*35238bceSAndroid Build Coastguard Worker
5085*35238bceSAndroid Build Coastguard Worker if (mipmap)
5086*35238bceSAndroid Build Coastguard Worker {
5087*35238bceSAndroid Build Coastguard Worker const TextureFormat &format = level0.getFormat();
5088*35238bceSAndroid Build Coastguard Worker const int w = level0.getWidth();
5089*35238bceSAndroid Build Coastguard Worker const int numLevels = de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels1D(w));
5090*35238bceSAndroid Build Coastguard Worker
5091*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 1; levelNdx < numLevels; levelNdx++)
5092*35238bceSAndroid Build Coastguard Worker {
5093*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel + levelNdx))
5094*35238bceSAndroid Build Coastguard Worker {
5095*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level = getLevel(baseLevel + levelNdx);
5096*35238bceSAndroid Build Coastguard Worker const int expectedW = getMipLevelSize(w, levelNdx);
5097*35238bceSAndroid Build Coastguard Worker
5098*35238bceSAndroid Build Coastguard Worker if (level.getWidth() != expectedW || level.getFormat() != format)
5099*35238bceSAndroid Build Coastguard Worker return false;
5100*35238bceSAndroid Build Coastguard Worker }
5101*35238bceSAndroid Build Coastguard Worker else
5102*35238bceSAndroid Build Coastguard Worker return false;
5103*35238bceSAndroid Build Coastguard Worker }
5104*35238bceSAndroid Build Coastguard Worker }
5105*35238bceSAndroid Build Coastguard Worker
5106*35238bceSAndroid Build Coastguard Worker return true;
5107*35238bceSAndroid Build Coastguard Worker }
5108*35238bceSAndroid Build Coastguard Worker else
5109*35238bceSAndroid Build Coastguard Worker return false;
5110*35238bceSAndroid Build Coastguard Worker }
5111*35238bceSAndroid Build Coastguard Worker
sample(float s,float lod) const5112*35238bceSAndroid Build Coastguard Worker tcu::Vec4 Texture1D::sample(float s, float lod) const
5113*35238bceSAndroid Build Coastguard Worker {
5114*35238bceSAndroid Build Coastguard Worker return m_view.sample(getSampler(), s, 0.0f, lod);
5115*35238bceSAndroid Build Coastguard Worker }
5116*35238bceSAndroid Build Coastguard Worker
sample4(tcu::Vec4 output[4],const float packetTexcoords[4],float lodBias) const5117*35238bceSAndroid Build Coastguard Worker void Texture1D::sample4(tcu::Vec4 output[4], const float packetTexcoords[4], float lodBias) const
5118*35238bceSAndroid Build Coastguard Worker {
5119*35238bceSAndroid Build Coastguard Worker const float texWidth = (float)m_view.getWidth();
5120*35238bceSAndroid Build Coastguard Worker
5121*35238bceSAndroid Build Coastguard Worker const float dFdx0 = packetTexcoords[1] - packetTexcoords[0];
5122*35238bceSAndroid Build Coastguard Worker const float dFdx1 = packetTexcoords[3] - packetTexcoords[2];
5123*35238bceSAndroid Build Coastguard Worker const float dFdy0 = packetTexcoords[2] - packetTexcoords[0];
5124*35238bceSAndroid Build Coastguard Worker const float dFdy1 = packetTexcoords[3] - packetTexcoords[1];
5125*35238bceSAndroid Build Coastguard Worker
5126*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5127*35238bceSAndroid Build Coastguard Worker {
5128*35238bceSAndroid Build Coastguard Worker const float &dFdx = (fragNdx > 2) ? dFdx1 : dFdx0;
5129*35238bceSAndroid Build Coastguard Worker const float &dFdy = (fragNdx % 2) ? dFdy1 : dFdy0;
5130*35238bceSAndroid Build Coastguard Worker
5131*35238bceSAndroid Build Coastguard Worker const float mu = de::max(de::abs(dFdx), de::abs(dFdy));
5132*35238bceSAndroid Build Coastguard Worker const float p = mu * texWidth;
5133*35238bceSAndroid Build Coastguard Worker
5134*35238bceSAndroid Build Coastguard Worker const float lod = deFloatLog2(p) + lodBias;
5135*35238bceSAndroid Build Coastguard Worker
5136*35238bceSAndroid Build Coastguard Worker output[fragNdx] = sample(packetTexcoords[fragNdx], lod);
5137*35238bceSAndroid Build Coastguard Worker }
5138*35238bceSAndroid Build Coastguard Worker }
5139*35238bceSAndroid Build Coastguard Worker
updateView(tcu::Sampler::DepthStencilMode mode)5140*35238bceSAndroid Build Coastguard Worker void Texture1D::updateView(tcu::Sampler::DepthStencilMode mode)
5141*35238bceSAndroid Build Coastguard Worker {
5142*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5143*35238bceSAndroid Build Coastguard Worker
5144*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel) && !isEmpty(getLevel(baseLevel)))
5145*35238bceSAndroid Build Coastguard Worker {
5146*35238bceSAndroid Build Coastguard Worker const int width = getLevel(baseLevel).getWidth();
5147*35238bceSAndroid Build Coastguard Worker const bool isMipmap = isMipmapFilter(getSampler().minFilter);
5148*35238bceSAndroid Build Coastguard Worker const int numLevels = isMipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels1D(width)) : 1;
5149*35238bceSAndroid Build Coastguard Worker
5150*35238bceSAndroid Build Coastguard Worker m_levels.updateSamplerMode(mode);
5151*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture2DView(numLevels, m_levels.getEffectiveLevels() + baseLevel);
5152*35238bceSAndroid Build Coastguard Worker }
5153*35238bceSAndroid Build Coastguard Worker else
5154*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture2DView(0, DE_NULL);
5155*35238bceSAndroid Build Coastguard Worker }
5156*35238bceSAndroid Build Coastguard Worker
Texture2D(uint32_t name,bool es2)5157*35238bceSAndroid Build Coastguard Worker Texture2D::Texture2D(uint32_t name, bool es2) : Texture(name, TYPE_2D), m_view(0, DE_NULL, es2)
5158*35238bceSAndroid Build Coastguard Worker {
5159*35238bceSAndroid Build Coastguard Worker }
5160*35238bceSAndroid Build Coastguard Worker
~Texture2D(void)5161*35238bceSAndroid Build Coastguard Worker Texture2D::~Texture2D(void)
5162*35238bceSAndroid Build Coastguard Worker {
5163*35238bceSAndroid Build Coastguard Worker }
5164*35238bceSAndroid Build Coastguard Worker
allocLevel(int level,const tcu::TextureFormat & format,int width,int height)5165*35238bceSAndroid Build Coastguard Worker void Texture2D::allocLevel(int level, const tcu::TextureFormat &format, int width, int height)
5166*35238bceSAndroid Build Coastguard Worker {
5167*35238bceSAndroid Build Coastguard Worker m_levels.allocLevel(level, format, width, height, 1);
5168*35238bceSAndroid Build Coastguard Worker }
5169*35238bceSAndroid Build Coastguard Worker
isComplete(void) const5170*35238bceSAndroid Build Coastguard Worker bool Texture2D::isComplete(void) const
5171*35238bceSAndroid Build Coastguard Worker {
5172*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5173*35238bceSAndroid Build Coastguard Worker
5174*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel))
5175*35238bceSAndroid Build Coastguard Worker {
5176*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level0 = getLevel(baseLevel);
5177*35238bceSAndroid Build Coastguard Worker const bool mipmap = isMipmapFilter(getSampler().minFilter);
5178*35238bceSAndroid Build Coastguard Worker
5179*35238bceSAndroid Build Coastguard Worker if (mipmap)
5180*35238bceSAndroid Build Coastguard Worker {
5181*35238bceSAndroid Build Coastguard Worker const TextureFormat &format = level0.getFormat();
5182*35238bceSAndroid Build Coastguard Worker const int w = level0.getWidth();
5183*35238bceSAndroid Build Coastguard Worker const int h = level0.getHeight();
5184*35238bceSAndroid Build Coastguard Worker const int numLevels = de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(w, h));
5185*35238bceSAndroid Build Coastguard Worker
5186*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 1; levelNdx < numLevels; levelNdx++)
5187*35238bceSAndroid Build Coastguard Worker {
5188*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel + levelNdx))
5189*35238bceSAndroid Build Coastguard Worker {
5190*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level = getLevel(baseLevel + levelNdx);
5191*35238bceSAndroid Build Coastguard Worker const int expectedW = getMipLevelSize(w, levelNdx);
5192*35238bceSAndroid Build Coastguard Worker const int expectedH = getMipLevelSize(h, levelNdx);
5193*35238bceSAndroid Build Coastguard Worker
5194*35238bceSAndroid Build Coastguard Worker if (level.getWidth() != expectedW || level.getHeight() != expectedH || level.getFormat() != format)
5195*35238bceSAndroid Build Coastguard Worker return false;
5196*35238bceSAndroid Build Coastguard Worker }
5197*35238bceSAndroid Build Coastguard Worker else
5198*35238bceSAndroid Build Coastguard Worker return false;
5199*35238bceSAndroid Build Coastguard Worker }
5200*35238bceSAndroid Build Coastguard Worker }
5201*35238bceSAndroid Build Coastguard Worker
5202*35238bceSAndroid Build Coastguard Worker return true;
5203*35238bceSAndroid Build Coastguard Worker }
5204*35238bceSAndroid Build Coastguard Worker else
5205*35238bceSAndroid Build Coastguard Worker return false;
5206*35238bceSAndroid Build Coastguard Worker }
5207*35238bceSAndroid Build Coastguard Worker
updateView(tcu::Sampler::DepthStencilMode mode)5208*35238bceSAndroid Build Coastguard Worker void Texture2D::updateView(tcu::Sampler::DepthStencilMode mode)
5209*35238bceSAndroid Build Coastguard Worker {
5210*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5211*35238bceSAndroid Build Coastguard Worker
5212*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel) && !isEmpty(getLevel(baseLevel)))
5213*35238bceSAndroid Build Coastguard Worker {
5214*35238bceSAndroid Build Coastguard Worker // Update number of levels in mipmap pyramid.
5215*35238bceSAndroid Build Coastguard Worker const int width = getLevel(baseLevel).getWidth();
5216*35238bceSAndroid Build Coastguard Worker const int height = getLevel(baseLevel).getHeight();
5217*35238bceSAndroid Build Coastguard Worker const bool isMipmap = isMipmapFilter(getSampler().minFilter);
5218*35238bceSAndroid Build Coastguard Worker const int numLevels = isMipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(width, height)) : 1;
5219*35238bceSAndroid Build Coastguard Worker
5220*35238bceSAndroid Build Coastguard Worker m_levels.updateSamplerMode(mode);
5221*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture2DView(numLevels, m_levels.getEffectiveLevels() + baseLevel);
5222*35238bceSAndroid Build Coastguard Worker }
5223*35238bceSAndroid Build Coastguard Worker else
5224*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture2DView(0, DE_NULL);
5225*35238bceSAndroid Build Coastguard Worker }
5226*35238bceSAndroid Build Coastguard Worker
sample(float s,float t,float lod) const5227*35238bceSAndroid Build Coastguard Worker tcu::Vec4 Texture2D::sample(float s, float t, float lod) const
5228*35238bceSAndroid Build Coastguard Worker {
5229*35238bceSAndroid Build Coastguard Worker return m_view.sample(getSampler(), s, t, lod);
5230*35238bceSAndroid Build Coastguard Worker }
5231*35238bceSAndroid Build Coastguard Worker
sample4(tcu::Vec4 output[4],const tcu::Vec2 packetTexcoords[4],float lodBias) const5232*35238bceSAndroid Build Coastguard Worker void Texture2D::sample4(tcu::Vec4 output[4], const tcu::Vec2 packetTexcoords[4], float lodBias) const
5233*35238bceSAndroid Build Coastguard Worker {
5234*35238bceSAndroid Build Coastguard Worker const float texWidth = (float)m_view.getWidth();
5235*35238bceSAndroid Build Coastguard Worker const float texHeight = (float)m_view.getHeight();
5236*35238bceSAndroid Build Coastguard Worker
5237*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdx0 = packetTexcoords[1] - packetTexcoords[0];
5238*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdx1 = packetTexcoords[3] - packetTexcoords[2];
5239*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdy0 = packetTexcoords[2] - packetTexcoords[0];
5240*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdy1 = packetTexcoords[3] - packetTexcoords[1];
5241*35238bceSAndroid Build Coastguard Worker
5242*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5243*35238bceSAndroid Build Coastguard Worker {
5244*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 &dFdx = (fragNdx & 2) ? dFdx1 : dFdx0;
5245*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 &dFdy = (fragNdx & 1) ? dFdy1 : dFdy0;
5246*35238bceSAndroid Build Coastguard Worker
5247*35238bceSAndroid Build Coastguard Worker const float mu = de::max(de::abs(dFdx.x()), de::abs(dFdy.x()));
5248*35238bceSAndroid Build Coastguard Worker const float mv = de::max(de::abs(dFdx.y()), de::abs(dFdy.y()));
5249*35238bceSAndroid Build Coastguard Worker const float p = de::max(mu * texWidth, mv * texHeight);
5250*35238bceSAndroid Build Coastguard Worker
5251*35238bceSAndroid Build Coastguard Worker const float lod = deFloatLog2(p) + lodBias;
5252*35238bceSAndroid Build Coastguard Worker
5253*35238bceSAndroid Build Coastguard Worker output[fragNdx] = sample(packetTexcoords[fragNdx].x(), packetTexcoords[fragNdx].y(), lod);
5254*35238bceSAndroid Build Coastguard Worker }
5255*35238bceSAndroid Build Coastguard Worker }
5256*35238bceSAndroid Build Coastguard Worker
TextureCube(uint32_t name,bool seamless)5257*35238bceSAndroid Build Coastguard Worker TextureCube::TextureCube(uint32_t name, bool seamless) : Texture(name, TYPE_CUBE_MAP, seamless)
5258*35238bceSAndroid Build Coastguard Worker {
5259*35238bceSAndroid Build Coastguard Worker }
5260*35238bceSAndroid Build Coastguard Worker
~TextureCube(void)5261*35238bceSAndroid Build Coastguard Worker TextureCube::~TextureCube(void)
5262*35238bceSAndroid Build Coastguard Worker {
5263*35238bceSAndroid Build Coastguard Worker }
5264*35238bceSAndroid Build Coastguard Worker
clearLevels(void)5265*35238bceSAndroid Build Coastguard Worker void TextureCube::clearLevels(void)
5266*35238bceSAndroid Build Coastguard Worker {
5267*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
5268*35238bceSAndroid Build Coastguard Worker m_levels[face].clear();
5269*35238bceSAndroid Build Coastguard Worker }
5270*35238bceSAndroid Build Coastguard Worker
allocFace(int level,tcu::CubeFace face,const tcu::TextureFormat & format,int width,int height)5271*35238bceSAndroid Build Coastguard Worker void TextureCube::allocFace(int level, tcu::CubeFace face, const tcu::TextureFormat &format, int width, int height)
5272*35238bceSAndroid Build Coastguard Worker {
5273*35238bceSAndroid Build Coastguard Worker m_levels[face].allocLevel(level, format, width, height, 1);
5274*35238bceSAndroid Build Coastguard Worker }
5275*35238bceSAndroid Build Coastguard Worker
isComplete(void) const5276*35238bceSAndroid Build Coastguard Worker bool TextureCube::isComplete(void) const
5277*35238bceSAndroid Build Coastguard Worker {
5278*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5279*35238bceSAndroid Build Coastguard Worker
5280*35238bceSAndroid Build Coastguard Worker if (hasFace(baseLevel, tcu::CUBEFACE_NEGATIVE_X))
5281*35238bceSAndroid Build Coastguard Worker {
5282*35238bceSAndroid Build Coastguard Worker const int width = getFace(baseLevel, tcu::CUBEFACE_NEGATIVE_X).getWidth();
5283*35238bceSAndroid Build Coastguard Worker const int height = getFace(baseLevel, tcu::CUBEFACE_NEGATIVE_X).getHeight();
5284*35238bceSAndroid Build Coastguard Worker const tcu::TextureFormat &format = getFace(baseLevel, tcu::CUBEFACE_NEGATIVE_X).getFormat();
5285*35238bceSAndroid Build Coastguard Worker const bool mipmap = isMipmapFilter(getSampler().minFilter);
5286*35238bceSAndroid Build Coastguard Worker const int numLevels = mipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(width, height)) : 1;
5287*35238bceSAndroid Build Coastguard Worker
5288*35238bceSAndroid Build Coastguard Worker if (width != height)
5289*35238bceSAndroid Build Coastguard Worker return false; // Non-square is not supported.
5290*35238bceSAndroid Build Coastguard Worker
5291*35238bceSAndroid Build Coastguard Worker // \note Level 0 is always checked for consistency
5292*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
5293*35238bceSAndroid Build Coastguard Worker {
5294*35238bceSAndroid Build Coastguard Worker const int levelW = getMipLevelSize(width, levelNdx);
5295*35238bceSAndroid Build Coastguard Worker const int levelH = getMipLevelSize(height, levelNdx);
5296*35238bceSAndroid Build Coastguard Worker
5297*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
5298*35238bceSAndroid Build Coastguard Worker {
5299*35238bceSAndroid Build Coastguard Worker if (hasFace(baseLevel + levelNdx, (tcu::CubeFace)face))
5300*35238bceSAndroid Build Coastguard Worker {
5301*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level = getFace(baseLevel + levelNdx, (tcu::CubeFace)face);
5302*35238bceSAndroid Build Coastguard Worker
5303*35238bceSAndroid Build Coastguard Worker if (level.getWidth() != levelW || level.getHeight() != levelH || level.getFormat() != format)
5304*35238bceSAndroid Build Coastguard Worker return false;
5305*35238bceSAndroid Build Coastguard Worker }
5306*35238bceSAndroid Build Coastguard Worker else
5307*35238bceSAndroid Build Coastguard Worker return false;
5308*35238bceSAndroid Build Coastguard Worker }
5309*35238bceSAndroid Build Coastguard Worker }
5310*35238bceSAndroid Build Coastguard Worker
5311*35238bceSAndroid Build Coastguard Worker return true;
5312*35238bceSAndroid Build Coastguard Worker }
5313*35238bceSAndroid Build Coastguard Worker else
5314*35238bceSAndroid Build Coastguard Worker return false;
5315*35238bceSAndroid Build Coastguard Worker }
5316*35238bceSAndroid Build Coastguard Worker
updateView(tcu::Sampler::DepthStencilMode mode)5317*35238bceSAndroid Build Coastguard Worker void TextureCube::updateView(tcu::Sampler::DepthStencilMode mode)
5318*35238bceSAndroid Build Coastguard Worker {
5319*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5320*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess *faces[tcu::CUBEFACE_LAST];
5321*35238bceSAndroid Build Coastguard Worker
5322*35238bceSAndroid Build Coastguard Worker deMemset(&faces[0], 0, sizeof(faces));
5323*35238bceSAndroid Build Coastguard Worker
5324*35238bceSAndroid Build Coastguard Worker if (isComplete())
5325*35238bceSAndroid Build Coastguard Worker {
5326*35238bceSAndroid Build Coastguard Worker const int size = getFace(baseLevel, tcu::CUBEFACE_NEGATIVE_X).getWidth();
5327*35238bceSAndroid Build Coastguard Worker const bool isMipmap = isMipmapFilter(getSampler().minFilter);
5328*35238bceSAndroid Build Coastguard Worker const int numLevels = isMipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels1D(size)) : 1;
5329*35238bceSAndroid Build Coastguard Worker
5330*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
5331*35238bceSAndroid Build Coastguard Worker {
5332*35238bceSAndroid Build Coastguard Worker m_levels[face].updateSamplerMode(mode);
5333*35238bceSAndroid Build Coastguard Worker faces[face] = m_levels[face].getEffectiveLevels() + baseLevel;
5334*35238bceSAndroid Build Coastguard Worker }
5335*35238bceSAndroid Build Coastguard Worker
5336*35238bceSAndroid Build Coastguard Worker m_view = tcu::TextureCubeView(numLevels, faces);
5337*35238bceSAndroid Build Coastguard Worker }
5338*35238bceSAndroid Build Coastguard Worker else
5339*35238bceSAndroid Build Coastguard Worker m_view = tcu::TextureCubeView(0, faces);
5340*35238bceSAndroid Build Coastguard Worker }
5341*35238bceSAndroid Build Coastguard Worker
sample(float s,float t,float p,float lod) const5342*35238bceSAndroid Build Coastguard Worker tcu::Vec4 TextureCube::sample(float s, float t, float p, float lod) const
5343*35238bceSAndroid Build Coastguard Worker {
5344*35238bceSAndroid Build Coastguard Worker return m_view.sample(getSampler(), s, t, p, lod);
5345*35238bceSAndroid Build Coastguard Worker }
5346*35238bceSAndroid Build Coastguard Worker
sample4(tcu::Vec4 output[4],const tcu::Vec3 packetTexcoords[4],float lodBias) const5347*35238bceSAndroid Build Coastguard Worker void TextureCube::sample4(tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias) const
5348*35238bceSAndroid Build Coastguard Worker {
5349*35238bceSAndroid Build Coastguard Worker const float cubeSide = (float)m_view.getSize();
5350*35238bceSAndroid Build Coastguard Worker
5351*35238bceSAndroid Build Coastguard Worker // Each tex coord might be in a different face.
5352*35238bceSAndroid Build Coastguard Worker
5353*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5354*35238bceSAndroid Build Coastguard Worker {
5355*35238bceSAndroid Build Coastguard Worker const tcu::CubeFace face = tcu::selectCubeFace(packetTexcoords[fragNdx]);
5356*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 coords[4] = {
5357*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, packetTexcoords[0]),
5358*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, packetTexcoords[1]),
5359*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, packetTexcoords[2]),
5360*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, packetTexcoords[3]),
5361*35238bceSAndroid Build Coastguard Worker };
5362*35238bceSAndroid Build Coastguard Worker
5363*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdx0 = coords[1] - coords[0];
5364*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdx1 = coords[3] - coords[2];
5365*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdy0 = coords[2] - coords[0];
5366*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdy1 = coords[3] - coords[1];
5367*35238bceSAndroid Build Coastguard Worker
5368*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 &dFdx = (fragNdx & 2) ? dFdx1 : dFdx0;
5369*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 &dFdy = (fragNdx & 1) ? dFdy1 : dFdy0;
5370*35238bceSAndroid Build Coastguard Worker
5371*35238bceSAndroid Build Coastguard Worker const float mu = de::max(de::abs(dFdx.x()), de::abs(dFdy.x()));
5372*35238bceSAndroid Build Coastguard Worker const float mv = de::max(de::abs(dFdx.y()), de::abs(dFdy.y()));
5373*35238bceSAndroid Build Coastguard Worker const float p = de::max(mu * cubeSide, mv * cubeSide);
5374*35238bceSAndroid Build Coastguard Worker
5375*35238bceSAndroid Build Coastguard Worker const float lod = deFloatLog2(p) + lodBias;
5376*35238bceSAndroid Build Coastguard Worker
5377*35238bceSAndroid Build Coastguard Worker output[fragNdx] =
5378*35238bceSAndroid Build Coastguard Worker sample(packetTexcoords[fragNdx].x(), packetTexcoords[fragNdx].y(), packetTexcoords[fragNdx].z(), lod);
5379*35238bceSAndroid Build Coastguard Worker }
5380*35238bceSAndroid Build Coastguard Worker }
5381*35238bceSAndroid Build Coastguard Worker
Texture2DArray(uint32_t name)5382*35238bceSAndroid Build Coastguard Worker Texture2DArray::Texture2DArray(uint32_t name) : Texture(name, TYPE_2D_ARRAY), m_view(0, DE_NULL)
5383*35238bceSAndroid Build Coastguard Worker {
5384*35238bceSAndroid Build Coastguard Worker }
5385*35238bceSAndroid Build Coastguard Worker
~Texture2DArray(void)5386*35238bceSAndroid Build Coastguard Worker Texture2DArray::~Texture2DArray(void)
5387*35238bceSAndroid Build Coastguard Worker {
5388*35238bceSAndroid Build Coastguard Worker }
5389*35238bceSAndroid Build Coastguard Worker
allocLevel(int level,const tcu::TextureFormat & format,int width,int height,int numLayers)5390*35238bceSAndroid Build Coastguard Worker void Texture2DArray::allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int numLayers)
5391*35238bceSAndroid Build Coastguard Worker {
5392*35238bceSAndroid Build Coastguard Worker m_levels.allocLevel(level, format, width, height, numLayers);
5393*35238bceSAndroid Build Coastguard Worker }
5394*35238bceSAndroid Build Coastguard Worker
isComplete(void) const5395*35238bceSAndroid Build Coastguard Worker bool Texture2DArray::isComplete(void) const
5396*35238bceSAndroid Build Coastguard Worker {
5397*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5398*35238bceSAndroid Build Coastguard Worker
5399*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel))
5400*35238bceSAndroid Build Coastguard Worker {
5401*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level0 = getLevel(baseLevel);
5402*35238bceSAndroid Build Coastguard Worker const bool mipmap = isMipmapFilter(getSampler().minFilter);
5403*35238bceSAndroid Build Coastguard Worker
5404*35238bceSAndroid Build Coastguard Worker if (mipmap)
5405*35238bceSAndroid Build Coastguard Worker {
5406*35238bceSAndroid Build Coastguard Worker const TextureFormat &format = level0.getFormat();
5407*35238bceSAndroid Build Coastguard Worker const int w = level0.getWidth();
5408*35238bceSAndroid Build Coastguard Worker const int h = level0.getHeight();
5409*35238bceSAndroid Build Coastguard Worker const int numLayers = level0.getDepth();
5410*35238bceSAndroid Build Coastguard Worker const int numLevels = de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(w, h));
5411*35238bceSAndroid Build Coastguard Worker
5412*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 1; levelNdx < numLevels; levelNdx++)
5413*35238bceSAndroid Build Coastguard Worker {
5414*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel + levelNdx))
5415*35238bceSAndroid Build Coastguard Worker {
5416*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level = getLevel(baseLevel + levelNdx);
5417*35238bceSAndroid Build Coastguard Worker const int expectedW = getMipLevelSize(w, levelNdx);
5418*35238bceSAndroid Build Coastguard Worker const int expectedH = getMipLevelSize(h, levelNdx);
5419*35238bceSAndroid Build Coastguard Worker
5420*35238bceSAndroid Build Coastguard Worker if (level.getWidth() != expectedW || level.getHeight() != expectedH ||
5421*35238bceSAndroid Build Coastguard Worker level.getDepth() != numLayers || level.getFormat() != format)
5422*35238bceSAndroid Build Coastguard Worker return false;
5423*35238bceSAndroid Build Coastguard Worker }
5424*35238bceSAndroid Build Coastguard Worker else
5425*35238bceSAndroid Build Coastguard Worker return false;
5426*35238bceSAndroid Build Coastguard Worker }
5427*35238bceSAndroid Build Coastguard Worker }
5428*35238bceSAndroid Build Coastguard Worker
5429*35238bceSAndroid Build Coastguard Worker return true;
5430*35238bceSAndroid Build Coastguard Worker }
5431*35238bceSAndroid Build Coastguard Worker else
5432*35238bceSAndroid Build Coastguard Worker return false;
5433*35238bceSAndroid Build Coastguard Worker }
5434*35238bceSAndroid Build Coastguard Worker
updateView(tcu::Sampler::DepthStencilMode mode)5435*35238bceSAndroid Build Coastguard Worker void Texture2DArray::updateView(tcu::Sampler::DepthStencilMode mode)
5436*35238bceSAndroid Build Coastguard Worker {
5437*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5438*35238bceSAndroid Build Coastguard Worker
5439*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel) && !isEmpty(getLevel(baseLevel)))
5440*35238bceSAndroid Build Coastguard Worker {
5441*35238bceSAndroid Build Coastguard Worker const int width = getLevel(baseLevel).getWidth();
5442*35238bceSAndroid Build Coastguard Worker const int height = getLevel(baseLevel).getHeight();
5443*35238bceSAndroid Build Coastguard Worker const bool isMipmap = isMipmapFilter(getSampler().minFilter);
5444*35238bceSAndroid Build Coastguard Worker const int numLevels = isMipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(width, height)) : 1;
5445*35238bceSAndroid Build Coastguard Worker
5446*35238bceSAndroid Build Coastguard Worker m_levels.updateSamplerMode(mode);
5447*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture2DArrayView(numLevels, m_levels.getEffectiveLevels() + baseLevel);
5448*35238bceSAndroid Build Coastguard Worker }
5449*35238bceSAndroid Build Coastguard Worker else
5450*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture2DArrayView(0, DE_NULL);
5451*35238bceSAndroid Build Coastguard Worker }
5452*35238bceSAndroid Build Coastguard Worker
sample(float s,float t,float r,float lod) const5453*35238bceSAndroid Build Coastguard Worker tcu::Vec4 Texture2DArray::sample(float s, float t, float r, float lod) const
5454*35238bceSAndroid Build Coastguard Worker {
5455*35238bceSAndroid Build Coastguard Worker return m_view.sample(getSampler(), s, t, r, lod);
5456*35238bceSAndroid Build Coastguard Worker }
5457*35238bceSAndroid Build Coastguard Worker
sample4(tcu::Vec4 output[4],const tcu::Vec3 packetTexcoords[4],float lodBias) const5458*35238bceSAndroid Build Coastguard Worker void Texture2DArray::sample4(tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias) const
5459*35238bceSAndroid Build Coastguard Worker {
5460*35238bceSAndroid Build Coastguard Worker const float texWidth = (float)m_view.getWidth();
5461*35238bceSAndroid Build Coastguard Worker const float texHeight = (float)m_view.getHeight();
5462*35238bceSAndroid Build Coastguard Worker
5463*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdx0 = packetTexcoords[1] - packetTexcoords[0];
5464*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdx1 = packetTexcoords[3] - packetTexcoords[2];
5465*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdy0 = packetTexcoords[2] - packetTexcoords[0];
5466*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdy1 = packetTexcoords[3] - packetTexcoords[1];
5467*35238bceSAndroid Build Coastguard Worker
5468*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5469*35238bceSAndroid Build Coastguard Worker {
5470*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 &dFdx = (fragNdx & 2) ? dFdx1 : dFdx0;
5471*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 &dFdy = (fragNdx & 1) ? dFdy1 : dFdy0;
5472*35238bceSAndroid Build Coastguard Worker
5473*35238bceSAndroid Build Coastguard Worker const float mu = de::max(de::abs(dFdx.x()), de::abs(dFdy.x()));
5474*35238bceSAndroid Build Coastguard Worker const float mv = de::max(de::abs(dFdx.y()), de::abs(dFdy.y()));
5475*35238bceSAndroid Build Coastguard Worker const float p = de::max(mu * texWidth, mv * texHeight);
5476*35238bceSAndroid Build Coastguard Worker
5477*35238bceSAndroid Build Coastguard Worker const float lod = deFloatLog2(p) + lodBias;
5478*35238bceSAndroid Build Coastguard Worker
5479*35238bceSAndroid Build Coastguard Worker output[fragNdx] =
5480*35238bceSAndroid Build Coastguard Worker sample(packetTexcoords[fragNdx].x(), packetTexcoords[fragNdx].y(), packetTexcoords[fragNdx].z(), lod);
5481*35238bceSAndroid Build Coastguard Worker }
5482*35238bceSAndroid Build Coastguard Worker }
5483*35238bceSAndroid Build Coastguard Worker
TextureCubeArray(uint32_t name)5484*35238bceSAndroid Build Coastguard Worker TextureCubeArray::TextureCubeArray(uint32_t name) : Texture(name, TYPE_CUBE_MAP_ARRAY), m_view(0, DE_NULL)
5485*35238bceSAndroid Build Coastguard Worker {
5486*35238bceSAndroid Build Coastguard Worker }
5487*35238bceSAndroid Build Coastguard Worker
~TextureCubeArray(void)5488*35238bceSAndroid Build Coastguard Worker TextureCubeArray::~TextureCubeArray(void)
5489*35238bceSAndroid Build Coastguard Worker {
5490*35238bceSAndroid Build Coastguard Worker }
5491*35238bceSAndroid Build Coastguard Worker
allocLevel(int level,const tcu::TextureFormat & format,int width,int height,int numLayers)5492*35238bceSAndroid Build Coastguard Worker void TextureCubeArray::allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int numLayers)
5493*35238bceSAndroid Build Coastguard Worker {
5494*35238bceSAndroid Build Coastguard Worker DE_ASSERT(numLayers % 6 == 0);
5495*35238bceSAndroid Build Coastguard Worker m_levels.allocLevel(level, format, width, height, numLayers);
5496*35238bceSAndroid Build Coastguard Worker }
5497*35238bceSAndroid Build Coastguard Worker
isComplete(void) const5498*35238bceSAndroid Build Coastguard Worker bool TextureCubeArray::isComplete(void) const
5499*35238bceSAndroid Build Coastguard Worker {
5500*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5501*35238bceSAndroid Build Coastguard Worker
5502*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel))
5503*35238bceSAndroid Build Coastguard Worker {
5504*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level0 = getLevel(baseLevel);
5505*35238bceSAndroid Build Coastguard Worker const bool mipmap = isMipmapFilter(getSampler().minFilter);
5506*35238bceSAndroid Build Coastguard Worker
5507*35238bceSAndroid Build Coastguard Worker if (mipmap)
5508*35238bceSAndroid Build Coastguard Worker {
5509*35238bceSAndroid Build Coastguard Worker const TextureFormat &format = level0.getFormat();
5510*35238bceSAndroid Build Coastguard Worker const int w = level0.getWidth();
5511*35238bceSAndroid Build Coastguard Worker const int h = level0.getHeight();
5512*35238bceSAndroid Build Coastguard Worker const int numLayers = level0.getDepth();
5513*35238bceSAndroid Build Coastguard Worker const int numLevels = de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(w, h));
5514*35238bceSAndroid Build Coastguard Worker
5515*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 1; levelNdx < numLevels; levelNdx++)
5516*35238bceSAndroid Build Coastguard Worker {
5517*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel + levelNdx))
5518*35238bceSAndroid Build Coastguard Worker {
5519*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level = getLevel(baseLevel + levelNdx);
5520*35238bceSAndroid Build Coastguard Worker const int expectedW = getMipLevelSize(w, levelNdx);
5521*35238bceSAndroid Build Coastguard Worker const int expectedH = getMipLevelSize(h, levelNdx);
5522*35238bceSAndroid Build Coastguard Worker
5523*35238bceSAndroid Build Coastguard Worker if (level.getWidth() != expectedW || level.getHeight() != expectedH ||
5524*35238bceSAndroid Build Coastguard Worker level.getDepth() != numLayers || level.getFormat() != format)
5525*35238bceSAndroid Build Coastguard Worker return false;
5526*35238bceSAndroid Build Coastguard Worker }
5527*35238bceSAndroid Build Coastguard Worker else
5528*35238bceSAndroid Build Coastguard Worker return false;
5529*35238bceSAndroid Build Coastguard Worker }
5530*35238bceSAndroid Build Coastguard Worker }
5531*35238bceSAndroid Build Coastguard Worker
5532*35238bceSAndroid Build Coastguard Worker return true;
5533*35238bceSAndroid Build Coastguard Worker }
5534*35238bceSAndroid Build Coastguard Worker else
5535*35238bceSAndroid Build Coastguard Worker return false;
5536*35238bceSAndroid Build Coastguard Worker }
5537*35238bceSAndroid Build Coastguard Worker
updateView(tcu::Sampler::DepthStencilMode mode)5538*35238bceSAndroid Build Coastguard Worker void TextureCubeArray::updateView(tcu::Sampler::DepthStencilMode mode)
5539*35238bceSAndroid Build Coastguard Worker {
5540*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5541*35238bceSAndroid Build Coastguard Worker
5542*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel) && !isEmpty(getLevel(baseLevel)))
5543*35238bceSAndroid Build Coastguard Worker {
5544*35238bceSAndroid Build Coastguard Worker const int width = getLevel(baseLevel).getWidth();
5545*35238bceSAndroid Build Coastguard Worker const int height = getLevel(baseLevel).getHeight();
5546*35238bceSAndroid Build Coastguard Worker const bool isMipmap = isMipmapFilter(getSampler().minFilter);
5547*35238bceSAndroid Build Coastguard Worker const int numLevels = isMipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels2D(width, height)) : 1;
5548*35238bceSAndroid Build Coastguard Worker
5549*35238bceSAndroid Build Coastguard Worker m_levels.updateSamplerMode(mode);
5550*35238bceSAndroid Build Coastguard Worker m_view = tcu::TextureCubeArrayView(numLevels, m_levels.getEffectiveLevels() + baseLevel);
5551*35238bceSAndroid Build Coastguard Worker }
5552*35238bceSAndroid Build Coastguard Worker else
5553*35238bceSAndroid Build Coastguard Worker m_view = tcu::TextureCubeArrayView(0, DE_NULL);
5554*35238bceSAndroid Build Coastguard Worker }
5555*35238bceSAndroid Build Coastguard Worker
sample(float s,float t,float r,float q,float lod) const5556*35238bceSAndroid Build Coastguard Worker tcu::Vec4 TextureCubeArray::sample(float s, float t, float r, float q, float lod) const
5557*35238bceSAndroid Build Coastguard Worker {
5558*35238bceSAndroid Build Coastguard Worker return m_view.sample(getSampler(), s, t, r, q, lod);
5559*35238bceSAndroid Build Coastguard Worker }
5560*35238bceSAndroid Build Coastguard Worker
sample4(tcu::Vec4 output[4],const tcu::Vec4 packetTexcoords[4],float lodBias) const5561*35238bceSAndroid Build Coastguard Worker void TextureCubeArray::sample4(tcu::Vec4 output[4], const tcu::Vec4 packetTexcoords[4], float lodBias) const
5562*35238bceSAndroid Build Coastguard Worker {
5563*35238bceSAndroid Build Coastguard Worker const float cubeSide = (float)m_view.getSize();
5564*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 cubeCoords[4] = {packetTexcoords[0].toWidth<3>(), packetTexcoords[1].toWidth<3>(),
5565*35238bceSAndroid Build Coastguard Worker packetTexcoords[2].toWidth<3>(), packetTexcoords[3].toWidth<3>()};
5566*35238bceSAndroid Build Coastguard Worker
5567*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5568*35238bceSAndroid Build Coastguard Worker {
5569*35238bceSAndroid Build Coastguard Worker const tcu::CubeFace face = tcu::selectCubeFace(cubeCoords[fragNdx]);
5570*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 faceCoords[4] = {
5571*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, cubeCoords[0]),
5572*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, cubeCoords[1]),
5573*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, cubeCoords[2]),
5574*35238bceSAndroid Build Coastguard Worker tcu::projectToFace(face, cubeCoords[3]),
5575*35238bceSAndroid Build Coastguard Worker };
5576*35238bceSAndroid Build Coastguard Worker
5577*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdx0 = faceCoords[1] - faceCoords[0];
5578*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdx1 = faceCoords[3] - faceCoords[2];
5579*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdy0 = faceCoords[2] - faceCoords[0];
5580*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 dFdy1 = faceCoords[3] - faceCoords[1];
5581*35238bceSAndroid Build Coastguard Worker
5582*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 &dFdx = (fragNdx & 2) ? dFdx1 : dFdx0;
5583*35238bceSAndroid Build Coastguard Worker const tcu::Vec2 &dFdy = (fragNdx & 1) ? dFdy1 : dFdy0;
5584*35238bceSAndroid Build Coastguard Worker
5585*35238bceSAndroid Build Coastguard Worker const float mu = de::max(de::abs(dFdx.x()), de::abs(dFdy.x()));
5586*35238bceSAndroid Build Coastguard Worker const float mv = de::max(de::abs(dFdx.y()), de::abs(dFdy.y()));
5587*35238bceSAndroid Build Coastguard Worker const float p = de::max(mu * cubeSide, mv * cubeSide);
5588*35238bceSAndroid Build Coastguard Worker
5589*35238bceSAndroid Build Coastguard Worker const float lod = deFloatLog2(p) + lodBias;
5590*35238bceSAndroid Build Coastguard Worker
5591*35238bceSAndroid Build Coastguard Worker output[fragNdx] = sample(packetTexcoords[fragNdx].x(), packetTexcoords[fragNdx].y(),
5592*35238bceSAndroid Build Coastguard Worker packetTexcoords[fragNdx].z(), packetTexcoords[fragNdx].w(), lod);
5593*35238bceSAndroid Build Coastguard Worker }
5594*35238bceSAndroid Build Coastguard Worker }
5595*35238bceSAndroid Build Coastguard Worker
Texture3D(uint32_t name)5596*35238bceSAndroid Build Coastguard Worker Texture3D::Texture3D(uint32_t name) : Texture(name, TYPE_3D), m_view(0, DE_NULL)
5597*35238bceSAndroid Build Coastguard Worker {
5598*35238bceSAndroid Build Coastguard Worker }
5599*35238bceSAndroid Build Coastguard Worker
~Texture3D(void)5600*35238bceSAndroid Build Coastguard Worker Texture3D::~Texture3D(void)
5601*35238bceSAndroid Build Coastguard Worker {
5602*35238bceSAndroid Build Coastguard Worker }
5603*35238bceSAndroid Build Coastguard Worker
allocLevel(int level,const tcu::TextureFormat & format,int width,int height,int depth)5604*35238bceSAndroid Build Coastguard Worker void Texture3D::allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int depth)
5605*35238bceSAndroid Build Coastguard Worker {
5606*35238bceSAndroid Build Coastguard Worker m_levels.allocLevel(level, format, width, height, depth);
5607*35238bceSAndroid Build Coastguard Worker }
5608*35238bceSAndroid Build Coastguard Worker
isComplete(void) const5609*35238bceSAndroid Build Coastguard Worker bool Texture3D::isComplete(void) const
5610*35238bceSAndroid Build Coastguard Worker {
5611*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5612*35238bceSAndroid Build Coastguard Worker
5613*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel))
5614*35238bceSAndroid Build Coastguard Worker {
5615*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level0 = getLevel(baseLevel);
5616*35238bceSAndroid Build Coastguard Worker const bool mipmap = isMipmapFilter(getSampler().minFilter);
5617*35238bceSAndroid Build Coastguard Worker
5618*35238bceSAndroid Build Coastguard Worker if (mipmap)
5619*35238bceSAndroid Build Coastguard Worker {
5620*35238bceSAndroid Build Coastguard Worker const TextureFormat &format = level0.getFormat();
5621*35238bceSAndroid Build Coastguard Worker const int w = level0.getWidth();
5622*35238bceSAndroid Build Coastguard Worker const int h = level0.getHeight();
5623*35238bceSAndroid Build Coastguard Worker const int d = level0.getDepth();
5624*35238bceSAndroid Build Coastguard Worker const int numLevels = de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels3D(w, h, d));
5625*35238bceSAndroid Build Coastguard Worker
5626*35238bceSAndroid Build Coastguard Worker for (int levelNdx = 1; levelNdx < numLevels; levelNdx++)
5627*35238bceSAndroid Build Coastguard Worker {
5628*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel + levelNdx))
5629*35238bceSAndroid Build Coastguard Worker {
5630*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &level = getLevel(baseLevel + levelNdx);
5631*35238bceSAndroid Build Coastguard Worker const int expectedW = getMipLevelSize(w, levelNdx);
5632*35238bceSAndroid Build Coastguard Worker const int expectedH = getMipLevelSize(h, levelNdx);
5633*35238bceSAndroid Build Coastguard Worker const int expectedD = getMipLevelSize(d, levelNdx);
5634*35238bceSAndroid Build Coastguard Worker
5635*35238bceSAndroid Build Coastguard Worker if (level.getWidth() != expectedW || level.getHeight() != expectedH ||
5636*35238bceSAndroid Build Coastguard Worker level.getDepth() != expectedD || level.getFormat() != format)
5637*35238bceSAndroid Build Coastguard Worker return false;
5638*35238bceSAndroid Build Coastguard Worker }
5639*35238bceSAndroid Build Coastguard Worker else
5640*35238bceSAndroid Build Coastguard Worker return false;
5641*35238bceSAndroid Build Coastguard Worker }
5642*35238bceSAndroid Build Coastguard Worker }
5643*35238bceSAndroid Build Coastguard Worker
5644*35238bceSAndroid Build Coastguard Worker return true;
5645*35238bceSAndroid Build Coastguard Worker }
5646*35238bceSAndroid Build Coastguard Worker else
5647*35238bceSAndroid Build Coastguard Worker return false;
5648*35238bceSAndroid Build Coastguard Worker }
5649*35238bceSAndroid Build Coastguard Worker
sample(float s,float t,float r,float lod) const5650*35238bceSAndroid Build Coastguard Worker tcu::Vec4 Texture3D::sample(float s, float t, float r, float lod) const
5651*35238bceSAndroid Build Coastguard Worker {
5652*35238bceSAndroid Build Coastguard Worker return m_view.sample(getSampler(), s, t, r, lod);
5653*35238bceSAndroid Build Coastguard Worker }
5654*35238bceSAndroid Build Coastguard Worker
sample4(tcu::Vec4 output[4],const tcu::Vec3 packetTexcoords[4],float lodBias) const5655*35238bceSAndroid Build Coastguard Worker void Texture3D::sample4(tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias) const
5656*35238bceSAndroid Build Coastguard Worker {
5657*35238bceSAndroid Build Coastguard Worker const float texWidth = (float)m_view.getWidth();
5658*35238bceSAndroid Build Coastguard Worker const float texHeight = (float)m_view.getHeight();
5659*35238bceSAndroid Build Coastguard Worker const float texDepth = (float)m_view.getDepth();
5660*35238bceSAndroid Build Coastguard Worker
5661*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdx0 = packetTexcoords[1] - packetTexcoords[0];
5662*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdx1 = packetTexcoords[3] - packetTexcoords[2];
5663*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdy0 = packetTexcoords[2] - packetTexcoords[0];
5664*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 dFdy1 = packetTexcoords[3] - packetTexcoords[1];
5665*35238bceSAndroid Build Coastguard Worker
5666*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
5667*35238bceSAndroid Build Coastguard Worker {
5668*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 &dFdx = (fragNdx & 2) ? dFdx1 : dFdx0;
5669*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 &dFdy = (fragNdx & 1) ? dFdy1 : dFdy0;
5670*35238bceSAndroid Build Coastguard Worker
5671*35238bceSAndroid Build Coastguard Worker const float mu = de::max(de::abs(dFdx.x()), de::abs(dFdy.x()));
5672*35238bceSAndroid Build Coastguard Worker const float mv = de::max(de::abs(dFdx.y()), de::abs(dFdy.y()));
5673*35238bceSAndroid Build Coastguard Worker const float mw = de::max(de::abs(dFdx.z()), de::abs(dFdy.z()));
5674*35238bceSAndroid Build Coastguard Worker const float p = de::max(de::max(mu * texWidth, mv * texHeight), mw * texDepth);
5675*35238bceSAndroid Build Coastguard Worker
5676*35238bceSAndroid Build Coastguard Worker const float lod = deFloatLog2(p) + lodBias;
5677*35238bceSAndroid Build Coastguard Worker
5678*35238bceSAndroid Build Coastguard Worker output[fragNdx] =
5679*35238bceSAndroid Build Coastguard Worker sample(packetTexcoords[fragNdx].x(), packetTexcoords[fragNdx].y(), packetTexcoords[fragNdx].z(), lod);
5680*35238bceSAndroid Build Coastguard Worker }
5681*35238bceSAndroid Build Coastguard Worker }
5682*35238bceSAndroid Build Coastguard Worker
updateView(tcu::Sampler::DepthStencilMode mode)5683*35238bceSAndroid Build Coastguard Worker void Texture3D::updateView(tcu::Sampler::DepthStencilMode mode)
5684*35238bceSAndroid Build Coastguard Worker {
5685*35238bceSAndroid Build Coastguard Worker const int baseLevel = getBaseLevel();
5686*35238bceSAndroid Build Coastguard Worker
5687*35238bceSAndroid Build Coastguard Worker if (hasLevel(baseLevel) && !isEmpty(getLevel(baseLevel)))
5688*35238bceSAndroid Build Coastguard Worker {
5689*35238bceSAndroid Build Coastguard Worker const int width = getLevel(baseLevel).getWidth();
5690*35238bceSAndroid Build Coastguard Worker const int height = getLevel(baseLevel).getHeight();
5691*35238bceSAndroid Build Coastguard Worker const int depth = getLevel(baseLevel).getDepth();
5692*35238bceSAndroid Build Coastguard Worker const bool isMipmap = isMipmapFilter(getSampler().minFilter);
5693*35238bceSAndroid Build Coastguard Worker const int numLevels =
5694*35238bceSAndroid Build Coastguard Worker isMipmap ? de::min(getMaxLevel() - baseLevel + 1, getNumMipLevels3D(width, height, depth)) : 1;
5695*35238bceSAndroid Build Coastguard Worker
5696*35238bceSAndroid Build Coastguard Worker m_levels.updateSamplerMode(mode);
5697*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture3DView(numLevels, m_levels.getEffectiveLevels() + baseLevel);
5698*35238bceSAndroid Build Coastguard Worker }
5699*35238bceSAndroid Build Coastguard Worker else
5700*35238bceSAndroid Build Coastguard Worker m_view = tcu::Texture3DView(0, DE_NULL);
5701*35238bceSAndroid Build Coastguard Worker }
5702*35238bceSAndroid Build Coastguard Worker
Renderbuffer(uint32_t name)5703*35238bceSAndroid Build Coastguard Worker Renderbuffer::Renderbuffer(uint32_t name) : NamedObject(name)
5704*35238bceSAndroid Build Coastguard Worker {
5705*35238bceSAndroid Build Coastguard Worker }
5706*35238bceSAndroid Build Coastguard Worker
~Renderbuffer(void)5707*35238bceSAndroid Build Coastguard Worker Renderbuffer::~Renderbuffer(void)
5708*35238bceSAndroid Build Coastguard Worker {
5709*35238bceSAndroid Build Coastguard Worker }
5710*35238bceSAndroid Build Coastguard Worker
setStorage(const TextureFormat & format,int width,int height)5711*35238bceSAndroid Build Coastguard Worker void Renderbuffer::setStorage(const TextureFormat &format, int width, int height)
5712*35238bceSAndroid Build Coastguard Worker {
5713*35238bceSAndroid Build Coastguard Worker m_data.setStorage(format, width, height);
5714*35238bceSAndroid Build Coastguard Worker }
5715*35238bceSAndroid Build Coastguard Worker
Framebuffer(uint32_t name)5716*35238bceSAndroid Build Coastguard Worker Framebuffer::Framebuffer(uint32_t name) : NamedObject(name)
5717*35238bceSAndroid Build Coastguard Worker {
5718*35238bceSAndroid Build Coastguard Worker }
5719*35238bceSAndroid Build Coastguard Worker
~Framebuffer(void)5720*35238bceSAndroid Build Coastguard Worker Framebuffer::~Framebuffer(void)
5721*35238bceSAndroid Build Coastguard Worker {
5722*35238bceSAndroid Build Coastguard Worker }
5723*35238bceSAndroid Build Coastguard Worker
VertexArray(uint32_t name,int maxVertexAttribs)5724*35238bceSAndroid Build Coastguard Worker VertexArray::VertexArray(uint32_t name, int maxVertexAttribs)
5725*35238bceSAndroid Build Coastguard Worker : NamedObject(name)
5726*35238bceSAndroid Build Coastguard Worker , m_elementArrayBufferBinding(DE_NULL)
5727*35238bceSAndroid Build Coastguard Worker , m_arrays(maxVertexAttribs)
5728*35238bceSAndroid Build Coastguard Worker {
5729*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < maxVertexAttribs; ++i)
5730*35238bceSAndroid Build Coastguard Worker {
5731*35238bceSAndroid Build Coastguard Worker m_arrays[i].enabled = false;
5732*35238bceSAndroid Build Coastguard Worker m_arrays[i].size = 4;
5733*35238bceSAndroid Build Coastguard Worker m_arrays[i].stride = 0;
5734*35238bceSAndroid Build Coastguard Worker m_arrays[i].type = GL_FLOAT;
5735*35238bceSAndroid Build Coastguard Worker m_arrays[i].normalized = false;
5736*35238bceSAndroid Build Coastguard Worker m_arrays[i].integer = false;
5737*35238bceSAndroid Build Coastguard Worker m_arrays[i].divisor = 0;
5738*35238bceSAndroid Build Coastguard Worker m_arrays[i].bufferDeleted = false;
5739*35238bceSAndroid Build Coastguard Worker m_arrays[i].bufferBinding = DE_NULL;
5740*35238bceSAndroid Build Coastguard Worker m_arrays[i].pointer = DE_NULL;
5741*35238bceSAndroid Build Coastguard Worker }
5742*35238bceSAndroid Build Coastguard Worker }
5743*35238bceSAndroid Build Coastguard Worker
ShaderProgramObjectContainer(uint32_t name,ShaderProgram * program)5744*35238bceSAndroid Build Coastguard Worker ShaderProgramObjectContainer::ShaderProgramObjectContainer(uint32_t name, ShaderProgram *program)
5745*35238bceSAndroid Build Coastguard Worker : NamedObject(name)
5746*35238bceSAndroid Build Coastguard Worker , m_program(program)
5747*35238bceSAndroid Build Coastguard Worker , m_deleteFlag(false)
5748*35238bceSAndroid Build Coastguard Worker {
5749*35238bceSAndroid Build Coastguard Worker }
5750*35238bceSAndroid Build Coastguard Worker
~ShaderProgramObjectContainer(void)5751*35238bceSAndroid Build Coastguard Worker ShaderProgramObjectContainer::~ShaderProgramObjectContainer(void)
5752*35238bceSAndroid Build Coastguard Worker {
5753*35238bceSAndroid Build Coastguard Worker }
5754*35238bceSAndroid Build Coastguard Worker
5755*35238bceSAndroid Build Coastguard Worker } // namespace rc
5756*35238bceSAndroid Build Coastguard Worker } // namespace sglr
5757