1 #ifndef _SGLRREFERENCECONTEXT_HPP
2 #define _SGLRREFERENCECONTEXT_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
5 * ------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Reference Rendering Context.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "sglrContext.hpp"
28 #include "tcuPixelFormat.hpp"
29 #include "tcuSurface.hpp"
30 #include "tcuTexture.hpp"
31 #include "tcuVector.hpp"
32 #include "rrFragmentOperations.hpp"
33 #include "rrRenderState.hpp"
34 #include "rrRenderer.hpp"
35 #include "rrMultisamplePixelBufferAccess.hpp"
36 #include "gluRenderContext.hpp"
37 #include "gluShaderUtil.hpp"
38 #include "deArrayBuffer.hpp"
50 MAX_TEXTURE_SIZE_LOG2 = 14,
51 MAX_TEXTURE_SIZE = 1<<MAX_TEXTURE_SIZE_LOG2
57 virtual ~NamedObject (void) {}
59 deUint32 getName (void) const { return m_name; }
61 int getRefCount (void) const { return m_refCount; }
62 void incRefCount (void) { m_refCount += 1; }
63 void decRefCount (void) { DE_ASSERT(m_refCount > 0); m_refCount -= 1; }
66 NamedObject (deUint32 name) : m_name(name), m_refCount(1) {}
73 class Texture : public NamedObject
88 Texture (deUint32 name, Type type);
89 virtual ~Texture (void) {}
91 Type getType (void) const { return m_type; }
93 int getBaseLevel (void) const { return m_baseLevel; }
94 int getMaxLevel (void) const { return m_maxLevel; }
95 bool isImmutable (void) const { return m_immutable; }
97 void setBaseLevel (int baseLevel) { m_baseLevel = baseLevel; }
98 void setMaxLevel (int maxLevel) { m_maxLevel = maxLevel; }
99 void setImmutable (void) { m_immutable = true; }
101 const tcu::Sampler& getSampler (void) const { return m_sampler; }
102 tcu::Sampler& getSampler (void) { return m_sampler; }
109 tcu::Sampler m_sampler;
114 //! Class for managing list of texture levels.
115 class TextureLevelArray
118 TextureLevelArray (void);
119 ~TextureLevelArray (void);
121 bool hasLevel (int level) const { return deInBounds32(level, 0, DE_LENGTH_OF_ARRAY(m_data)) && !m_data[level].empty(); }
122 const tcu::PixelBufferAccess& getLevel (int level) { DE_ASSERT(hasLevel(level)); return m_access[level]; }
123 const tcu::ConstPixelBufferAccess& getLevel (int level) const { DE_ASSERT(hasLevel(level)); return m_access[level]; }
125 const tcu::ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
127 void allocLevel (int level, const tcu::TextureFormat& format, int width, int height, int depth);
128 void clearLevel (int level);
133 de::ArrayBuffer<deUint8> m_data[MAX_TEXTURE_SIZE_LOG2];
134 tcu::PixelBufferAccess m_access[MAX_TEXTURE_SIZE_LOG2];
137 class Texture1D : public Texture
140 Texture1D (deUint32 name = 0);
141 virtual ~Texture1D (void);
143 void clearLevels (void) { m_levels.clear(); }
145 bool hasLevel (int level) const { return m_levels.hasLevel(level); }
146 const tcu::ConstPixelBufferAccess& getLevel (int level) const { return m_levels.getLevel(level); }
147 const tcu::PixelBufferAccess& getLevel (int level) { return m_levels.getLevel(level); }
149 void allocLevel (int level, const tcu::TextureFormat& format, int width);
151 bool isComplete (void) const;
153 void updateView (void); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
155 tcu::Vec4 sample (float s, float lod) const;
156 void sample4 (tcu::Vec4 output[4], const float packetTexcoords[4], float lodBias = 0.0f) const;
159 TextureLevelArray m_levels;
160 tcu::Texture2DView m_view;
163 class Texture2D : public Texture
166 Texture2D (deUint32 name = 0);
167 virtual ~Texture2D (void);
169 void clearLevels (void) { m_levels.clear(); }
171 bool hasLevel (int level) const { return m_levels.hasLevel(level); }
172 const tcu::ConstPixelBufferAccess& getLevel (int level) const { return m_levels.getLevel(level); }
173 const tcu::PixelBufferAccess& getLevel (int level) { return m_levels.getLevel(level); }
175 void allocLevel (int level, const tcu::TextureFormat& format, int width, int height);
177 bool isComplete (void) const;
179 void updateView (void); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
181 tcu::Vec4 sample (float s, float t, float lod) const;
182 void sample4 (tcu::Vec4 output[4], const tcu::Vec2 packetTexcoords[4], float lodBias = 0.0f) const;
185 TextureLevelArray m_levels;
186 tcu::Texture2DView m_view;
189 class TextureCube : public Texture
192 TextureCube (deUint32 name = 0);
193 virtual ~TextureCube (void);
195 void clearLevels (void);
197 bool hasFace (int level, tcu::CubeFace face) const { return m_levels[face].hasLevel(level); }
198 const tcu::PixelBufferAccess& getFace (int level, tcu::CubeFace face) { return m_levels[face].getLevel(level); }
199 const tcu::ConstPixelBufferAccess& getFace (int level, tcu::CubeFace face) const { return m_levels[face].getLevel(level); }
201 void allocFace (int level, tcu::CubeFace face, const tcu::TextureFormat& format, int width, int height);
203 bool isComplete (void) const;
204 void updateView (void); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
206 tcu::Vec4 sample (float s, float t, float p, float lod) const;
207 void sample4 (tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias = 0.0f) const;
210 TextureLevelArray m_levels[tcu::CUBEFACE_LAST];
211 tcu::TextureCubeView m_view;
214 class Texture2DArray : public Texture
217 Texture2DArray (deUint32 name = 0);
218 virtual ~Texture2DArray (void);
220 void clearLevels (void) { m_levels.clear(); }
222 bool hasLevel (int level) const { return m_levels.hasLevel(level); }
223 const tcu::ConstPixelBufferAccess& getLevel (int level) const { return m_levels.getLevel(level); }
224 const tcu::PixelBufferAccess& getLevel (int level) { return m_levels.getLevel(level); }
226 void allocLevel (int level, const tcu::TextureFormat& format, int width, int height, int numLayers);
228 bool isComplete (void) const;
230 void updateView (void); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
232 tcu::Vec4 sample (float s, float t, float r, float lod) const;
233 void sample4 (tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias = 0.0f) const;
236 TextureLevelArray m_levels;
237 tcu::Texture2DArrayView m_view;
240 class Texture3D : public Texture
243 Texture3D (deUint32 name = 0);
244 virtual ~Texture3D (void);
246 void clearLevels (void) { m_levels.clear(); }
248 bool hasLevel (int level) const { return m_levels.hasLevel(level); }
249 const tcu::ConstPixelBufferAccess& getLevel (int level) const { return m_levels.getLevel(level); }
250 const tcu::PixelBufferAccess& getLevel (int level) { return m_levels.getLevel(level); }
252 void allocLevel (int level, const tcu::TextureFormat& format, int width, int height, int numLayers);
254 bool isComplete (void) const;
256 void updateView (void); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
258 tcu::Vec4 sample (float s, float t, float r, float lod) const;
259 void sample4 (tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias = 0.0f) const;
262 TextureLevelArray m_levels;
263 tcu::Texture3DView m_view;
266 class TextureCubeArray : public Texture
269 TextureCubeArray (deUint32 name = 0);
270 virtual ~TextureCubeArray (void);
272 void clearLevels (void) { m_levels.clear(); }
274 bool hasLevel (int level) const { return m_levels.hasLevel(level); }
275 const tcu::ConstPixelBufferAccess& getLevel (int level) const { return m_levels.getLevel(level); }
276 const tcu::PixelBufferAccess& getLevel (int level) { return m_levels.getLevel(level); }
278 void allocLevel (int level, const tcu::TextureFormat& format, int width, int height, int numLayers);
280 bool isComplete (void) const;
282 void updateView (void); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
284 tcu::Vec4 sample (float s, float t, float r, float q, float lod) const;
285 void sample4 (tcu::Vec4 output[4], const tcu::Vec4 packetTexcoords[4], float lodBias = 0.0f) const;
288 TextureLevelArray m_levels;
289 tcu::TextureCubeArrayView m_view;
292 class Renderbuffer : public NamedObject
297 FORMAT_DEPTH_COMPONENT16,
301 FORMAT_STENCIL_INDEX8,
306 Renderbuffer (deUint32 name);
307 virtual ~Renderbuffer (void);
309 void setStorage (const tcu::TextureFormat& format, int width, int height);
311 int getWidth (void) const { return m_data.getWidth(); }
312 int getHeight (void) const { return m_data.getHeight(); }
313 tcu::TextureFormat getFormat (void) const { return m_data.getFormat(); }
315 tcu::PixelBufferAccess getAccess (void) { return m_data.getAccess(); }
316 tcu::ConstPixelBufferAccess getAccess (void) const { return m_data.getAccess(); }
319 tcu::TextureLevel m_data;
322 class Framebuffer : public NamedObject
327 ATTACHMENTPOINT_COLOR0,
328 ATTACHMENTPOINT_DEPTH,
329 ATTACHMENTPOINT_STENCIL,
336 ATTACHMENTTYPE_RENDERBUFFER,
337 ATTACHMENTTYPE_TEXTURE,
345 TEXTARGET_CUBE_MAP_POSITIVE_X,
346 TEXTARGET_CUBE_MAP_POSITIVE_Y,
347 TEXTARGET_CUBE_MAP_POSITIVE_Z,
348 TEXTARGET_CUBE_MAP_NEGATIVE_X,
349 TEXTARGET_CUBE_MAP_NEGATIVE_Y,
350 TEXTARGET_CUBE_MAP_NEGATIVE_Z,
353 TEXTARGET_CUBE_MAP_ARRAY,
367 : type (ATTACHMENTTYPE_LAST)
369 , texTarget (TEXTARGET_LAST)
376 Framebuffer (deUint32 name);
377 virtual ~Framebuffer (void);
379 Attachment& getAttachment (AttachmentPoint point) { return m_attachments[point]; }
380 const Attachment& getAttachment (AttachmentPoint point) const { return m_attachments[point]; }
384 Attachment m_attachments[ATTACHMENTPOINT_LAST];
387 class DataBuffer : public NamedObject
390 DataBuffer (deUint32 name) : NamedObject(name) {}
391 ~DataBuffer (void) {}
393 void setStorage (int size) { m_data.resize(size); }
395 int getSize (void) const { return (int)m_data.size(); }
396 const deUint8* getData (void) const { return m_data.empty() ? DE_NULL : &m_data[0]; }
397 deUint8* getData (void) { return m_data.empty() ? DE_NULL : &m_data[0]; }
400 std::vector<deUint8> m_data;
403 class VertexArray : public NamedObject
406 struct VertexAttribArray
418 ! These three variables define the state. bufferDeleted is needed to distinguish
419 ! drawing from user pointer and offset to a deleted buffer from each other.
421 ! Only these three combinations are possible:
422 ! 1) bufferDeleted = false, bufferBinding = NULL, pointer = user_ptr. < render from a user ptr
423 ! 2) bufferDeleted = false, bufferBinding = ptr, pointer = offset. < render from a buffer with offset
424 ! 3) bufferDeleted = true, bufferBinding = NULL, pointer = offset < render from a deleted buffer. Don't do anything
426 ! (bufferFreed = true) implies (bufferBinding = NULL)
429 rc::DataBuffer* bufferBinding;
433 VertexArray (deUint32 name, int maxVertexAttribs);
434 ~VertexArray (void) {}
436 rc::DataBuffer* m_elementArrayBufferBinding;
437 std::vector<VertexAttribArray> m_arrays;
440 class ShaderProgramObjectContainer : public NamedObject
443 ShaderProgramObjectContainer (deUint32 name, ShaderProgram* program);
444 ~ShaderProgramObjectContainer (void);
446 ShaderProgram* m_program;
450 template <typename T>
454 ObjectManager (void);
455 ~ObjectManager (void);
457 deUint32 allocateName (void);
458 void insert (T* object);
459 T* find (deUint32 name);
461 void acquireReference (T* object);
462 void releaseReference (T* object);
464 int getCount (void) const { return (int)m_objects.size(); }
465 void getAll (typename std::vector<T*>& objects) const;
468 ObjectManager (const ObjectManager<T>& other);
469 ObjectManager& operator= (const ObjectManager<T>& other);
472 std::map<deUint32, T*> m_objects;
475 template <typename T>
476 ObjectManager<T>::ObjectManager (void)
481 template <typename T>
482 ObjectManager<T>::~ObjectManager (void)
484 DE_ASSERT(m_objects.size() == 0);
487 template <typename T>
488 deUint32 ObjectManager<T>::allocateName (void)
490 TCU_CHECK(m_lastName != 0xffffffff);
494 template <typename T>
495 void ObjectManager<T>::insert (T* object)
497 deUint32 name = object->getName();
498 DE_ASSERT(object->getName() != 0);
500 if (name > m_lastName)
503 m_objects.insert(std::pair<deUint32, T*>(name, object));
506 template <typename T>
507 T* ObjectManager<T>::find (deUint32 name)
509 typename std::map<deUint32, T*>::iterator it = m_objects.find(name);
510 if (it != m_objects.end())
516 template <typename T>
517 void ObjectManager<T>::acquireReference (T* object)
519 DE_ASSERT(find(object->getName()) == object);
520 object->incRefCount();
523 template <typename T>
524 void ObjectManager<T>::releaseReference (T* object)
526 DE_ASSERT(find(object->getName()) == object);
527 object->decRefCount();
529 if (object->getRefCount() == 0)
531 m_objects.erase(object->getName());
536 template <typename T>
537 void ObjectManager<T>::getAll (typename std::vector<T*>& objects) const
539 objects.resize(m_objects.size());
540 typename std::vector<T*>::iterator dst = objects.begin();
542 for (typename std::map<deUint32, T*>::const_iterator i = m_objects.begin();
543 i != m_objects.end(); i++)
551 struct ReferenceContextLimits
553 ReferenceContextLimits (void)
554 : contextType (glu::ApiType::es(3,0))
555 , maxTextureImageUnits (16)
556 , maxTexture2DSize (2048)
557 , maxTextureCubeSize (2048)
558 , maxTexture2DArrayLayers (256)
559 , maxTexture3DSize (256)
560 , maxRenderbufferSize (2048)
561 , maxVertexAttribs (16)
565 ReferenceContextLimits (const glu::RenderContext& renderCtx);
567 void addExtension (const char* extension);
569 glu::ContextType contextType;
571 int maxTextureImageUnits;
572 int maxTexture2DSize;
573 int maxTextureCubeSize;
574 int maxTexture2DArrayLayers;
575 int maxTexture3DSize;
576 int maxRenderbufferSize;
577 int maxVertexAttribs;
579 // Both variants are needed since there are glGetString() and glGetStringi()
580 std::vector<std::string> extensionList;
581 std::string extensionStr;
584 class ReferenceContextBuffers
587 ReferenceContextBuffers (const tcu::PixelFormat& colorBits, int depthBits, int stencilBits, int width, int height, int samples = 1);
589 rr::MultisamplePixelBufferAccess getColorbuffer (void) { return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(m_colorbuffer.getAccess()); }
590 rr::MultisamplePixelBufferAccess getDepthbuffer (void) { return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(m_depthbuffer.getAccess()); }
591 rr::MultisamplePixelBufferAccess getStencilbuffer (void) { return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(m_stencilbuffer.getAccess()); }
594 tcu::TextureLevel m_colorbuffer;
595 tcu::TextureLevel m_depthbuffer;
596 tcu::TextureLevel m_stencilbuffer;
599 class ReferenceContext : public Context
602 ReferenceContext (const ReferenceContextLimits& limits, const rr::MultisamplePixelBufferAccess& colorbuffer, const rr::MultisamplePixelBufferAccess& depthbuffer, const rr::MultisamplePixelBufferAccess& stencilbuffer);
603 virtual ~ReferenceContext (void);
605 virtual int getWidth (void) const { return m_defaultColorbuffer.raw().getHeight(); }
606 virtual int getHeight (void) const { return m_defaultColorbuffer.raw().getDepth(); }
608 virtual void viewport (int x, int y, int width, int height) { m_viewport = tcu::IVec4(x, y, width, height); }
609 virtual void activeTexture (deUint32 texture);
611 virtual void bindTexture (deUint32 target, deUint32 texture);
612 virtual void genTextures (int numTextures, deUint32* textures);
613 virtual void deleteTextures (int numTextures, const deUint32* textures);
615 virtual void bindFramebuffer (deUint32 target, deUint32 framebuffer);
616 virtual void genFramebuffers (int numFramebuffers, deUint32* framebuffers);
617 virtual void deleteFramebuffers (int numFramebuffers, const deUint32* framebuffers);
619 virtual void bindRenderbuffer (deUint32 target, deUint32 renderbuffer);
620 virtual void genRenderbuffers (int numRenderbuffers, deUint32* renderbuffers);
621 virtual void deleteRenderbuffers (int numRenderbuffers, const deUint32* renderbuffers);
623 virtual void pixelStorei (deUint32 pname, int param);
624 virtual void texImage1D (deUint32 target, int level, deUint32 internalFormat, int width, int border, deUint32 format, deUint32 type, const void* data);
625 virtual void texImage2D (deUint32 target, int level, deUint32 internalFormat, int width, int height, int border, deUint32 format, deUint32 type, const void* data);
626 virtual void texImage3D (deUint32 target, int level, deUint32 internalFormat, int width, int height, int depth, int border, deUint32 format, deUint32 type, const void* data);
627 virtual void texSubImage1D (deUint32 target, int level, int xoffset, int width, deUint32 format, deUint32 type, const void* data);
628 virtual void texSubImage2D (deUint32 target, int level, int xoffset, int yoffset, int width, int height, deUint32 format, deUint32 type, const void* data);
629 virtual void texSubImage3D (deUint32 target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, deUint32 format, deUint32 type, const void* data);
630 virtual void copyTexImage1D (deUint32 target, int level, deUint32 internalFormat, int x, int y, int width, int border);
631 virtual void copyTexImage2D (deUint32 target, int level, deUint32 internalFormat, int x, int y, int width, int height, int border);
632 virtual void copyTexSubImage1D (deUint32 target, int level, int xoffset, int x, int y, int width);
633 virtual void copyTexSubImage2D (deUint32 target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
634 virtual void copyTexSubImage3D (deUint32 target, int level, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
636 virtual void texStorage2D (deUint32 target, int levels, deUint32 internalFormat, int width, int height);
637 virtual void texStorage3D (deUint32 target, int levels, deUint32 internalFormat, int width, int height, int depth);
639 virtual void texParameteri (deUint32 target, deUint32 pname, int value);
641 virtual void framebufferTexture2D (deUint32 target, deUint32 attachment, deUint32 textarget, deUint32 texture, int level);
642 virtual void framebufferTextureLayer (deUint32 target, deUint32 attachment, deUint32 texture, int level, int layer);
643 virtual void framebufferRenderbuffer (deUint32 target, deUint32 attachment, deUint32 renderbuffertarget, deUint32 renderbuffer);
644 virtual deUint32 checkFramebufferStatus (deUint32 target);
646 virtual void getFramebufferAttachmentParameteriv (deUint32 target, deUint32 attachment, deUint32 pname, int* params);
648 virtual void renderbufferStorage (deUint32 target, deUint32 internalformat, int width, int height);
649 virtual void renderbufferStorageMultisample (deUint32 target, int samples, deUint32 internalFormat, int width, int height);
651 virtual void bindBuffer (deUint32 target, deUint32 buffer);
652 virtual void genBuffers (int numBuffers, deUint32* buffers);
653 virtual void deleteBuffers (int numBuffers, const deUint32* buffers);
655 virtual void bufferData (deUint32 target, deIntptr size, const void* data, deUint32 usage);
656 virtual void bufferSubData (deUint32 target, deIntptr offset, deIntptr size, const void* data);
658 virtual void clearColor (float red, float green, float blue, float alpha);
659 virtual void clearDepthf (float depth);
660 virtual void clearStencil (int stencil);
662 virtual void clear (deUint32 buffers);
663 virtual void clearBufferiv (deUint32 buffer, int drawbuffer, const int* value);
664 virtual void clearBufferfv (deUint32 buffer, int drawbuffer, const float* value);
665 virtual void clearBufferuiv (deUint32 buffer, int drawbuffer, const deUint32* value);
666 virtual void clearBufferfi (deUint32 buffer, int drawbuffer, float depth, int stencil);
667 virtual void scissor (int x, int y, int width, int height);
669 virtual void enable (deUint32 cap);
670 virtual void disable (deUint32 cap);
672 virtual void stencilFunc (deUint32 func, int ref, deUint32 mask);
673 virtual void stencilOp (deUint32 sfail, deUint32 dpfail, deUint32 dppass);
674 virtual void stencilFuncSeparate (deUint32 face, deUint32 func, int ref, deUint32 mask);
675 virtual void stencilOpSeparate (deUint32 face, deUint32 sfail, deUint32 dpfail, deUint32 dppass);
677 virtual void depthFunc (deUint32 func);
678 virtual void depthRangef (float n, float f);
679 virtual void depthRange (double n, double f);
681 virtual void polygonOffset (float factor, float units);
682 virtual void provokingVertex (deUint32 convention);
683 virtual void primitiveRestartIndex (deUint32 index);
685 virtual void blendEquation (deUint32 mode);
686 virtual void blendEquationSeparate (deUint32 modeRGB, deUint32 modeAlpha);
687 virtual void blendFunc (deUint32 src, deUint32 dst);
688 virtual void blendFuncSeparate (deUint32 srcRGB, deUint32 dstRGB, deUint32 srcAlpha, deUint32 dstAlpha);
689 virtual void blendColor (float red, float green, float blue, float alpha);
691 virtual void colorMask (deBool r, deBool g, deBool b, deBool a);
692 virtual void depthMask (deBool mask);
693 virtual void stencilMask (deUint32 mask);
694 virtual void stencilMaskSeparate (deUint32 face, deUint32 mask);
696 virtual void blitFramebuffer (int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, deUint32 mask, deUint32 filter);
698 virtual void invalidateSubFramebuffer(deUint32 target, int numAttachments, const deUint32* attachments, int x, int y, int width, int height);
699 virtual void invalidateFramebuffer (deUint32 target, int numAttachments, const deUint32* attachments);
701 virtual void bindVertexArray (deUint32 array);
702 virtual void genVertexArrays (int numArrays, deUint32* vertexArrays);
703 virtual void deleteVertexArrays (int numArrays, const deUint32* vertexArrays);
705 virtual void vertexAttribPointer (deUint32 index, int size, deUint32 type, deBool normalized, int stride, const void *pointer);
706 virtual void vertexAttribIPointer (deUint32 index, int size, deUint32 type, int stride, const void *pointer);
707 virtual void enableVertexAttribArray (deUint32 index);
708 virtual void disableVertexAttribArray(deUint32 index);
709 virtual void vertexAttribDivisor (deUint32 index, deUint32 divisor);
711 virtual void vertexAttrib1f (deUint32 index, float);
712 virtual void vertexAttrib2f (deUint32 index, float, float);
713 virtual void vertexAttrib3f (deUint32 index, float, float, float);
714 virtual void vertexAttrib4f (deUint32 index, float, float, float, float);
715 virtual void vertexAttribI4i (deUint32 index, deInt32, deInt32, deInt32, deInt32);
716 virtual void vertexAttribI4ui (deUint32 index, deUint32, deUint32, deUint32, deUint32);
718 virtual deInt32 getAttribLocation (deUint32 program, const char *name);
720 virtual void uniform1f (deInt32 location, float);
721 virtual void uniform1i (deInt32 location, deInt32);
722 virtual void uniform1fv (deInt32 index, deInt32 count, const float*);
723 virtual void uniform2fv (deInt32 index, deInt32 count, const float*);
724 virtual void uniform3fv (deInt32 index, deInt32 count, const float*);
725 virtual void uniform4fv (deInt32 index, deInt32 count, const float*);
726 virtual void uniform1iv (deInt32 index, deInt32 count, const deInt32*);
727 virtual void uniform2iv (deInt32 index, deInt32 count, const deInt32*);
728 virtual void uniform3iv (deInt32 index, deInt32 count, const deInt32*);
729 virtual void uniform4iv (deInt32 index, deInt32 count, const deInt32*);
730 virtual void uniformMatrix3fv (deInt32 location, deInt32 count, deInt32 transpose, const float *value);
731 virtual void uniformMatrix4fv (deInt32 location, deInt32 count, deInt32 transpose, const float *value);
732 virtual deInt32 getUniformLocation (deUint32 program, const char *name);
734 virtual void lineWidth (float);
736 virtual void drawArrays (deUint32 mode, int first, int count);
737 virtual void drawArraysInstanced (deUint32 mode, int first, int count, int instanceCount);
738 virtual void drawElements (deUint32 mode, int count, deUint32 type, const void *indices);
739 virtual void drawElementsBaseVertex (deUint32 mode, int count, deUint32 type, const void *indices, int baseVertex);
740 virtual void drawElementsInstanced (deUint32 mode, int count, deUint32 type, const void *indices, int instanceCount);
741 virtual void drawElementsInstancedBaseVertex (deUint32 mode, int count, deUint32 type, const void *indices, int instanceCount, int baseVertex);
742 virtual void drawRangeElements (deUint32 mode, deUint32 start, deUint32 end, int count, deUint32 type, const void *indices);
743 virtual void drawRangeElementsBaseVertex (deUint32 mode, deUint32 start, deUint32 end, int count, deUint32 type, const void *indices, int baseVertex);
744 virtual void drawArraysIndirect (deUint32 mode, const void *indirect);
745 virtual void drawElementsIndirect (deUint32 mode, deUint32 type, const void *indirect);
747 virtual void multiDrawArrays (deUint32 mode, const int* first, const int* count, int primCount);
748 virtual void multiDrawElements (deUint32 mode, const int* count, deUint32 type, const void** indices, int primCount);
749 virtual void multiDrawElementsBaseVertex (deUint32 mode, const int* count, deUint32 type, const void** indices, int primCount, const int* baseVertex);
751 virtual deUint32 createProgram (ShaderProgram* program);
752 virtual void useProgram (deUint32 program);
753 virtual void deleteProgram (deUint32 program);
755 virtual void readPixels (int x, int y, int width, int height, deUint32 format, deUint32 type, void* data);
756 virtual deUint32 getError (void);
757 virtual void finish (void);
759 virtual void getIntegerv (deUint32 pname, int* params);
760 virtual const char* getString (deUint32 pname);
762 // Expose helpers from Context.
763 using Context::readPixels;
764 using Context::texImage2D;
765 using Context::texSubImage2D;
768 ReferenceContext (const ReferenceContext& other); // Not allowed!
769 ReferenceContext& operator= (const ReferenceContext& other); // Not allowed!
771 void deleteTexture (rc::Texture* texture);
772 void deleteFramebuffer (rc::Framebuffer* framebuffer);
773 void deleteRenderbuffer (rc::Renderbuffer* renderbuffer);
774 void deleteBuffer (rc::DataBuffer* buffer);
775 void deleteVertexArray (rc::VertexArray* vertexArray);
776 void deleteProgramObject (rc::ShaderProgramObjectContainer* sp);
778 void acquireFboAttachmentReference (const rc::Framebuffer::Attachment& attachment);
779 void releaseFboAttachmentReference (const rc::Framebuffer::Attachment& attachment);
780 tcu::PixelBufferAccess getFboAttachment (const rc::Framebuffer& framebuffer, rc::Framebuffer::AttachmentPoint point);
782 deUint32 blitResolveMultisampleFramebuffer (deUint32 mask, const tcu::IVec4& srcRect, const tcu::IVec4& dstRect, bool flipX, bool flipY);
784 rr::MultisamplePixelBufferAccess getDrawColorbuffer (void) { return (m_drawFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(*m_drawFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_COLOR0))) : (m_defaultColorbuffer); }
785 rr::MultisamplePixelBufferAccess getDrawDepthbuffer (void) { return (m_drawFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(*m_drawFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_DEPTH))) : (m_defaultDepthbuffer); }
786 rr::MultisamplePixelBufferAccess getDrawStencilbuffer (void) { return (m_drawFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(*m_drawFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_STENCIL))) : (m_defaultStencilbuffer); }
787 rr::MultisamplePixelBufferAccess getReadColorbuffer (void) { return (m_readFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(*m_readFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_COLOR0))) : (m_defaultColorbuffer); }
788 rr::MultisamplePixelBufferAccess getReadDepthbuffer (void) { return (m_readFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(*m_readFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_DEPTH))) : (m_defaultDepthbuffer); }
789 rr::MultisamplePixelBufferAccess getReadStencilbuffer (void) { return (m_readFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(*m_readFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_STENCIL))) : (m_defaultStencilbuffer); }
791 const rc::Texture2D& getTexture2D (int unitNdx) const;
792 const rc::TextureCube& getTextureCube (int unitNdx) const;
793 const tcu::IVec4& getViewport (void) const { return m_viewport; }
795 void setError (deUint32 error);
797 void setTex1DBinding (int unit, rc::Texture1D* tex1D);
798 void setTex2DBinding (int unit, rc::Texture2D* tex2D);
799 void setTexCubeBinding (int unit, rc::TextureCube* texCube);
800 void setTex2DArrayBinding (int unit, rc::Texture2DArray* tex2DArray);
801 void setTex3DBinding (int unit, rc::Texture3D* tex3D);
802 void setTexCubeArrayBinding (int unit, rc::TextureCubeArray* texCubeArray);
804 void setBufferBinding (deUint32 target, rc::DataBuffer* buffer);
805 rc::DataBuffer* getBufferBinding (deUint32 target) const;
807 void* getPixelPackPtr (void* ptrOffset) const { return m_pixelPackBufferBinding ? (void*)((deUintptr)m_pixelPackBufferBinding->getData()+(deUintptr)ptrOffset) : ptrOffset; }
808 const void* getPixelUnpackPtr (const void* ptrOffset) const { return m_pixelUnpackBufferBinding ? (const void*)((deUintptr)m_pixelUnpackBufferBinding->getData()+(deUintptr)ptrOffset) : ptrOffset; }
810 bool predrawErrorChecks (deUint32 mode);
811 void drawWithReference (const rr::PrimitiveList& primitives, int instanceCount);
813 // Helpers for getting valid access object based on current unpack state.
814 tcu::ConstPixelBufferAccess getUnpack2DAccess (const tcu::TextureFormat& format, int width, int height, const void* data);
815 tcu::ConstPixelBufferAccess getUnpack3DAccess (const tcu::TextureFormat& format, int width, int height, int depth, const void* data);
817 void uniformv (deInt32 index, glu::DataType type, deInt32 count, const void*);
822 rc::Texture1D* tex1DBinding;
823 rc::Texture2D* tex2DBinding;
824 rc::TextureCube* texCubeBinding;
825 rc::Texture2DArray* tex2DArrayBinding;
826 rc::Texture3D* tex3DBinding;
827 rc::TextureCubeArray* texCubeArrayBinding;
829 rc::Texture1D default1DTex;
830 rc::Texture2D default2DTex;
831 rc::TextureCube defaultCubeTex;
832 rc::Texture2DArray default2DArrayTex;
833 rc::Texture3D default3DTex;
834 rc::TextureCubeArray defaultCubeArrayTex;
837 : tex1DBinding (DE_NULL)
838 , tex2DBinding (DE_NULL)
839 , texCubeBinding (DE_NULL)
840 , tex2DArrayBinding (DE_NULL)
841 , tex3DBinding (DE_NULL)
842 , texCubeArrayBinding (DE_NULL)
846 , default2DArrayTex (0)
848 , defaultCubeArrayTex (0)
858 deUint32 opStencilFail;
859 deUint32 opDepthFail;
860 deUint32 opDepthPass;
866 ReferenceContextLimits m_limits;
868 rr::MultisamplePixelBufferAccess m_defaultColorbuffer;
869 rr::MultisamplePixelBufferAccess m_defaultDepthbuffer;
870 rr::MultisamplePixelBufferAccess m_defaultStencilbuffer;
871 rc::VertexArray m_clientVertexArray;
873 tcu::IVec4 m_viewport;
875 rc::ObjectManager<rc::Texture> m_textures;
876 rc::ObjectManager<rc::Framebuffer> m_framebuffers;
877 rc::ObjectManager<rc::Renderbuffer> m_renderbuffers;
878 rc::ObjectManager<rc::DataBuffer> m_buffers;
879 rc::ObjectManager<rc::VertexArray> m_vertexArrays;
880 rc::ObjectManager<rc::ShaderProgramObjectContainer> m_programs;
883 std::vector<TextureUnit> m_textureUnits;
884 rc::Texture1D m_emptyTex1D;
885 rc::Texture2D m_emptyTex2D;
886 rc::TextureCube m_emptyTexCube;
887 rc::Texture2DArray m_emptyTex2DArray;
888 rc::Texture3D m_emptyTex3D;
889 rc::TextureCubeArray m_emptyTexCubeArray;
891 int m_pixelUnpackRowLength;
892 int m_pixelUnpackSkipRows;
893 int m_pixelUnpackSkipPixels;
894 int m_pixelUnpackImageHeight;
895 int m_pixelUnpackSkipImages;
896 int m_pixelUnpackAlignment;
897 int m_pixelPackAlignment;
899 rc::Framebuffer* m_readFramebufferBinding;
900 rc::Framebuffer* m_drawFramebufferBinding;
901 rc::Renderbuffer* m_renderbufferBinding;
902 rc::VertexArray* m_vertexArrayBinding;
903 rc::ShaderProgramObjectContainer* m_currentProgram;
905 rc::DataBuffer* m_arrayBufferBinding;
906 rc::DataBuffer* m_pixelPackBufferBinding;
907 rc::DataBuffer* m_pixelUnpackBufferBinding;
908 rc::DataBuffer* m_transformFeedbackBufferBinding;
909 rc::DataBuffer* m_uniformBufferBinding;
910 rc::DataBuffer* m_copyReadBufferBinding;
911 rc::DataBuffer* m_copyWriteBufferBinding;
912 rc::DataBuffer* m_drawIndirectBufferBinding;
914 tcu::Vec4 m_clearColor;
918 bool m_scissorEnabled;
919 tcu::IVec4 m_scissorBox;
921 bool m_stencilTestEnabled;
922 StencilState m_stencil[rr::FACETYPE_LAST];
924 bool m_depthTestEnabled;
925 deUint32 m_depthFunc;
926 float m_depthRangeNear;
927 float m_depthRangeFar;
929 float m_polygonOffsetFactor;
930 float m_polygonOffsetUnits;
931 bool m_polygonOffsetFillEnabled;
933 bool m_provokingFirstVertexConvention;
936 deUint32 m_blendModeRGB;
937 deUint32 m_blendModeAlpha;
938 deUint32 m_blendFactorSrcRGB;
939 deUint32 m_blendFactorDstRGB;
940 deUint32 m_blendFactorSrcAlpha;
941 deUint32 m_blendFactorDstAlpha;
942 tcu::Vec4 m_blendColor;
944 bool m_sRGBUpdateEnabled;
946 bool m_depthClampEnabled;
948 tcu::BVec4 m_colorMask;
951 std::vector<rr::GenericVec4> m_currentAttribs;
954 bool m_primitiveRestartFixedIndex;
955 bool m_primitiveRestartSettableIndex;
956 deUint32 m_primitiveRestartIndex;
958 deUint32 m_lastError;
960 rr::FragmentProcessor m_fragmentProcessor;
961 std::vector<rr::Fragment> m_fragmentBuffer;
962 std::vector<float> m_fragmentDepths;
963 } DE_WARN_UNUSED_TYPE;
967 #endif // _SGLRREFERENCECONTEXT_HPP