blob: 5dfb4493ac4a2adde54343067edf67d02d049a01 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// 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>
18#include <d3d9.h>
19
20#include <map>
21
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000022#include "common/angleutils.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000023#include "libGLESv2/ResourceManager.h"
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000024#include "libGLESv2/RefCountObject.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
26namespace egl
27{
28class Display;
29class Surface;
30class Config;
31}
32
33namespace gl
34{
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000035struct TranslatedAttribute;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000036struct TranslatedIndexData;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000037
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038class Buffer;
39class Shader;
40class Program;
41class Texture;
42class Texture2D;
43class TextureCubeMap;
44class Framebuffer;
45class Renderbuffer;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000046class RenderbufferStorage;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047class Colorbuffer;
48class Depthbuffer;
49class Stencilbuffer;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +000050class DepthStencilbuffer;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000051class VertexDataManager;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +000052class IndexDataManager;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000053class BufferBackEnd;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +000054class Blit;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000055class Fence;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000056
57enum
58{
daniel@transgaming.com1c233ff2010-06-08 14:13:00 +000059 MAX_VERTEX_ATTRIBS = 12,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000060 MAX_VERTEX_UNIFORM_VECTORS = 128,
daniel@transgaming.com396c6432010-11-26 16:26:12 +000061 MAX_VARYING_VECTORS_SM2 = 8,
62 MAX_VARYING_VECTORS_SM3 = 10,
daniel@transgaming.com1c233ff2010-06-08 14:13:00 +000063 MAX_COMBINED_TEXTURE_IMAGE_UNITS = 16,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064 MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0,
daniel@transgaming.com1c233ff2010-06-08 14:13:00 +000065 MAX_TEXTURE_IMAGE_UNITS = 16,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066 MAX_FRAGMENT_UNIFORM_VECTORS = 16,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000067 MAX_DRAW_BUFFERS = 1,
68
69 IMPLEMENTATION_COLOR_READ_FORMAT = GL_RGB,
70 IMPLEMENTATION_COLOR_READ_TYPE = GL_UNSIGNED_SHORT_5_6_5
71};
72
daniel@transgaming.comd989add2010-03-26 04:08:42 +000073const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
74const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
daniel@transgaming.comccad59f2010-03-26 04:08:39 +000075const float ALIASED_POINT_SIZE_RANGE_MIN = 1.0f;
daniel@transgaming.combe5a0862010-07-28 19:20:37 +000076const float ALIASED_POINT_SIZE_RANGE_MAX_SM2 = 1.0f;
77const float ALIASED_POINT_SIZE_RANGE_MAX_SM3 = 64.0f;
daniel@transgaming.comccad59f2010-03-26 04:08:39 +000078
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000079struct Color
80{
81 float red;
82 float green;
83 float blue;
84 float alpha;
85};
86
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000087// Helper structure describing a single vertex attribute
88class AttributeState
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089{
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000090 public:
91 AttributeState()
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000092 : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mPointer(NULL), mEnabled(false)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000093 {
94 mCurrentValue[0] = 0;
95 mCurrentValue[1] = 0;
96 mCurrentValue[2] = 0;
97 mCurrentValue[3] = 1;
98 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000100 // From VertexArrayPointer
101 GLenum mType;
102 GLint mSize;
103 bool mNormalized;
104 GLsizei mStride; // 0 means natural stride
105 const void *mPointer;
106
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000107 BindingPointer<Buffer> mBoundBuffer; // Captured when VertexArrayPointer is called.
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000108
109 bool mEnabled; // From Enable/DisableVertexAttribArray
110
111 float mCurrentValue[4]; // From VertexAttrib4f
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000112};
113
114// Helper structure to store all raw state
115struct State
116{
117 Color colorClearValue;
118 GLclampf depthClearValue;
119 int stencilClearValue;
120
121 bool cullFace;
122 GLenum cullMode;
123 GLenum frontFace;
124 bool depthTest;
125 GLenum depthFunc;
126 bool blend;
127 GLenum sourceBlendRGB;
128 GLenum destBlendRGB;
129 GLenum sourceBlendAlpha;
130 GLenum destBlendAlpha;
131 GLenum blendEquationRGB;
132 GLenum blendEquationAlpha;
133 Color blendColor;
134 bool stencilTest;
135 GLenum stencilFunc;
136 GLint stencilRef;
137 GLuint stencilMask;
138 GLenum stencilFail;
139 GLenum stencilPassDepthFail;
140 GLenum stencilPassDepthPass;
141 GLuint stencilWritemask;
142 GLenum stencilBackFunc;
143 GLint stencilBackRef;
144 GLuint stencilBackMask;
145 GLenum stencilBackFail;
146 GLenum stencilBackPassDepthFail;
147 GLenum stencilBackPassDepthPass;
148 GLuint stencilBackWritemask;
149 bool polygonOffsetFill;
daniel@transgaming.com777f2672010-04-07 03:25:16 +0000150 GLfloat polygonOffsetFactor;
151 GLfloat polygonOffsetUnits;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000152 bool sampleAlphaToCoverage;
153 bool sampleCoverage;
154 GLclampf sampleCoverageValue;
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +0000155 bool sampleCoverageInvert;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000156 bool scissorTest;
157 bool dither;
158
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.com4f39fd92010-03-08 20:26:45 +0000164 GLint viewportX;
165 GLint viewportY;
166 GLsizei viewportWidth;
167 GLsizei viewportHeight;
168 float zNear;
169 float zFar;
170
171 GLint scissorX;
172 GLint scissorY;
173 GLsizei scissorWidth;
174 GLsizei scissorHeight;
175
176 bool colorMaskRed;
177 bool colorMaskGreen;
178 bool colorMaskBlue;
179 bool colorMaskAlpha;
180 bool depthMask;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000181
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000182 int activeSampler; // Active texture unit selector - GL_TEXTURE0
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000183 BindingPointer<Buffer> arrayBuffer;
184 BindingPointer<Buffer> elementArrayBuffer;
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +0000185 GLuint readFramebuffer;
186 GLuint drawFramebuffer;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000187 BindingPointer<Renderbuffer> renderbuffer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000188 GLuint currentProgram;
189
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000190 AttributeState vertexAttribute[MAX_VERTEX_ATTRIBS];
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000191 BindingPointer<Texture> samplerTexture[SAMPLER_TYPE_COUNT][MAX_TEXTURE_IMAGE_UNITS];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000192
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +0000193 GLint unpackAlignment;
194 GLint packAlignment;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000195};
196
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000197class Context
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198{
199 public:
daniel@transgaming.com0d25b002010-07-28 19:21:07 +0000200 Context(const egl::Config *config, const gl::Context *shareContext);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000201
202 ~Context();
203
204 void makeCurrent(egl::Display *display, egl::Surface *surface);
205
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000206 void markAllStateDirty();
207
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000208 // State manipulation
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000209 void setClearColor(float red, float green, float blue, float alpha);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000210
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211 void setClearDepth(float depth);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000212
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000213 void setClearStencil(int stencil);
214
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000215 void setCullFace(bool enabled);
216 bool isCullFaceEnabled() const;
217
218 void setCullMode(GLenum mode);
219
220 void setFrontFace(GLenum front);
221
222 void setDepthTest(bool enabled);
223 bool isDepthTestEnabled() const;
224
225 void setDepthFunc(GLenum depthFunc);
226
227 void setDepthRange(float zNear, float zFar);
228
229 void setBlend(bool enabled);
230 bool isBlendEnabled() const;
231
232 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
233 void setBlendColor(float red, float green, float blue, float alpha);
234 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
235
236 void setStencilTest(bool enabled);
237 bool isStencilTestEnabled() const;
238
239 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
240 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
241 void setStencilWritemask(GLuint stencilWritemask);
242 void setStencilBackWritemask(GLuint stencilBackWritemask);
243 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
244 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
245
246 void setPolygonOffsetFill(bool enabled);
247 bool isPolygonOffsetFillEnabled() const;
248
249 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
250
251 void setSampleAlphaToCoverage(bool enabled);
252 bool isSampleAlphaToCoverageEnabled() const;
253
254 void setSampleCoverage(bool enabled);
255 bool isSampleCoverageEnabled() const;
256
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +0000257 void setSampleCoverageParams(GLclampf value, bool invert);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000258
259 void setScissorTest(bool enabled);
260 bool isScissorTestEnabled() const;
261
262 void setDither(bool enabled);
263 bool isDitherEnabled() const;
264
265 void setLineWidth(GLfloat width);
266
267 void setGenerateMipmapHint(GLenum hint);
alokp@chromium.orgd303ef92010-09-09 17:30:15 +0000268 void setFragmentShaderDerivativeHint(GLenum hint);
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000269
270 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
271
272 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
273
274 void setColorMask(bool red, bool green, bool blue, bool alpha);
275 void setDepthMask(bool mask);
276
277 void setActiveSampler(int active);
278
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000279 GLuint getReadFramebufferHandle() const;
280 GLuint getDrawFramebufferHandle() const;
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000281 GLuint getRenderbufferHandle() const;
282
283 GLuint getArrayBufferHandle() const;
284
285 void setVertexAttribEnabled(unsigned int attribNum, bool enabled);
286 const AttributeState &getVertexAttribState(unsigned int attribNum);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000287 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000288 bool normalized, GLsizei stride, const void *pointer);
289 const void *getVertexAttribPointer(unsigned int attribNum) const;
290
291 const AttributeState *getVertexAttribBlock();
292
293 void setUnpackAlignment(GLint alignment);
294 GLint getUnpackAlignment() const;
295
296 void setPackAlignment(GLint alignment);
297 GLint getPackAlignment() const;
298
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000299 // These create and destroy methods are merely pass-throughs to
300 // ResourceManager, which owns these object types
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000301 GLuint createBuffer();
302 GLuint createShader(GLenum type);
303 GLuint createProgram();
304 GLuint createTexture();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305 GLuint createRenderbuffer();
306
307 void deleteBuffer(GLuint buffer);
308 void deleteShader(GLuint shader);
309 void deleteProgram(GLuint program);
310 void deleteTexture(GLuint texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000311 void deleteRenderbuffer(GLuint renderbuffer);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000312
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000313 // Framebuffers are owned by the Context, so these methods do not pass through
314 GLuint createFramebuffer();
315 void deleteFramebuffer(GLuint framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000317 // Fences are owned by the Context.
318 GLuint createFence();
319 void deleteFence(GLuint fence);
320
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000321 void bindArrayBuffer(GLuint buffer);
322 void bindElementArrayBuffer(GLuint buffer);
323 void bindTexture2D(GLuint texture);
324 void bindTextureCubeMap(GLuint texture);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000325 void bindReadFramebuffer(GLuint framebuffer);
326 void bindDrawFramebuffer(GLuint framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000327 void bindRenderbuffer(GLuint renderbuffer);
328 void useProgram(GLuint program);
329
330 void setFramebufferZero(Framebuffer *framebuffer);
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000331
332 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000333
daniel@transgaming.come4b08c82010-04-20 18:53:06 +0000334 void setVertexAttrib(GLuint index, const GLfloat *values);
335
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336 Buffer *getBuffer(GLuint handle);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000337 Fence *getFence(GLuint handle);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000338 Shader *getShader(GLuint handle);
339 Program *getProgram(GLuint handle);
340 Texture *getTexture(GLuint handle);
341 Framebuffer *getFramebuffer(GLuint handle);
342 Renderbuffer *getRenderbuffer(GLuint handle);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343
344 Buffer *getArrayBuffer();
345 Buffer *getElementArrayBuffer();
346 Program *getCurrentProgram();
347 Texture2D *getTexture2D();
348 TextureCubeMap *getTextureCubeMap();
daniel@transgaming.com416485f2010-03-16 06:23:23 +0000349 Texture *getSamplerTexture(unsigned int sampler, SamplerType type);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000350 Framebuffer *getReadFramebuffer();
351 Framebuffer *getDrawFramebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000352
daniel@transgaming.com777f2672010-04-07 03:25:16 +0000353 bool getFloatv(GLenum pname, GLfloat *params);
354 bool getIntegerv(GLenum pname, GLint *params);
355 bool getBooleanv(GLenum pname, GLboolean *params);
356
357 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams);
358
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000359 bool applyRenderTarget(bool ignoreViewport);
daniel@transgaming.com5af64272010-04-15 20:45:12 +0000360 void applyState(GLenum drawMode);
daniel@transgaming.com81655a72010-05-20 19:18:17 +0000361 GLenum applyVertexBuffer(GLenum mode, GLint first, GLsizei count, bool *useIndexing, TranslatedIndexData *indexInfo);
daniel@transgaming.com838bcea2010-05-20 19:17:42 +0000362 GLenum applyVertexBuffer(const TranslatedIndexData &indexInfo);
daniel@transgaming.com41d8dd82010-05-12 03:45:03 +0000363 GLenum applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
daniel@transgaming.com81655a72010-05-20 19:18:17 +0000364 GLenum applyCountingIndexBuffer(GLenum mode, GLenum count, TranslatedIndexData *indexInfo);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000365 void applyShaders();
366 void applyTextures();
367
368 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels);
369 void clear(GLbitfield mask);
370 void drawArrays(GLenum mode, GLint first, GLsizei count);
371 void drawElements(GLenum mode, GLsizei count, GLenum type, const void* indices);
372 void finish();
373 void flush();
374
375 void recordInvalidEnum();
376 void recordInvalidValue();
377 void recordInvalidOperation();
378 void recordOutOfMemory();
379 void recordInvalidFramebufferOperation();
380
381 GLenum getError();
382
daniel@transgaming.combe5a0862010-07-28 19:20:37 +0000383 bool supportsShaderModel3() const;
daniel@transgaming.com396c6432010-11-26 16:26:12 +0000384 int getMaximumVaryingVectors() const;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000385 int getMaximumRenderbufferDimension() const;
386 int getMaximumTextureDimension() const;
387 int getMaximumCubeTextureDimension() const;
388 int getMaximumTextureLevel() const;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000389 GLsizei getMaxSupportedSamples() const;
390 int getNearestSupportedSamples(D3DFORMAT format, int requested) const;
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +0000391 const char *getExtensionString() const;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000392 bool supportsEventQueries() const;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000393 bool supportsCompressedTextures() const;
daniel@transgaming.com0a337e92010-08-28 17:38:27 +0000394 bool supportsFloatTextures() const;
395 bool supportsFloatLinearFilter() const;
daniel@transgaming.com1297d922010-09-01 15:47:47 +0000396 bool supportsFloatRenderableTextures() const;
daniel@transgaming.com0a337e92010-08-28 17:38:27 +0000397 bool supportsHalfFloatTextures() const;
398 bool supportsHalfFloatLinearFilter() const;
daniel@transgaming.com1297d922010-09-01 15:47:47 +0000399 bool supportsHalfFloatRenderableTextures() const;
daniel@transgaming.comed828e52010-10-15 17:57:30 +0000400 bool supportsLuminanceTextures() const;
401 bool supportsLuminanceAlphaTextures() const;
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +0000402
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +0000403 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
404 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
405 GLbitfield mask);
406
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000407 Blit *getBlitter() { return mBlit; }
408
daniel@transgaming.comc808c5a2010-05-14 17:31:01 +0000409 const D3DCAPS9 &getDeviceCaps() { return mDeviceCaps; }
410
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000411 private:
412 DISALLOW_COPY_AND_ASSIGN(Context);
413
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000414 void lookupAttributeMapping(TranslatedAttribute *attributes);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000415
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000416 void detachBuffer(GLuint buffer);
417 void detachTexture(GLuint texture);
418 void detachFramebuffer(GLuint framebuffer);
419 void detachRenderbuffer(GLuint renderbuffer);
420
daniel@transgaming.com12d54072010-03-16 06:23:26 +0000421 Texture *getIncompleteTexture(SamplerType type);
422
daniel@transgaming.com5af64272010-04-15 20:45:12 +0000423 bool cullSkipsDraw(GLenum drawMode);
424 bool isTriangleMode(GLenum drawMode);
daniel@transgaming.comace5e662010-03-21 04:31:20 +0000425
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000426 const egl::Config *const mConfig;
427
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000428 State mState;
429
apatrick@chromium.org4e3bad42010-09-15 17:31:48 +0000430 BindingPointer<Texture2D> mTexture2DZero;
431 BindingPointer<TextureCubeMap> mTextureCubeMapZero;
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +0000432
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +0000433
434 typedef std::map<GLuint, Framebuffer*> FramebufferMap;
435 FramebufferMap mFramebufferMap;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000436
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000437 typedef std::map<GLuint, Fence*> FenceMap;
438 FenceMap mFenceMap;
439
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +0000440 void initExtensionString();
441 std::string mExtensionString;
442
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000443 BufferBackEnd *mBufferBackEnd;
444 VertexDataManager *mVertexDataManager;
daniel@transgaming.comf8b58a02010-03-26 04:08:45 +0000445 IndexDataManager *mIndexDataManager;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000446
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000447 Blit *mBlit;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000448
apatrick@chromium.org4e3bad42010-09-15 17:31:48 +0000449 BindingPointer<Texture> mIncompleteTextures[SAMPLER_TYPE_COUNT];
daniel@transgaming.com12d54072010-03-16 06:23:26 +0000450
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000451 // Recorded errors
452 bool mInvalidEnum;
453 bool mInvalidValue;
454 bool mInvalidOperation;
455 bool mOutOfMemory;
456 bool mInvalidFramebufferOperation;
daniel@transgaming.com159acdf2010-03-21 04:31:24 +0000457
458 bool mHasBeenCurrent;
daniel@transgaming.com296ca9c2010-04-03 20:56:07 +0000459
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000460 unsigned int mAppliedProgram;
daniel@transgaming.com092bd482010-05-12 03:39:36 +0000461 unsigned int mAppliedRenderTargetSerial;
daniel@transgaming.com339ae702010-05-12 03:40:20 +0000462 unsigned int mAppliedDepthbufferSerial;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000463 unsigned int mAppliedStencilbufferSerial;
vangelis@chromium.orgcf66ebb2010-09-14 22:15:43 +0000464 bool mDepthStencilInitialized;
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000465
daniel@transgaming.combe5a0862010-07-28 19:20:37 +0000466 bool mSupportsShaderModel3;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000467 int mMaxRenderbufferDimension;
468 int mMaxTextureDimension;
469 int mMaxCubeTextureDimension;
470 int mMaxTextureLevel;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000471 std::map<D3DFORMAT, bool *> mMultiSampleSupport;
472 GLsizei mMaxSupportedSamples;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +0000473 bool mSupportsEventQueries;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000474 bool mSupportsCompressedTextures;
daniel@transgaming.com0a337e92010-08-28 17:38:27 +0000475 bool mSupportsFloatTextures;
476 bool mSupportsFloatLinearFilter;
daniel@transgaming.com1297d922010-09-01 15:47:47 +0000477 bool mSupportsFloatRenderableTextures;
daniel@transgaming.com0a337e92010-08-28 17:38:27 +0000478 bool mSupportsHalfFloatTextures;
479 bool mSupportsHalfFloatLinearFilter;
daniel@transgaming.com1297d922010-09-01 15:47:47 +0000480 bool mSupportsHalfFloatRenderableTextures;
daniel@transgaming.comed828e52010-10-15 17:57:30 +0000481 bool mSupportsLuminanceTextures;
482 bool mSupportsLuminanceAlphaTextures;
daniel@transgaming.coma79f9d12010-05-12 03:40:01 +0000483
484 // state caching flags
485 bool mClearStateDirty;
486 bool mCullStateDirty;
487 bool mDepthStateDirty;
488 bool mMaskStateDirty;
489 bool mPixelPackingStateDirty;
490 bool mBlendStateDirty;
491 bool mStencilStateDirty;
492 bool mPolygonOffsetStateDirty;
493 bool mScissorStateDirty;
494 bool mSampleStateDirty;
495 bool mFrontFaceDirty;
496 bool mDitherStateDirty;
daniel@transgaming.comc808c5a2010-05-14 17:31:01 +0000497
daniel@transgaming.com8f05d1a2010-06-07 02:06:03 +0000498 IDirect3DStateBlock9 *mMaskedClearSavedState;
499
daniel@transgaming.comc808c5a2010-05-14 17:31:01 +0000500 D3DCAPS9 mDeviceCaps;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000501
502 ResourceManager *mResourceManager;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000503};
504}
505
506extern "C"
507{
508// Exported functions for use by EGL
daniel@transgaming.com0d25b002010-07-28 19:21:07 +0000509gl::Context *glCreateContext(const egl::Config *config, const gl::Context *shareContext);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000510void glDestroyContext(gl::Context *context);
511void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface);
512gl::Context *glGetCurrentContext();
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +0000513__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000514}
515
516#endif // INCLUDE_CONTEXT_H_