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