blob: c288b7df7ef4fd4554f77ee997d0371a33b4d0b3 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.h: Defines the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000010#ifndef LIBGLESV2_CONTEXT_H_
11#define LIBGLESV2_CONTEXT_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
13#define GL_APICALL
14#include <GLES2/gl2.h>
alokp@chromium.orgd303ef92010-09-09 17:30:15 +000015#include <GLES2/gl2ext.h>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000016#define EGLAPI
17#include <EGL/egl.h>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000019#include <string>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000020#include <map>
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000021#ifdef _MSC_VER
benvanik@google.coma9d0b762011-04-28 20:11:54 +000022#include <hash_map>
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000023#else
24#include <unordered_map>
25#endif
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000026
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000027#include "common/angleutils.h"
apatrick@chromium.orgb66a7012012-01-23 20:04:48 +000028#include "common/RefCountObject.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000029#include "libGLESv2/ResourceManager.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000030#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comd0db3502012-11-28 19:35:20 +000031#include "libGLESv2/angletypes.h"
daniel@transgaming.com621ce052012-10-31 17:52:29 +000032#include "libGLESv2/renderer/Renderer.h"
daniel@transgaming.com3c720782012-10-31 18:42:34 +000033#include "libGLESv2/renderer/SwapChain.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034
35namespace egl
36{
37class Display;
38class Surface;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039}
40
41namespace gl
42{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043class Shader;
44class Program;
daniel@transgaming.com5ae3ccc2012-07-24 18:29:38 +000045class ProgramBinary;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046class Texture;
47class Texture2D;
48class TextureCubeMap;
49class Framebuffer;
50class Renderbuffer;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000051class RenderbufferStorage;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052class Colorbuffer;
53class Depthbuffer;
54class Stencilbuffer;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +000055class DepthStencilbuffer;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000056class Fence;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000057class Query;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058
59enum
60{
jbauman@chromium.orge0f059c2012-01-24 23:21:52 +000061 D3D9_MAX_FLOAT_CONSTANTS = 256,
jbauman@chromium.orge0f059c2012-01-24 23:21:52 +000062
daniel@transgaming.com83921382011-01-08 05:46:00 +000063 MAX_VERTEX_ATTRIBS = 16,
jbauman@chromium.orge0f059c2012-01-24 23:21:52 +000064 MAX_VERTEX_UNIFORM_VECTORS = D3D9_MAX_FLOAT_CONSTANTS - 2, // Reserve space for dx_HalfPixelSize and dx_DepthRange.
daniel@transgaming.com396c6432010-11-26 16:26:12 +000065 MAX_VARYING_VECTORS_SM2 = 8,
66 MAX_VARYING_VECTORS_SM3 = 10,
daniel@transgaming.com1c233ff2010-06-08 14:13:00 +000067 MAX_TEXTURE_IMAGE_UNITS = 16,
daniel@transgaming.comaf29cac2011-05-11 15:36:31 +000068 MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF = 4, // For devices supporting vertex texture fetch
69 MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF,
daniel@transgaming.com12985182012-12-20 20:56:31 +000070 MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 3, // Reserve space for dx_Coord, dx_DepthFront and dx_DepthRange.
71 MAX_FRAGMENT_UNIFORM_VECTORS_SM3 = 224 - 3,
daniel@transgaming.com106e1f72012-10-31 18:38:36 +000072 MAX_DRAW_BUFFERS = 1
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073};
74
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000075enum QueryType
76{
77 QUERY_ANY_SAMPLES_PASSED,
78 QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,
79
80 QUERY_TYPE_COUNT
81};
82
daniel@transgaming.comd989add2010-03-26 04:08:42 +000083const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
84const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
daniel@transgaming.comccad59f2010-03-26 04:08:39 +000085const float ALIASED_POINT_SIZE_RANGE_MIN = 1.0f;
daniel@transgaming.combe5a0862010-07-28 19:20:37 +000086const float ALIASED_POINT_SIZE_RANGE_MAX_SM2 = 1.0f;
daniel@transgaming.comccad59f2010-03-26 04:08:39 +000087
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000088// Helper structure describing a single vertex attribute
daniel@transgaming.com83921382011-01-08 05:46:00 +000089class VertexAttribute
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090{
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000091 public:
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +000092 VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mPointer(NULL), mArrayEnabled(false), mDivisor(0)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000093 {
daniel@transgaming.com83921382011-01-08 05:46:00 +000094 mCurrentValue[0] = 0.0f;
95 mCurrentValue[1] = 0.0f;
96 mCurrentValue[2] = 0.0f;
97 mCurrentValue[3] = 1.0f;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000098 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
daniel@transgaming.com83921382011-01-08 05:46:00 +0000100 int typeSize() const
101 {
102 switch (mType)
103 {
104 case GL_BYTE: return mSize * sizeof(GLbyte);
105 case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
106 case GL_SHORT: return mSize * sizeof(GLshort);
107 case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
108 case GL_FIXED: return mSize * sizeof(GLfixed);
109 case GL_FLOAT: return mSize * sizeof(GLfloat);
110 default: UNREACHABLE(); return mSize * sizeof(GLfloat);
111 }
112 }
113
114 GLsizei stride() const
115 {
116 return mStride ? mStride : typeSize();
117 }
118
119 // From glVertexAttribPointer
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000120 GLenum mType;
121 GLint mSize;
122 bool mNormalized;
daniel@transgaming.com83921382011-01-08 05:46:00 +0000123 GLsizei mStride; // 0 means natural stride
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000124
daniel@transgaming.com83921382011-01-08 05:46:00 +0000125 union
126 {
127 const void *mPointer;
128 intptr_t mOffset;
129 };
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000130
daniel@transgaming.com83921382011-01-08 05:46:00 +0000131 BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000132
daniel@transgaming.com83921382011-01-08 05:46:00 +0000133 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
134 float mCurrentValue[4]; // From glVertexAttrib
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +0000135 unsigned int mDivisor;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000136};
137
138// Helper structure to store all raw state
139struct State
140{
141 Color colorClearValue;
142 GLclampf depthClearValue;
143 int stencilClearValue;
144
daniel@transgaming.comf39967e2012-11-28 19:35:56 +0000145 RasterizerState rasterizer;
daniel@transgaming.comd55e8c12012-11-28 21:07:02 +0000146 bool scissorTest;
daniel@transgaming.comf39967e2012-11-28 19:35:56 +0000147 Rectangle scissor;
148
149 BlendState blend;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150 Color blendColor;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000151 bool sampleCoverage;
152 GLclampf sampleCoverageValue;
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +0000153 bool sampleCoverageInvert;
daniel@transgaming.comf39967e2012-11-28 19:35:56 +0000154
155 DepthStencilState depthStencil;
daniel@transgaming.com08c331d2012-11-28 19:38:39 +0000156 GLint stencilRef;
157 GLint stencilBackRef;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +0000159 GLfloat lineWidth;
160
daniel@transgaming.com5949aa12010-03-21 04:31:15 +0000161 GLenum generateMipmapHint;
alokp@chromium.orgd303ef92010-09-09 17:30:15 +0000162 GLenum fragmentShaderDerivativeHint;
daniel@transgaming.com5949aa12010-03-21 04:31:15 +0000163
daniel@transgaming.com3884e2c2012-11-28 19:41:00 +0000164 Rectangle viewport;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000165 float zNear;
166 float zFar;
167
daniel@transgaming.comdfd57022011-05-11 15:37:25 +0000168 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000169 BindingPointer<Buffer> arrayBuffer;
170 BindingPointer<Buffer> elementArrayBuffer;
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +0000171 GLuint readFramebuffer;
172 GLuint drawFramebuffer;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000173 BindingPointer<Renderbuffer> renderbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000174 GLuint currentProgram;
175
daniel@transgaming.com83921382011-01-08 05:46:00 +0000176 VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000177 BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF];
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000178 BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000179
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +0000180 GLint unpackAlignment;
181 GLint packAlignment;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +0000182 bool packReverseRowOrder;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000183};
184
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000185class Context
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000186{
187 public:
daniel@transgaming.com03d39092012-11-28 19:31:59 +0000188 Context(const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000189
190 ~Context();
191
daniel@transgaming.comad629872012-11-28 19:32:06 +0000192 void makeCurrent(egl::Surface *surface);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000193
daniel@transgaming.com09fcc9f2011-11-09 17:46:47 +0000194 virtual void markContextLost();
195 bool isContextLost();
196
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000197 // State manipulation
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198 void setClearColor(float red, float green, float blue, float alpha);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000199
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000200 void setClearDepth(float depth);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000201
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000202 void setClearStencil(int stencil);
203
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000204 void setCullFace(bool enabled);
205 bool isCullFaceEnabled() const;
206
207 void setCullMode(GLenum mode);
208
209 void setFrontFace(GLenum front);
210
211 void setDepthTest(bool enabled);
212 bool isDepthTestEnabled() const;
213
214 void setDepthFunc(GLenum depthFunc);
215
216 void setDepthRange(float zNear, float zFar);
217
218 void setBlend(bool enabled);
219 bool isBlendEnabled() const;
220
221 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
222 void setBlendColor(float red, float green, float blue, float alpha);
223 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
224
225 void setStencilTest(bool enabled);
226 bool isStencilTestEnabled() const;
227
228 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
229 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
230 void setStencilWritemask(GLuint stencilWritemask);
231 void setStencilBackWritemask(GLuint stencilBackWritemask);
232 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
233 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
234
235 void setPolygonOffsetFill(bool enabled);
236 bool isPolygonOffsetFillEnabled() const;
237
238 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
239
240 void setSampleAlphaToCoverage(bool enabled);
241 bool isSampleAlphaToCoverageEnabled() const;
242
243 void setSampleCoverage(bool enabled);
244 bool isSampleCoverageEnabled() const;
245
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +0000246 void setSampleCoverageParams(GLclampf value, bool invert);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000247
248 void setScissorTest(bool enabled);
249 bool isScissorTestEnabled() const;
250
251 void setDither(bool enabled);
252 bool isDitherEnabled() const;
253
254 void setLineWidth(GLfloat width);
255
256 void setGenerateMipmapHint(GLenum hint);
alokp@chromium.orgd303ef92010-09-09 17:30:15 +0000257 void setFragmentShaderDerivativeHint(GLenum hint);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000258
259 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
260
261 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
262
263 void setColorMask(bool red, bool green, bool blue, bool alpha);
264 void setDepthMask(bool mask);
265
daniel@transgaming.comdfd57022011-05-11 15:37:25 +0000266 void setActiveSampler(unsigned int active);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000267
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000268 GLuint getReadFramebufferHandle() const;
269 GLuint getDrawFramebufferHandle() const;
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000270 GLuint getRenderbufferHandle() const;
271
272 GLuint getArrayBufferHandle() const;
273
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000274 GLuint getActiveQuery(GLenum target) const;
275
daniel@transgaming.com83921382011-01-08 05:46:00 +0000276 void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
277 const VertexAttribute &getVertexAttribState(unsigned int attribNum);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000278 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000279 bool normalized, GLsizei stride, const void *pointer);
280 const void *getVertexAttribPointer(unsigned int attribNum) const;
281
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000282 void setUnpackAlignment(GLint alignment);
283 GLint getUnpackAlignment() const;
284
285 void setPackAlignment(GLint alignment);
286 GLint getPackAlignment() const;
287
bsalomon@google.com56d46ab2011-11-23 14:53:10 +0000288 void setPackReverseRowOrder(bool reverseRowOrder);
289 bool getPackReverseRowOrder() const;
290
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000291 // These create and destroy methods are merely pass-throughs to
292 // ResourceManager, which owns these object types
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293 GLuint createBuffer();
294 GLuint createShader(GLenum type);
295 GLuint createProgram();
296 GLuint createTexture();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297 GLuint createRenderbuffer();
298
299 void deleteBuffer(GLuint buffer);
300 void deleteShader(GLuint shader);
301 void deleteProgram(GLuint program);
302 void deleteTexture(GLuint texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000303 void deleteRenderbuffer(GLuint renderbuffer);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000304
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000305 // Framebuffers are owned by the Context, so these methods do not pass through
306 GLuint createFramebuffer();
307 void deleteFramebuffer(GLuint framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000309 // Fences are owned by the Context.
310 GLuint createFence();
311 void deleteFence(GLuint fence);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000312
313 // Queries are owned by the Context;
314 GLuint createQuery();
315 void deleteQuery(GLuint query);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000316
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000317 void bindArrayBuffer(GLuint buffer);
318 void bindElementArrayBuffer(GLuint buffer);
319 void bindTexture2D(GLuint texture);
320 void bindTextureCubeMap(GLuint texture);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000321 void bindReadFramebuffer(GLuint framebuffer);
322 void bindDrawFramebuffer(GLuint framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323 void bindRenderbuffer(GLuint renderbuffer);
324 void useProgram(GLuint program);
daniel@transgaming.com95d29422012-07-24 18:36:10 +0000325 void linkProgram(GLuint program);
326 void setProgramBinary(GLuint program, const void *binary, GLint length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000327
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000328 void beginQuery(GLenum target, GLuint query);
329 void endQuery(GLenum target);
330
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000331 void setFramebufferZero(Framebuffer *framebuffer);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000332
daniel@transgaming.com70062c92012-11-28 19:32:30 +0000333 void setRenderbufferStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334
daniel@transgaming.come4b08c82010-04-20 18:53:06 +0000335 void setVertexAttrib(GLuint index, const GLfloat *values);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +0000336 void setVertexAttribDivisor(GLuint index, GLuint divisor);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +0000337
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000338 Buffer *getBuffer(GLuint handle);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000339 Fence *getFence(GLuint handle);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000340 Shader *getShader(GLuint handle);
341 Program *getProgram(GLuint handle);
342 Texture *getTexture(GLuint handle);
343 Framebuffer *getFramebuffer(GLuint handle);
344 Renderbuffer *getRenderbuffer(GLuint handle);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000345 Query *getQuery(GLuint handle, bool create, GLenum type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000346
347 Buffer *getArrayBuffer();
348 Buffer *getElementArrayBuffer();
daniel@transgaming.com62a28462012-07-24 18:33:59 +0000349 ProgramBinary *getCurrentProgramBinary();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350 Texture2D *getTexture2D();
351 TextureCubeMap *getTextureCubeMap();
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +0000352 Texture *getSamplerTexture(unsigned int sampler, TextureType type);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000353 Framebuffer *getReadFramebuffer();
354 Framebuffer *getDrawFramebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
daniel@transgaming.com777f2672010-04-07 03:25:16 +0000356 bool getFloatv(GLenum pname, GLfloat *params);
357 bool getIntegerv(GLenum pname, GLint *params);
358 bool getBooleanv(GLenum pname, GLboolean *params);
359
360 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams);
361
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000362 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000363 void clear(GLbitfield mask);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +0000364 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances);
365 void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances);
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +0000366 void sync(bool block); // flush/finish
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000367
368 void recordInvalidEnum();
369 void recordInvalidValue();
370 void recordInvalidOperation();
371 void recordOutOfMemory();
372 void recordInvalidFramebufferOperation();
373
374 GLenum getError();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +0000375 GLenum getResetStatus();
daniel@transgaming.com4ff960d2011-11-09 17:47:09 +0000376 virtual bool isResetNotificationEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000377
daniel@transgaming.com9549bea2012-11-28 20:57:23 +0000378 int getMajorShaderModel() const;
daniel@transgaming.com13be3e42012-07-04 19:16:24 +0000379 float getMaximumPointSize() const;
daniel@transgaming.com396c6432010-11-26 16:26:12 +0000380 int getMaximumVaryingVectors() const;
daniel@transgaming.comdfd57022011-05-11 15:37:25 +0000381 unsigned int getMaximumVertexTextureImageUnits() const;
382 unsigned int getMaximumCombinedTextureImageUnits() const;
daniel@transgaming.com458da142010-11-28 02:03:02 +0000383 int getMaximumFragmentUniformVectors() const;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000384 int getMaximumRenderbufferDimension() const;
385 int getMaximumTextureDimension() const;
386 int getMaximumCubeTextureDimension() const;
387 int getMaximumTextureLevel() const;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000388 GLsizei getMaxSupportedSamples() const;
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +0000389 const char *getExtensionString() const;
daniel@transgaming.comc23ff642011-08-16 20:28:45 +0000390 const char *getRendererString() const;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000391 bool supportsEventQueries() const;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000392 bool supportsOcclusionQueries() const;
gman@chromium.org50c526d2011-08-10 05:19:44 +0000393 bool supportsDXT1Textures() const;
394 bool supportsDXT3Textures() const;
395 bool supportsDXT5Textures() const;
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +0000396 bool supportsFloat32Textures() const;
397 bool supportsFloat32LinearFilter() const;
398 bool supportsFloat32RenderableTextures() const;
399 bool supportsFloat16Textures() const;
400 bool supportsFloat16LinearFilter() const;
401 bool supportsFloat16RenderableTextures() const;
daniel@transgaming.comed828e52010-10-15 17:57:30 +0000402 bool supportsLuminanceTextures() const;
403 bool supportsLuminanceAlphaTextures() const;
daniel@transgaming.com1c49f792012-05-31 01:14:02 +0000404 bool supportsDepthTextures() const;
daniel@transgaming.com83921382011-01-08 05:46:00 +0000405 bool supports32bitIndices() const;
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +0000406 bool supportsNonPower2Texture() const;
daniel@transgaming.comc6f7f9d2012-01-27 15:40:00 +0000407 bool supportsInstancing() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +0000408 bool supportsTextureFilterAnisotropy() const;
daniel@transgaming.com7629bb62013-01-11 04:12:28 +0000409 bool supportsDerivativeInstructions() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +0000410
daniel@transgaming.com42944b02012-09-27 17:45:57 +0000411 bool getCurrentReadFormatType(GLenum *format, GLenum *type);
412
daniel@transgaming.com07ab8412012-07-12 15:17:09 +0000413 float getTextureMaxAnisotropy() const;
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +0000414
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +0000415 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
416 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
417 GLbitfield mask);
418
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000419 private:
420 DISALLOW_COPY_AND_ASSIGN(Context);
421
daniel@transgaming.com12985182012-12-20 20:56:31 +0000422 bool applyRenderTarget(GLenum drawMode, bool ignoreViewport);
daniel@transgaming.comd4a35172011-05-11 15:36:45 +0000423 void applyState(GLenum drawMode);
daniel@transgaming.comd4a35172011-05-11 15:36:45 +0000424 void applyShaders();
425 void applyTextures();
426 void applyTextures(SamplerType type);
427
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000428 void detachBuffer(GLuint buffer);
429 void detachTexture(GLuint texture);
430 void detachFramebuffer(GLuint framebuffer);
431 void detachRenderbuffer(GLuint renderbuffer);
432
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +0000433 Texture *getIncompleteTexture(TextureType type);
daniel@transgaming.com12d54072010-03-16 06:23:26 +0000434
daniel@transgaming.com087e5782012-09-17 21:28:47 +0000435 bool skipDraw(GLenum drawMode);
daniel@transgaming.comace5e662010-03-21 04:31:20 +0000436
daniel@transgaming.comc23ff642011-08-16 20:28:45 +0000437 void initExtensionString();
438 void initRendererString();
439
daniel@transgaming.comdedd1a02012-11-28 20:57:11 +0000440 rx::Renderer *const mRenderer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000441
daniel@transgaming.combaa74512011-04-13 14:56:47 +0000442 State mState;
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000443
apatrick@chromium.org4e3bad42010-09-15 17:31:48 +0000444 BindingPointer<Texture2D> mTexture2DZero;
445 BindingPointer<TextureCubeMap> mTextureCubeMapZero;
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +0000446
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000447#ifndef HASH_MAP
448# ifdef _MSC_VER
449# define HASH_MAP stdext::hash_map
450# else
451# define HASH_MAP std::unordered_map
452# endif
453#endif
454
455 typedef HASH_MAP<GLuint, Framebuffer*> FramebufferMap;
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +0000456 FramebufferMap mFramebufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000457 HandleAllocator mFramebufferHandleAllocator;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000458
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000459 typedef HASH_MAP<GLuint, Fence*> FenceMap;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000460 FenceMap mFenceMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000461 HandleAllocator mFenceHandleAllocator;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000462
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000463 typedef HASH_MAP<GLuint, Query*> QueryMap;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000464 QueryMap mQueryMap;
465 HandleAllocator mQueryHandleAllocator;
466
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000467 const char *mExtensionString;
468 const char *mRendererString;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000469
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +0000470 BindingPointer<Texture> mIncompleteTextures[TEXTURE_TYPE_COUNT];
daniel@transgaming.com12d54072010-03-16 06:23:26 +0000471
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000472 // Recorded errors
473 bool mInvalidEnum;
474 bool mInvalidValue;
475 bool mInvalidOperation;
476 bool mOutOfMemory;
477 bool mInvalidFramebufferOperation;
daniel@transgaming.com159acdf2010-03-21 04:31:24 +0000478
daniel@transgaming.com09fcc9f2011-11-09 17:46:47 +0000479 // Current/lost context flags
daniel@transgaming.com159acdf2010-03-21 04:31:24 +0000480 bool mHasBeenCurrent;
daniel@transgaming.com09fcc9f2011-11-09 17:46:47 +0000481 bool mContextLost;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +0000482 GLenum mResetStatus;
daniel@transgaming.com4ff960d2011-11-09 17:47:09 +0000483 GLenum mResetStrategy;
484 bool mRobustAccess;
daniel@transgaming.com296ca9c2010-04-03 20:56:07 +0000485
daniel@transgaming.com989c1c82012-07-24 18:40:38 +0000486 BindingPointer<ProgramBinary> mCurrentProgramBinary;
jbauman@chromium.org040c4db2011-10-13 21:35:52 +0000487 Framebuffer *mBoundDrawFramebuffer;
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000488
daniel@transgaming.com9549bea2012-11-28 20:57:23 +0000489 int mMajorShaderModel;
daniel@transgaming.com13be3e42012-07-04 19:16:24 +0000490 float mMaximumPointSize;
daniel@transgaming.comaf29cac2011-05-11 15:36:31 +0000491 bool mSupportsVertexTexture;
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +0000492 bool mSupportsNonPower2Texture;
daniel@transgaming.comc6f7f9d2012-01-27 15:40:00 +0000493 bool mSupportsInstancing;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000494 int mMaxRenderbufferDimension;
495 int mMaxTextureDimension;
496 int mMaxCubeTextureDimension;
497 int mMaxTextureLevel;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +0000498 float mMaxTextureAnisotropy;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000499 bool mSupportsEventQueries;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000500 bool mSupportsOcclusionQueries;
gman@chromium.org50c526d2011-08-10 05:19:44 +0000501 bool mSupportsDXT1Textures;
502 bool mSupportsDXT3Textures;
503 bool mSupportsDXT5Textures;
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +0000504 bool mSupportsFloat32Textures;
505 bool mSupportsFloat32LinearFilter;
506 bool mSupportsFloat32RenderableTextures;
507 bool mSupportsFloat16Textures;
508 bool mSupportsFloat16LinearFilter;
509 bool mSupportsFloat16RenderableTextures;
daniel@transgaming.comed828e52010-10-15 17:57:30 +0000510 bool mSupportsLuminanceTextures;
511 bool mSupportsLuminanceAlphaTextures;
daniel@transgaming.com1c49f792012-05-31 01:14:02 +0000512 bool mSupportsDepthTextures;
daniel@transgaming.com83921382011-01-08 05:46:00 +0000513 bool mSupports32bitIndices;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +0000514 bool mSupportsTextureFilterAnisotropy;
daniel@transgaming.com7629bb62013-01-11 04:12:28 +0000515 bool mSupportsDerivativeInstructions;
gman@chromium.org50c526d2011-08-10 05:19:44 +0000516 int mNumCompressedTextureFormats;
daniel@transgaming.coma79f9d12010-05-12 03:40:01 +0000517
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000518 ResourceManager *mResourceManager;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000519};
520}
521
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000522#endif // INCLUDE_CONTEXT_H_