• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Context.h: Defines the Context class, managing all GL state and performing
16 // rendering operations. It is the GLES2 specific implementation of EGLContext.
17 
18 #ifndef LIBGLES_CM_CONTEXT_H_
19 #define LIBGLES_CM_CONTEXT_H_
20 
21 #include "libEGL/Context.hpp"
22 #include "ResourceManager.h"
23 #include "common/NameSpace.hpp"
24 #include "common/Object.hpp"
25 #include "common/Image.hpp"
26 #include "Renderer/Sampler.hpp"
27 #include "common/MatrixStack.hpp"
28 
29 #include <GLES/gl.h>
30 #include <GLES/glext.h>
31 #include <EGL/egl.h>
32 
33 #include <map>
34 #include <string>
35 
36 namespace gl { class Surface; }
37 
38 namespace egl
39 {
40 class Display;
41 class Config;
42 }
43 
44 namespace es1
45 {
46 struct TranslatedAttribute;
47 struct TranslatedIndexData;
48 
49 class Device;
50 class Buffer;
51 class Texture;
52 class Texture2D;
53 class TextureExternal;
54 class Framebuffer;
55 class Renderbuffer;
56 class RenderbufferStorage;
57 class Colorbuffer;
58 class Depthbuffer;
59 class StreamingIndexBuffer;
60 class Stencilbuffer;
61 class DepthStencilbuffer;
62 class VertexDataManager;
63 class IndexDataManager;
64 
65 enum
66 {
67 	MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,
68 	MAX_VARYING_VECTORS = 10,
69 	MAX_TEXTURE_UNITS = 2,
70 	MAX_DRAW_BUFFERS = 1,
71 	MAX_LIGHTS = 8,
72 	MAX_CLIP_PLANES = sw::MAX_CLIP_PLANES,
73 
74 	MAX_MODELVIEW_STACK_DEPTH = 32,
75 	MAX_PROJECTION_STACK_DEPTH = 2,
76 	MAX_TEXTURE_STACK_DEPTH = 2,
77 };
78 
79 const GLenum compressedTextureFormats[] =
80 {
81 	GL_ETC1_RGB8_OES,
82 	GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
83 	GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
84 };
85 
86 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
87 
88 const GLint multisampleCount[] = {4, 2, 1};
89 const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);
90 const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];
91 
92 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
93 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
94 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
95 const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;
96 const float SMOOTH_LINE_WIDTH_RANGE_MIN = 1.0f;
97 const float SMOOTH_LINE_WIDTH_RANGE_MAX = 1.0f;
98 const float SMOOTH_POINT_SIZE_RANGE_MIN = 0.125f;
99 const float SMOOTH_POINT_SIZE_RANGE_MAX = 8192.0f;
100 const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;
101 
102 struct Color
103 {
104 	float red;
105 	float green;
106 	float blue;
107 	float alpha;
108 };
109 
110 struct Point
111 {
112 	float x;
113 	float y;
114 	float z;
115 	float w;
116 };
117 
118 struct Vector
119 {
120 	float x;
121 	float y;
122 	float z;
123 };
124 
125 struct Attenuation
126 {
127 	float constant;
128 	float linear;
129 	float quadratic;
130 };
131 
132 struct Light
133 {
134 	bool enabled;
135 	Color ambient;
136 	Color diffuse;
137 	Color specular;
138 	Point position;
139 	Vector direction;
140 	Attenuation attenuation;
141 	float spotExponent;
142 	float spotCutoffAngle;
143 };
144 
145 // Helper structure describing a single vertex attribute
146 class VertexAttribute
147 {
148 public:
VertexAttribute()149 	VertexAttribute() : mType(GL_FLOAT), mSize(4), mNormalized(false), mStride(0), mPointer(nullptr), mArrayEnabled(false)
150 	{
151 		mCurrentValue[0] = 0.0f;
152 		mCurrentValue[1] = 0.0f;
153 		mCurrentValue[2] = 0.0f;
154 		mCurrentValue[3] = 1.0f;
155 	}
156 
typeSize()157 	int typeSize() const
158 	{
159 		switch(mType)
160 		{
161 		case GL_BYTE:           return mSize * sizeof(GLbyte);
162 		case GL_UNSIGNED_BYTE:  return mSize * sizeof(GLubyte);
163 		case GL_SHORT:          return mSize * sizeof(GLshort);
164 		case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
165 		case GL_FIXED:          return mSize * sizeof(GLfixed);
166 		case GL_FLOAT:          return mSize * sizeof(GLfloat);
167 		default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
168 		}
169 	}
170 
stride()171 	GLsizei stride() const
172 	{
173 		return mStride ? mStride : typeSize();
174 	}
175 
176 	// From glVertexAttribPointer
177 	GLenum mType;
178 	GLint mSize;
179 	bool mNormalized;
180 	GLsizei mStride;   // 0 means natural stride
181 
182 	union
183 	{
184 		const void *mPointer;
185 		intptr_t mOffset;
186 	};
187 
188 	gl::BindingPointer<Buffer> mBoundBuffer;   // Captured when glVertexAttribPointer is called.
189 
190 	bool mArrayEnabled;   // From glEnable/DisableVertexAttribArray
191 	float mCurrentValue[4];   // From glVertexAttrib
192 };
193 
194 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
195 
196 struct TextureUnit
197 {
198 	Color color;
199 	GLenum environmentMode;
200 	GLenum combineRGB;
201 	GLenum combineAlpha;
202 	GLenum src0RGB;
203 	GLenum src0Alpha;
204 	GLenum src1RGB;
205 	GLenum src1Alpha;
206 	GLenum src2RGB;
207 	GLenum src2Alpha;
208 	GLenum operand0RGB;
209 	GLenum operand0Alpha;
210 	GLenum operand1RGB;
211 	GLenum operand1Alpha;
212 	GLenum operand2RGB;
213 	GLenum operand2Alpha;
214 };
215 
216 // Helper structure to store all raw state
217 struct State
218 {
219 	Color colorClearValue;
220 	GLclampf depthClearValue;
221 	int stencilClearValue;
222 
223 	bool cullFaceEnabled;
224 	GLenum cullMode;
225 	GLenum frontFace;
226 	bool depthTestEnabled;
227 	GLenum depthFunc;
228 	bool blendEnabled;
229 	GLenum sourceBlendRGB;
230 	GLenum destBlendRGB;
231 	GLenum sourceBlendAlpha;
232 	GLenum destBlendAlpha;
233 	GLenum blendEquationRGB;
234 	GLenum blendEquationAlpha;
235 	bool stencilTestEnabled;
236 	GLenum stencilFunc;
237 	GLint stencilRef;
238 	GLuint stencilMask;
239 	GLenum stencilFail;
240 	GLenum stencilPassDepthFail;
241 	GLenum stencilPassDepthPass;
242 	GLuint stencilWritemask;
243 	bool polygonOffsetFillEnabled;
244 	GLfloat polygonOffsetFactor;
245 	GLfloat polygonOffsetUnits;
246 	bool sampleAlphaToCoverageEnabled;
247 	bool sampleCoverageEnabled;
248 	GLclampf sampleCoverageValue;
249 	bool sampleCoverageInvert;
250 	bool scissorTestEnabled;
251 	bool ditherEnabled;
252 	GLenum shadeModel;
253 
254 	GLfloat lineWidth;
255 
256 	GLenum generateMipmapHint;
257 	GLenum perspectiveCorrectionHint;
258 	GLenum fogHint;
259 
260 	GLint viewportX;
261 	GLint viewportY;
262 	GLsizei viewportWidth;
263 	GLsizei viewportHeight;
264 	float zNear;
265 	float zFar;
266 
267 	GLint scissorX;
268 	GLint scissorY;
269 	GLsizei scissorWidth;
270 	GLsizei scissorHeight;
271 
272 	bool colorMaskRed;
273 	bool colorMaskGreen;
274 	bool colorMaskBlue;
275 	bool colorMaskAlpha;
276 	bool depthMask;
277 
278 	unsigned int activeSampler;   // Active texture unit selector - GL_TEXTURE0
279 	gl::BindingPointer<Buffer> arrayBuffer;
280 	gl::BindingPointer<Buffer> elementArrayBuffer;
281 	GLuint framebuffer;
282 	gl::BindingPointer<Renderbuffer> renderbuffer;
283 
284 	VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
285 	gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_TEXTURE_UNITS];
286 
287 	GLint unpackAlignment;
288 	GLint packAlignment;
289 
290 	TextureUnit textureUnit[MAX_TEXTURE_UNITS];
291 };
292 
293 class [[clang::lto_visibility_public]] Context : public egl::Context
294 {
295 public:
296 	Context(egl::Display *display, const Context *shareContext, const egl::Config *config);
297 
298 	void makeCurrent(gl::Surface *surface) override;
299 	EGLint getClientVersion() const override;
300 	EGLint getConfigID() const override;
301 
302 	void finish() override;
303 
304 	void markAllStateDirty();
305 
306 	// State manipulation
307 	void setClearColor(float red, float green, float blue, float alpha);
308 	void setClearDepth(float depth);
309 	void setClearStencil(int stencil);
310 
311 	void setCullFaceEnabled(bool enabled);
312 	bool isCullFaceEnabled() const;
313 	void setCullMode(GLenum mode);
314 	void setFrontFace(GLenum front);
315 
316 	void setDepthTestEnabled(bool enabled);
317 	bool isDepthTestEnabled() const;
318 	void setDepthFunc(GLenum depthFunc);
319 	void setDepthRange(float zNear, float zFar);
320 
321 	void setAlphaTestEnabled(bool enabled);
322 	bool isAlphaTestEnabled() const;
323 	void setAlphaFunc(GLenum alphaFunc, GLclampf reference);
324 
325 	void setBlendEnabled(bool enabled);
326 	bool isBlendEnabled() const;
327 	void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
328 	void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
329 
330 	void setStencilTestEnabled(bool enabled);
331 	bool isStencilTestEnabled() const;
332 	void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
333 	void setStencilWritemask(GLuint stencilWritemask);
334 	void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
335 
336 	void setPolygonOffsetFillEnabled(bool enabled);
337 	bool isPolygonOffsetFillEnabled() const;
338 	void setPolygonOffsetParams(GLfloat factor, GLfloat units);
339 
340 	void setSampleAlphaToCoverageEnabled(bool enabled);
341 	bool isSampleAlphaToCoverageEnabled() const;
342 	void setSampleCoverageEnabled(bool enabled);
343 	bool isSampleCoverageEnabled() const;
344 	void setSampleCoverageParams(GLclampf value, bool invert);
345 
346 	void setShadeModel(GLenum mode);
347 	void setDitherEnabled(bool enabled);
348 	bool isDitherEnabled() const;
349 	void setLightingEnabled(bool enabled);
350 	bool isLightingEnabled() const;
351 	void setLightEnabled(int index, bool enable);
352 	bool isLightEnabled(int index) const;
353 	void setLightAmbient(int index, float r, float g, float b, float a);
354 	void setLightDiffuse(int index, float r, float g, float b, float a);
355 	void setLightSpecular(int index, float r, float g, float b, float a);
356 	void setLightPosition(int index, float x, float y, float z, float w);
357 	void setLightDirection(int index, float x, float y, float z);
358 	void setLightAttenuationConstant(int index, float constant);
359 	void setLightAttenuationLinear(int index, float linear);
360 	void setLightAttenuationQuadratic(int index, float quadratic);
361 	void setSpotLightExponent(int index, float exponent);
362 	void setSpotLightCutoff(int index, float cutoff);
363 
364 	void setGlobalAmbient(float red, float green, float blue, float alpha);
365 	void setMaterialAmbient(float red, float green, float blue, float alpha);
366 	void setMaterialDiffuse(float red, float green, float blue, float alpha);
367 	void setMaterialSpecular(float red, float green, float blue, float alpha);
368 	void setMaterialEmission(float red, float green, float blue, float alpha);
369 	void setMaterialShininess(float shininess);
370 	void setLightModelTwoSide(bool enable);
371 
372 	void setFogEnabled(bool enabled);
373 	bool isFogEnabled() const;
374 	void setFogMode(GLenum mode);
375 	void setFogDensity(float fogDensity);
376 	void setFogStart(float fogStart);
377 	void setFogEnd(float fogEnd);
378 	void setFogColor(float r, float g, float b, float a);
379 
380 	void setTexture2Denabled(bool enabled);
381 	bool isTexture2Denabled() const;
382 	void setTextureExternalEnabled(bool enabled);
383 	bool isTextureExternalEnabled() const;
384 	void clientActiveTexture(GLenum texture);
385 	GLenum getClientActiveTexture() const;
386 	unsigned int getActiveTexture() const;
387 
388 	void setTextureEnvMode(GLenum texEnvMode);
389 	void setTextureEnvColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
390 	void setCombineRGB(GLenum combineRGB);
391 	void setCombineAlpha(GLenum combineAlpha);
392 	void setOperand0RGB(GLenum operand);
393 	void setOperand1RGB(GLenum operand);
394 	void setOperand2RGB(GLenum operand);
395 	void setOperand0Alpha(GLenum operand);
396 	void setOperand1Alpha(GLenum operand);
397 	void setOperand2Alpha(GLenum operand);
398 	void setSrc0RGB(GLenum src);
399 	void setSrc1RGB(GLenum src);
400 	void setSrc2RGB(GLenum src);
401 	void setSrc0Alpha(GLenum src);
402 	void setSrc1Alpha(GLenum src);
403 	void setSrc2Alpha(GLenum src);
404 
405 	void setLineWidth(GLfloat width);
406 
407 	void setGenerateMipmapHint(GLenum hint);
408 	void setPerspectiveCorrectionHint(GLenum hint);
409 	void setFogHint(GLenum hint);
410 
411 	void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
412 
413 	void setScissorTestEnabled(bool enabled);
414 	bool isScissorTestEnabled() const;
415 	void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
416 
417 	void setColorMask(bool red, bool green, bool blue, bool alpha);
418 	void setDepthMask(bool mask);
419 
420 	void setActiveSampler(unsigned int active);
421 
422 	GLuint getFramebufferName() const;
423 	GLuint getRenderbufferName() const;
424 
425 	GLuint getArrayBufferName() const;
426 
427 	void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
428 	const VertexAttribute &getVertexAttribState(unsigned int attribNum);
429 	void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
430 	                          bool normalized, GLsizei stride, const void *pointer);
431 	const void *getVertexAttribPointer(unsigned int attribNum) const;
432 
433 	const VertexAttributeArray &getVertexAttributes();
434 
435 	void setUnpackAlignment(GLint alignment);
436 	GLint getUnpackAlignment() const;
437 
438 	void setPackAlignment(GLint alignment);
439 	GLint getPackAlignment() const;
440 
441 	// These create and destroy methods are merely pass-throughs to
442 	// ResourceManager, which owns these object types
443 	GLuint createBuffer();
444 	GLuint createTexture();
445 	GLuint createRenderbuffer();
446 
447 	void deleteBuffer(GLuint buffer);
448 	void deleteTexture(GLuint texture);
449 	void deleteRenderbuffer(GLuint renderbuffer);
450 
451 	// Framebuffers are owned by the Context, so these methods do not pass through
452 	GLuint createFramebuffer();
453 	void deleteFramebuffer(GLuint framebuffer);
454 
455 	void bindArrayBuffer(GLuint buffer);
456 	void bindElementArrayBuffer(GLuint buffer);
457 	void bindTexture(TextureType type, GLuint texture);
458 	void bindTextureExternal(GLuint texture);
459 	void bindFramebuffer(GLuint framebuffer);
460 	void bindRenderbuffer(GLuint renderbuffer);
461 
462 	void setFramebufferZero(Framebuffer *framebuffer);
463 
464 	void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
465 
466 	void setVertexAttrib(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
467 
468 	Buffer *getBuffer(GLuint handle);
469 	virtual Texture *getTexture(GLuint handle);
470 	Framebuffer *getFramebuffer(GLuint handle);
471 	virtual Renderbuffer *getRenderbuffer(GLuint handle);
472 
473 	Buffer *getArrayBuffer();
474 	Buffer *getElementArrayBuffer();
475 	Texture2D *getTexture2D();
476 	TextureExternal *getTextureExternal();
477 	Texture *getSamplerTexture(unsigned int sampler, TextureType type);
478 	Framebuffer *getFramebuffer();
479 
480 	bool getFloatv(GLenum pname, GLfloat *params);
481 	bool getIntegerv(GLenum pname, GLint *params);
482 	bool getBooleanv(GLenum pname, GLboolean *params);
483 	bool getPointerv(GLenum pname, const GLvoid **params);
484 
485 	int getQueryParameterNum(GLenum pname);
486 	bool isQueryParameterInt(GLenum pname);
487 	bool isQueryParameterFloat(GLenum pname);
488 	bool isQueryParameterBool(GLenum pname);
489 	bool isQueryParameterPointer(GLenum pname);
490 
491 	void drawArrays(GLenum mode, GLint first, GLsizei count);
492 	void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
493 	void drawTexture(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
494 	void blit(sw::Surface *source, const sw::SliceRect &sRect, sw::Surface *dest, const sw::SliceRect &dRect) override;
495 	void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
496 	void clear(GLbitfield mask);
497 	void flush();
498 
499 	void recordInvalidEnum();
500 	void recordInvalidValue();
501 	void recordInvalidOperation();
502 	void recordOutOfMemory();
503 	void recordInvalidFramebufferOperation();
504 	void recordMatrixStackOverflow();
505 	void recordMatrixStackUnderflow();
506 
507 	GLenum getError();
508 
509 	static int getSupportedMultisampleCount(int requested);
510 
511 	void bindTexImage(gl::Surface *surface) override;
512 	EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel) override;
513 	egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel) override;
514 	egl::Image *getSharedImage(GLeglImageOES image);
515 
516 	Device *getDevice();
517 
518 	void setMatrixMode(GLenum mode);
519 	void loadIdentity();
520 	void load(const GLfloat *m);
521 	void pushMatrix();
522 	void popMatrix();
523 	void rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
524 	void translate(GLfloat x, GLfloat y, GLfloat z);
525 	void scale(GLfloat x, GLfloat y, GLfloat z);
526 	void multiply(const GLfloat *m);
527 	void frustum(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
528 	void ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
529 
530 	void setClipPlane(int index, const float plane[4]);
531 	void setClipPlaneEnabled(int index, bool enable);
532 	bool isClipPlaneEnabled(int index) const;
533 
534 	void setColorLogicOpEnabled(bool enable);
535 	bool isColorLogicOpEnabled() const;
536 	void setLogicalOperation(GLenum logicOp);
537 
538 	void setPointSmoothEnabled(bool enable);
539 	bool isPointSmoothEnabled() const;
540 
541 	void setLineSmoothEnabled(bool enable);
542 	bool isLineSmoothEnabled() const;
543 
544 	void setColorMaterialEnabled(bool enable);
545 	bool isColorMaterialEnabled() const;
546 
547 	void setNormalizeEnabled(bool enable);
548 	bool isNormalizeEnabled() const;
549 
550 	void setRescaleNormalEnabled(bool enable);
551 	bool isRescaleNormalEnabled() const;
552 
553 	void setVertexArrayEnabled(bool enable);
554 	bool isVertexArrayEnabled() const;
555 
556 	void setNormalArrayEnabled(bool enable);
557 	bool isNormalArrayEnabled() const;
558 
559 	void setColorArrayEnabled(bool enable);
560 	bool isColorArrayEnabled() const;
561 
562 	void setPointSizeArrayEnabled(bool enable);
563 	bool isPointSizeArrayEnabled() const;
564 
565 	void setTextureCoordArrayEnabled(bool enable);
566 	bool isTextureCoordArrayEnabled() const;
567 
568 	void setMultisampleEnabled(bool enable);
569 	bool isMultisampleEnabled() const;
570 
571 	void setSampleAlphaToOneEnabled(bool enable);
572 	bool isSampleAlphaToOneEnabled() const;
573 
574 	void setPointSpriteEnabled(bool enable);
575 	bool isPointSpriteEnabled() const;
576 	void setPointSizeMin(float min);
577 	void setPointSizeMax(float max);
578 	void setPointDistanceAttenuation(float a, float b, float c);
579 	void setPointFadeThresholdSize(float threshold);
580 
581 private:
582 	~Context() override;
583 
584 	bool applyRenderTarget();
585 	void applyState(GLenum drawMode);
586 	GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count);
587 	GLenum applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
588 	void applyTextures();
589 	void applyTexture(int sampler, Texture *texture);
590 
591 	void detachBuffer(GLuint buffer);
592 	void detachTexture(GLuint texture);
593 	void detachFramebuffer(GLuint framebuffer);
594 	void detachRenderbuffer(GLuint renderbuffer);
595 
596 	bool cullSkipsDraw(GLenum drawMode);
597 	bool isTriangleMode(GLenum drawMode);
598 
599 	const egl::Config *const config;
600 
601 	State mState;
602 
603 	gl::BindingPointer<Texture2D> mTexture2DZero;
604 	gl::BindingPointer<TextureExternal> mTextureExternalZero;
605 
606 	gl::NameSpace<Framebuffer> mFramebufferNameSpace;
607 
608 	VertexDataManager *mVertexDataManager;
609 	IndexDataManager *mIndexDataManager;
610 
611 	bool lightingEnabled;
612 	Light light[MAX_LIGHTS];
613 	Color globalAmbient;
614 	Color materialAmbient;
615 	Color materialDiffuse;
616 	Color materialSpecular;
617 	Color materialEmission;
618 	GLfloat materialShininess;
619 	bool lightModelTwoSide;
620 
621 	// Recorded errors
622 	bool mInvalidEnum;
623 	bool mInvalidValue;
624 	bool mInvalidOperation;
625 	bool mOutOfMemory;
626 	bool mInvalidFramebufferOperation;
627 	bool mMatrixStackOverflow;
628 	bool mMatrixStackUnderflow;
629 
630 	bool mHasBeenCurrent;
631 
632 	// state caching flags
633 	bool mDepthStateDirty;
634 	bool mMaskStateDirty;
635 	bool mBlendStateDirty;
636 	bool mStencilStateDirty;
637 	bool mPolygonOffsetStateDirty;
638 	bool mSampleStateDirty;
639 	bool mFrontFaceDirty;
640 	bool mDitherStateDirty;
641 
642 	sw::MatrixStack &currentMatrixStack();
643 	GLenum matrixMode;
644 	sw::MatrixStack modelViewStack;
645 	sw::MatrixStack projectionStack;
646 	sw::MatrixStack textureStack0;
647 	sw::MatrixStack textureStack1;
648 
649 	bool texture2Denabled[MAX_TEXTURE_UNITS];
650 	bool textureExternalEnabled[MAX_TEXTURE_UNITS];
651 	GLenum clientTexture;
652 
653 	int clipFlags;
654 
655 	bool alphaTestEnabled;
656 	GLenum alphaTestFunc;
657 	float alphaTestRef;
658 
659 	bool fogEnabled;
660 	GLenum fogMode;
661 	float fogDensity;
662 	float fogStart;
663 	float fogEnd;
664 	Color fogColor;
665 
666 	bool lineSmoothEnabled;
667 	bool colorMaterialEnabled;
668 	bool normalizeEnabled;
669 	bool rescaleNormalEnabled;
670 	bool multisampleEnabled;
671 	bool sampleAlphaToOneEnabled;
672 
673 	bool pointSpriteEnabled;
674 	bool pointSmoothEnabled;
675 	float pointSizeMin;
676 	float pointSizeMax;
677 	Attenuation pointDistanceAttenuation;
678 	float pointFadeThresholdSize;
679 
680 	bool colorLogicOpEnabled;
681 	GLenum logicalOperation;
682 
683 	Device *device;
684 	ResourceManager *mResourceManager;
685 };
686 }
687 
688 #endif   // INCLUDE_CONTEXT_H_
689