Hash :
777f2672
Author :
Date :
2010-04-07T03:25:16
Implements type conversion for queries. TRAC #11593 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Also adds missing query parameters. Author: Shannon Woods git-svn-id: https://angleproject.googlecode.com/svn/trunk@102 736b8ea6-26fd-11df-bfd4-992fa37f6226
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Context.h: Defines the gl::Context class, managing all GL state and performing
// rendering operations. It is the GLES2 specific implementation of EGLContext.
#ifndef INCLUDE_CONTEXT_H_
#define INCLUDE_CONTEXT_H_
#define GL_APICALL
#include <GLES2/gl2.h>
#define EGLAPI
#include <EGL/egl.h>
#include <d3d9.h>
#include <map>
#include "common/angleutils.h"
namespace egl
{
class Display;
class Surface;
class Config;
}
namespace gl
{
struct TranslatedAttribute;
struct TranslatedIndexData;
class Buffer;
class Shader;
class Program;
class Texture;
class Texture2D;
class TextureCubeMap;
class Framebuffer;
class Renderbuffer;
class Colorbuffer;
class Depthbuffer;
class Stencilbuffer;
class VertexDataManager;
class IndexDataManager;
class BufferBackEnd;
enum
{
MAX_VERTEX_ATTRIBS = 8,
MAX_VERTEX_UNIFORM_VECTORS = 128,
MAX_VARYING_VECTORS = 8,
MAX_COMBINED_TEXTURE_IMAGE_UNITS = 8,
MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0,
MAX_TEXTURE_IMAGE_UNITS = 8,
MAX_FRAGMENT_UNIFORM_VECTORS = 16,
MAX_RENDERBUFFER_SIZE = 4096, // FIXME: Verify
MAX_DRAW_BUFFERS = 1,
IMPLEMENTATION_COLOR_READ_FORMAT = GL_RGB,
IMPLEMENTATION_COLOR_READ_TYPE = GL_UNSIGNED_SHORT_5_6_5
};
const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MIN = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MAX = 1.0f;
// Because indices are accessed internally, we convert them to a common format.
typedef unsigned short Index;
enum SamplerType
{
SAMPLER_2D,
SAMPLER_CUBE,
SAMPLER_TYPE_COUNT
};
struct Color
{
float red;
float green;
float blue;
float alpha;
};
// Helper structure describing a single vertex attribute
class AttributeState
{
public:
AttributeState()
: mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mPointer(NULL), mBoundBuffer(0), mEnabled(false)
{
mCurrentValue[0] = 0;
mCurrentValue[1] = 0;
mCurrentValue[2] = 0;
mCurrentValue[3] = 1;
}
// From VertexArrayPointer
GLenum mType;
GLint mSize;
bool mNormalized;
GLsizei mStride; // 0 means natural stride
const void *mPointer;
GLuint mBoundBuffer; // Captured when VertexArrayPointer is called.
bool mEnabled; // From Enable/DisableVertexAttribArray
float mCurrentValue[4]; // From VertexAttrib4f
};
// Helper structure to store all raw state
struct State
{
Color colorClearValue;
GLclampf depthClearValue;
int stencilClearValue;
bool cullFace;
GLenum cullMode;
GLenum frontFace;
bool depthTest;
GLenum depthFunc;
bool blend;
GLenum sourceBlendRGB;
GLenum destBlendRGB;
GLenum sourceBlendAlpha;
GLenum destBlendAlpha;
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
Color blendColor;
bool stencilTest;
GLenum stencilFunc;
GLint stencilRef;
GLuint stencilMask;
GLenum stencilFail;
GLenum stencilPassDepthFail;
GLenum stencilPassDepthPass;
GLuint stencilWritemask;
GLenum stencilBackFunc;
GLint stencilBackRef;
GLuint stencilBackMask;
GLenum stencilBackFail;
GLenum stencilBackPassDepthFail;
GLenum stencilBackPassDepthPass;
GLuint stencilBackWritemask;
bool polygonOffsetFill;
GLfloat polygonOffsetFactor;
GLfloat polygonOffsetUnits;
bool sampleAlphaToCoverage;
bool sampleCoverage;
GLclampf sampleCoverageValue;
GLboolean sampleCoverageInvert;
bool scissorTest;
bool dither;
GLfloat lineWidth;
GLenum generateMipmapHint;
GLint viewportX;
GLint viewportY;
GLsizei viewportWidth;
GLsizei viewportHeight;
float zNear;
float zFar;
GLint scissorX;
GLint scissorY;
GLsizei scissorWidth;
GLsizei scissorHeight;
bool colorMaskRed;
bool colorMaskGreen;
bool colorMaskBlue;
bool colorMaskAlpha;
bool depthMask;
int activeSampler; // Active texture unit selector - GL_TEXTURE0
GLuint arrayBuffer;
GLuint elementArrayBuffer;
GLuint texture2D;
GLuint textureCubeMap;
GLuint framebuffer;
GLuint renderbuffer;
GLuint currentProgram;
AttributeState vertexAttribute[MAX_VERTEX_ATTRIBS];
GLuint samplerTexture[SAMPLER_TYPE_COUNT][MAX_TEXTURE_IMAGE_UNITS];
GLint unpackAlignment;
GLint packAlignment;
};
class Context : public State
{
public:
Context(const egl::Config *config);
~Context();
void makeCurrent(egl::Display *display, egl::Surface *surface);
void setClearColor(float red, float green, float blue, float alpha);
void setClearDepth(float depth);
void setClearStencil(int stencil);
GLuint createBuffer();
GLuint createShader(GLenum type);
GLuint createProgram();
GLuint createTexture();
GLuint createFramebuffer();
GLuint createRenderbuffer();
void deleteBuffer(GLuint buffer);
void deleteShader(GLuint shader);
void deleteProgram(GLuint program);
void deleteTexture(GLuint texture);
void deleteFramebuffer(GLuint framebuffer);
void deleteRenderbuffer(GLuint renderbuffer);
void bindArrayBuffer(GLuint buffer);
void bindElementArrayBuffer(GLuint buffer);
void bindTexture2D(GLuint texture);
void bindTextureCubeMap(GLuint texture);
void bindFramebuffer(GLuint framebuffer);
void bindRenderbuffer(GLuint renderbuffer);
void useProgram(GLuint program);
void setFramebufferZero(Framebuffer *framebuffer);
void setColorbufferZero(Colorbuffer *renderbuffer);
void setDepthbufferZero(Depthbuffer *depthBuffer);
void setStencilbufferZero(Stencilbuffer *stencilBuffer);
void setRenderbuffer(Renderbuffer *renderbuffer);
Buffer *getBuffer(GLuint handle);
Shader *getShader(GLuint handle);
Program *getProgram(GLuint handle);
Texture *getTexture(GLuint handle);
Framebuffer *getFramebuffer(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle);
Colorbuffer *getColorbuffer(GLuint handle);
Depthbuffer *getDepthbuffer(GLuint handle);
Stencilbuffer *getStencilbuffer(GLuint handle);
Buffer *getArrayBuffer();
Buffer *getElementArrayBuffer();
Program *getCurrentProgram();
Texture2D *getTexture2D();
TextureCubeMap *getTextureCubeMap();
Texture *getSamplerTexture(unsigned int sampler, SamplerType type);
Framebuffer *getFramebuffer();
bool getFloatv(GLenum pname, GLfloat *params);
bool getIntegerv(GLenum pname, GLint *params);
bool getBooleanv(GLenum pname, GLboolean *params);
bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams);
bool applyRenderTarget(bool ignoreViewport);
void applyState();
void applyVertexBuffer(GLint first, GLsizei count);
void applyVertexBuffer(const TranslatedIndexData &indexInfo);
TranslatedIndexData applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type);
void applyShaders();
void applyTextures();
void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels);
void clear(GLbitfield mask);
void drawArrays(GLenum mode, GLint first, GLsizei count);
void drawElements(GLenum mode, GLsizei count, GLenum type, const void* indices);
void finish();
void flush();
void recordInvalidEnum();
void recordInvalidValue();
void recordInvalidOperation();
void recordOutOfMemory();
void recordInvalidFramebufferOperation();
GLenum getError();
const char *getPixelShaderProfile();
const char *getVertexShaderProfile();
private:
DISALLOW_COPY_AND_ASSIGN(Context);
void lookupAttributeMapping(TranslatedAttribute *attributes);
const Index *adjustIndexPointer(const void *indices);
void detachBuffer(GLuint buffer);
void detachTexture(GLuint texture);
void detachFramebuffer(GLuint framebuffer);
void detachRenderbuffer(GLuint renderbuffer);
Texture *getIncompleteTexture(SamplerType type);
bool cullSkipsDraw(GLenum primitiveType);
const egl::Config *const mConfig;
Texture2D *mTexture2DZero;
TextureCubeMap *mTextureCubeMapZero;
Colorbuffer *mColorbufferZero;
Depthbuffer *mDepthbufferZero;
Stencilbuffer *mStencilbufferZero;
typedef std::map<GLuint, Buffer*> BufferMap;
BufferMap mBufferMap;
typedef std::map<GLuint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLuint, Program*> ProgramMap;
ProgramMap mProgramMap;
typedef std::map<GLuint, Texture*> TextureMap;
TextureMap mTextureMap;
typedef std::map<GLuint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
typedef std::map<GLuint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
BufferBackEnd *mBufferBackEnd;
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
Texture *mIncompleteTextures[SAMPLER_TYPE_COUNT];
// Recorded errors
bool mInvalidEnum;
bool mInvalidValue;
bool mInvalidOperation;
bool mOutOfMemory;
bool mInvalidFramebufferOperation;
bool mHasBeenCurrent;
const char *mPsProfile;
const char *mVsProfile;
};
}
extern "C"
{
// Exported functions for use by EGL
gl::Context *glCreateContext(const egl::Config *config);
void glDestroyContext(gl::Context *context);
void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface);
gl::Context *glGetCurrentContext();
}
#endif // INCLUDE_CONTEXT_H_