daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 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.cpp: Implements the gl::Context class, managing all GL state and performing |
| 8 | // rendering operations. It is the GLES2 specific implementation of EGLContext. |
| 9 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 10 | #include "libGLESv2/Context.h" |
daniel@transgaming.com | 1697302 | 2010-03-11 19:22:19 +0000 | [diff] [blame] | 11 | |
| 12 | #include <algorithm> |
| 13 | |
alokp@chromium.org | ea0e1af | 2010-03-22 19:33:14 +0000 | [diff] [blame] | 14 | #include "libEGL/Display.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 15 | |
| 16 | #include "libGLESv2/main.h" |
| 17 | #include "libGLESv2/mathutil.h" |
| 18 | #include "libGLESv2/utilities.h" |
| 19 | #include "libGLESv2/Blit.h" |
| 20 | #include "libGLESv2/Buffer.h" |
| 21 | #include "libGLESv2/FrameBuffer.h" |
| 22 | #include "libGLESv2/Program.h" |
| 23 | #include "libGLESv2/RenderBuffer.h" |
| 24 | #include "libGLESv2/Shader.h" |
| 25 | #include "libGLESv2/Texture.h" |
| 26 | #include "libGLESv2/geometry/backend.h" |
| 27 | #include "libGLESv2/geometry/VertexDataManager.h" |
| 28 | #include "libGLESv2/geometry/IndexDataManager.h" |
| 29 | #include "libGLESv2/geometry/dx9.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 30 | |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 31 | #undef near |
| 32 | #undef far |
| 33 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 36 | Context::Context(const egl::Config *config) |
| 37 | : mConfig(config) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 38 | { |
| 39 | setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 40 | mState.depthClearValue = 1.0f; |
| 41 | mState.stencilClearValue = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 42 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 43 | mState.cullFace = false; |
| 44 | mState.cullMode = GL_BACK; |
| 45 | mState.frontFace = GL_CCW; |
| 46 | mState.depthTest = false; |
| 47 | mState.depthFunc = GL_LESS; |
| 48 | mState.blend = false; |
| 49 | mState.sourceBlendRGB = GL_ONE; |
| 50 | mState.sourceBlendAlpha = GL_ONE; |
| 51 | mState.destBlendRGB = GL_ZERO; |
| 52 | mState.destBlendAlpha = GL_ZERO; |
| 53 | mState.blendEquationRGB = GL_FUNC_ADD; |
| 54 | mState.blendEquationAlpha = GL_FUNC_ADD; |
| 55 | mState.blendColor.red = 0; |
| 56 | mState.blendColor.green = 0; |
| 57 | mState.blendColor.blue = 0; |
| 58 | mState.blendColor.alpha = 0; |
| 59 | mState.stencilTest = false; |
| 60 | mState.stencilFunc = GL_ALWAYS; |
| 61 | mState.stencilRef = 0; |
| 62 | mState.stencilMask = -1; |
| 63 | mState.stencilWritemask = -1; |
| 64 | mState.stencilBackFunc = GL_ALWAYS; |
| 65 | mState.stencilBackRef = 0; |
| 66 | mState.stencilBackMask = - 1; |
| 67 | mState.stencilBackWritemask = -1; |
| 68 | mState.stencilFail = GL_KEEP; |
| 69 | mState.stencilPassDepthFail = GL_KEEP; |
| 70 | mState.stencilPassDepthPass = GL_KEEP; |
| 71 | mState.stencilBackFail = GL_KEEP; |
| 72 | mState.stencilBackPassDepthFail = GL_KEEP; |
| 73 | mState.stencilBackPassDepthPass = GL_KEEP; |
| 74 | mState.polygonOffsetFill = false; |
| 75 | mState.polygonOffsetFactor = 0.0f; |
| 76 | mState.polygonOffsetUnits = 0.0f; |
| 77 | mState.sampleAlphaToCoverage = false; |
| 78 | mState.sampleCoverage = false; |
| 79 | mState.sampleCoverageValue = 1.0f; |
| 80 | mState.sampleCoverageInvert = GL_FALSE; |
| 81 | mState.scissorTest = false; |
| 82 | mState.dither = true; |
| 83 | mState.generateMipmapHint = GL_DONT_CARE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 84 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 85 | mState.lineWidth = 1.0f; |
daniel@transgaming.com | 32e58cd | 2010-03-24 09:44:10 +0000 | [diff] [blame] | 86 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 87 | mState.viewportX = 0; |
| 88 | mState.viewportY = 0; |
| 89 | mState.viewportWidth = config->mDisplayMode.Width; |
| 90 | mState.viewportHeight = config->mDisplayMode.Height; |
| 91 | mState.zNear = 0.0f; |
| 92 | mState.zFar = 1.0f; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 93 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 94 | mState.scissorX = 0; |
| 95 | mState.scissorY = 0; |
| 96 | mState.scissorWidth = config->mDisplayMode.Width; |
| 97 | mState.scissorHeight = config->mDisplayMode.Height; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 98 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 99 | mState.colorMaskRed = true; |
| 100 | mState.colorMaskGreen = true; |
| 101 | mState.colorMaskBlue = true; |
| 102 | mState.colorMaskAlpha = true; |
| 103 | mState.depthMask = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 104 | |
| 105 | // [OpenGL ES 2.0.24] section 3.7 page 83: |
| 106 | // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional |
| 107 | // and cube map texture state vectors respectively associated with them. |
| 108 | // In order that access to these initial textures not be lost, they are treated as texture |
| 109 | // objects all of whose names are 0. |
| 110 | |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 111 | mTexture2DZero = new Texture2D(this); |
| 112 | mTextureCubeMapZero = new TextureCubeMap(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 113 | |
| 114 | mColorbufferZero = NULL; |
| 115 | mDepthbufferZero = NULL; |
| 116 | mStencilbufferZero = NULL; |
| 117 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 118 | mState.activeSampler = 0; |
| 119 | mState.arrayBuffer = 0; |
| 120 | mState.elementArrayBuffer = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 121 | bindTextureCubeMap(0); |
| 122 | bindTexture2D(0); |
| 123 | bindFramebuffer(0); |
| 124 | bindRenderbuffer(0); |
| 125 | |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 126 | for (int type = 0; type < SAMPLER_TYPE_COUNT; type++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 127 | { |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 128 | for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++) |
| 129 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 130 | mState.samplerTexture[type][sampler] = 0; |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 131 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 132 | } |
| 133 | |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 134 | for (int type = 0; type < SAMPLER_TYPE_COUNT; type++) |
| 135 | { |
| 136 | mIncompleteTextures[type] = NULL; |
| 137 | } |
| 138 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 139 | mState.currentProgram = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 140 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 141 | mState.packAlignment = 4; |
| 142 | mState.unpackAlignment = 4; |
daniel@transgaming.com | 3489e3a | 2010-03-21 04:31:11 +0000 | [diff] [blame] | 143 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 144 | mBufferBackEnd = NULL; |
| 145 | mVertexDataManager = NULL; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 146 | mIndexDataManager = NULL; |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 147 | mBlit = NULL; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 148 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 149 | mInvalidEnum = false; |
| 150 | mInvalidValue = false; |
| 151 | mInvalidOperation = false; |
| 152 | mOutOfMemory = false; |
| 153 | mInvalidFramebufferOperation = false; |
daniel@transgaming.com | 159acdf | 2010-03-21 04:31:24 +0000 | [diff] [blame] | 154 | |
| 155 | mHasBeenCurrent = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | Context::~Context() |
| 159 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 160 | mState.currentProgram = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 161 | |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 162 | for (int type = 0; type < SAMPLER_TYPE_COUNT; type++) |
| 163 | { |
| 164 | delete mIncompleteTextures[type]; |
| 165 | } |
| 166 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 167 | delete mTexture2DZero; |
| 168 | delete mTextureCubeMapZero; |
| 169 | |
| 170 | delete mColorbufferZero; |
| 171 | delete mDepthbufferZero; |
| 172 | delete mStencilbufferZero; |
| 173 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 174 | delete mBufferBackEnd; |
| 175 | delete mVertexDataManager; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 176 | delete mIndexDataManager; |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 177 | delete mBlit; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 178 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 179 | while (!mBufferMap.empty()) |
| 180 | { |
| 181 | deleteBuffer(mBufferMap.begin()->first); |
| 182 | } |
| 183 | |
| 184 | while (!mProgramMap.empty()) |
| 185 | { |
| 186 | deleteProgram(mProgramMap.begin()->first); |
| 187 | } |
| 188 | |
| 189 | while (!mShaderMap.empty()) |
| 190 | { |
| 191 | deleteShader(mShaderMap.begin()->first); |
| 192 | } |
| 193 | |
| 194 | while (!mFramebufferMap.empty()) |
| 195 | { |
| 196 | deleteFramebuffer(mFramebufferMap.begin()->first); |
| 197 | } |
| 198 | |
| 199 | while (!mRenderbufferMap.empty()) |
| 200 | { |
| 201 | deleteRenderbuffer(mRenderbufferMap.begin()->first); |
| 202 | } |
| 203 | |
| 204 | while (!mTextureMap.empty()) |
| 205 | { |
| 206 | deleteTexture(mTextureMap.begin()->first); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | void Context::makeCurrent(egl::Display *display, egl::Surface *surface) |
| 211 | { |
| 212 | IDirect3DDevice9 *device = display->getDevice(); |
| 213 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 214 | if (!mBufferBackEnd) |
| 215 | { |
| 216 | mBufferBackEnd = new Dx9BackEnd(device); |
| 217 | mVertexDataManager = new VertexDataManager(this, mBufferBackEnd); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 218 | mIndexDataManager = new IndexDataManager(this, mBufferBackEnd); |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 219 | mBlit = new Blit(this); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 220 | } |
| 221 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 222 | // Wrap the existing Direct3D 9 resources into GL objects and assign them to the '0' names |
| 223 | IDirect3DSurface9 *defaultRenderTarget = surface->getRenderTarget(); |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 224 | IDirect3DSurface9 *depthStencil = surface->getDepthStencil(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 225 | |
| 226 | Framebuffer *framebufferZero = new Framebuffer(); |
| 227 | Colorbuffer *colorbufferZero = new Colorbuffer(defaultRenderTarget); |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 228 | Depthbuffer *depthbufferZero = new Depthbuffer(depthStencil); |
| 229 | Stencilbuffer *stencilbufferZero = new Stencilbuffer(depthStencil); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 230 | |
| 231 | setFramebufferZero(framebufferZero); |
| 232 | setColorbufferZero(colorbufferZero); |
| 233 | setDepthbufferZero(depthbufferZero); |
| 234 | setStencilbufferZero(stencilbufferZero); |
| 235 | |
| 236 | framebufferZero->setColorbuffer(GL_RENDERBUFFER, 0); |
| 237 | framebufferZero->setDepthbuffer(GL_RENDERBUFFER, 0); |
| 238 | framebufferZero->setStencilbuffer(GL_RENDERBUFFER, 0); |
| 239 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 240 | if (!mHasBeenCurrent) |
daniel@transgaming.com | 159acdf | 2010-03-21 04:31:24 +0000 | [diff] [blame] | 241 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 242 | mState.viewportX = 0; |
| 243 | mState.viewportY = 0; |
| 244 | mState.viewportWidth = surface->getWidth(); |
| 245 | mState.viewportHeight = surface->getHeight(); |
daniel@transgaming.com | 159acdf | 2010-03-21 04:31:24 +0000 | [diff] [blame] | 246 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 247 | mState.scissorX = 0; |
| 248 | mState.scissorY = 0; |
| 249 | mState.scissorWidth = surface->getWidth(); |
| 250 | mState.scissorHeight = surface->getHeight(); |
daniel@transgaming.com | 159acdf | 2010-03-21 04:31:24 +0000 | [diff] [blame] | 251 | |
| 252 | mHasBeenCurrent = true; |
| 253 | } |
| 254 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 255 | defaultRenderTarget->Release(); |
| 256 | |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 257 | if (depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 258 | { |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 259 | depthStencil->Release(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 260 | } |
daniel@transgaming.com | 296ca9c | 2010-04-03 20:56:07 +0000 | [diff] [blame] | 261 | |
| 262 | D3DCAPS9 capabilities; |
| 263 | device->GetDeviceCaps(&capabilities); |
| 264 | |
| 265 | if (capabilities.PixelShaderVersion == D3DPS_VERSION(3, 0)) |
| 266 | { |
| 267 | mPsProfile = "ps_3_0"; |
| 268 | mVsProfile = "vs_3_0"; |
| 269 | } |
| 270 | else // egl::Display guarantees support for at least 2.0 |
| 271 | { |
| 272 | mPsProfile = "ps_2_0"; |
| 273 | mVsProfile = "vs_2_0"; |
| 274 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void Context::setClearColor(float red, float green, float blue, float alpha) |
| 278 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 279 | mState.colorClearValue.red = red; |
| 280 | mState.colorClearValue.green = green; |
| 281 | mState.colorClearValue.blue = blue; |
| 282 | mState.colorClearValue.alpha = alpha; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void Context::setClearDepth(float depth) |
| 286 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 287 | mState.depthClearValue = depth; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void Context::setClearStencil(int stencil) |
| 291 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 292 | mState.stencilClearValue = stencil; |
| 293 | } |
| 294 | |
| 295 | void Context::setCullFace(bool enabled) |
| 296 | { |
| 297 | mState.cullFace = enabled; |
| 298 | } |
| 299 | |
| 300 | bool Context::isCullFaceEnabled() const |
| 301 | { |
| 302 | return mState.cullFace; |
| 303 | } |
| 304 | |
| 305 | void Context::setCullMode(GLenum mode) |
| 306 | { |
| 307 | mState.cullMode = mode; |
| 308 | } |
| 309 | |
| 310 | void Context::setFrontFace(GLenum front) |
| 311 | { |
| 312 | mState.frontFace = front; |
| 313 | } |
| 314 | |
| 315 | void Context::setDepthTest(bool enabled) |
| 316 | { |
| 317 | mState.depthTest = enabled; |
| 318 | } |
| 319 | |
| 320 | bool Context::isDepthTestEnabled() const |
| 321 | { |
| 322 | return mState.depthTest; |
| 323 | } |
| 324 | |
| 325 | void Context::setDepthFunc(GLenum depthFunc) |
| 326 | { |
| 327 | mState.depthFunc = depthFunc; |
| 328 | } |
| 329 | |
| 330 | void Context::setDepthRange(float zNear, float zFar) |
| 331 | { |
| 332 | mState.zNear = zNear; |
| 333 | mState.zFar = zFar; |
| 334 | } |
| 335 | |
| 336 | void Context::setBlend(bool enabled) |
| 337 | { |
| 338 | mState.blend = enabled; |
| 339 | } |
| 340 | |
| 341 | bool Context::isBlendEnabled() const |
| 342 | { |
| 343 | return mState.blend; |
| 344 | } |
| 345 | |
| 346 | void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) |
| 347 | { |
| 348 | mState.sourceBlendRGB = sourceRGB; |
| 349 | mState.destBlendRGB = destRGB; |
| 350 | mState.sourceBlendAlpha = sourceAlpha; |
| 351 | mState.destBlendAlpha = destAlpha; |
| 352 | } |
| 353 | |
| 354 | void Context::setBlendColor(float red, float green, float blue, float alpha) |
| 355 | { |
| 356 | mState.blendColor.red = red; |
| 357 | mState.blendColor.green = green; |
| 358 | mState.blendColor.blue = blue; |
| 359 | mState.blendColor.alpha = alpha; |
| 360 | } |
| 361 | |
| 362 | void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 363 | { |
| 364 | mState.blendEquationRGB = rgbEquation; |
| 365 | mState.blendEquationAlpha = alphaEquation; |
| 366 | } |
| 367 | |
| 368 | void Context::setStencilTest(bool enabled) |
| 369 | { |
| 370 | mState.stencilTest = enabled; |
| 371 | } |
| 372 | |
| 373 | bool Context::isStencilTestEnabled() const |
| 374 | { |
| 375 | return mState.stencilTest; |
| 376 | } |
| 377 | |
| 378 | void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 379 | { |
| 380 | mState.stencilFunc = stencilFunc; |
| 381 | mState.stencilRef = stencilRef; |
| 382 | mState.stencilMask = stencilMask; |
| 383 | } |
| 384 | |
| 385 | void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) |
| 386 | { |
| 387 | mState.stencilBackFunc = stencilBackFunc; |
| 388 | mState.stencilBackRef = stencilBackRef; |
| 389 | mState.stencilBackMask = stencilBackMask; |
| 390 | } |
| 391 | |
| 392 | void Context::setStencilWritemask(GLuint stencilWritemask) |
| 393 | { |
| 394 | mState.stencilWritemask = stencilWritemask; |
| 395 | } |
| 396 | |
| 397 | void Context::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 398 | { |
| 399 | mState.stencilBackWritemask = stencilBackWritemask; |
| 400 | } |
| 401 | |
| 402 | void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) |
| 403 | { |
| 404 | mState.stencilFail = stencilFail; |
| 405 | mState.stencilPassDepthFail = stencilPassDepthFail; |
| 406 | mState.stencilPassDepthPass = stencilPassDepthPass; |
| 407 | } |
| 408 | |
| 409 | void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) |
| 410 | { |
| 411 | mState.stencilBackFail = stencilBackFail; |
| 412 | mState.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 413 | mState.stencilBackPassDepthPass = stencilBackPassDepthPass; |
| 414 | } |
| 415 | |
| 416 | void Context::setPolygonOffsetFill(bool enabled) |
| 417 | { |
| 418 | mState.polygonOffsetFill = enabled; |
| 419 | } |
| 420 | |
| 421 | bool Context::isPolygonOffsetFillEnabled() const |
| 422 | { |
| 423 | return mState.polygonOffsetFill; |
| 424 | } |
| 425 | |
| 426 | void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units) |
| 427 | { |
| 428 | mState.polygonOffsetFactor = factor; |
| 429 | mState.polygonOffsetUnits = units; |
| 430 | } |
| 431 | |
| 432 | void Context::setSampleAlphaToCoverage(bool enabled) |
| 433 | { |
| 434 | mState.sampleAlphaToCoverage = enabled; |
| 435 | } |
| 436 | |
| 437 | bool Context::isSampleAlphaToCoverageEnabled() const |
| 438 | { |
| 439 | return mState.sampleAlphaToCoverage; |
| 440 | } |
| 441 | |
| 442 | void Context::setSampleCoverage(bool enabled) |
| 443 | { |
| 444 | mState.sampleCoverage = enabled; |
| 445 | } |
| 446 | |
| 447 | bool Context::isSampleCoverageEnabled() const |
| 448 | { |
| 449 | return mState.sampleCoverage; |
| 450 | } |
| 451 | |
| 452 | void Context::setSampleCoverageParams(GLclampf value, GLboolean invert) |
| 453 | { |
| 454 | mState.sampleCoverageValue = value; |
| 455 | mState.sampleCoverageInvert = invert; |
| 456 | } |
| 457 | |
| 458 | void Context::setScissorTest(bool enabled) |
| 459 | { |
| 460 | mState.scissorTest = enabled; |
| 461 | } |
| 462 | |
| 463 | bool Context::isScissorTestEnabled() const |
| 464 | { |
| 465 | return mState.scissorTest; |
| 466 | } |
| 467 | |
| 468 | void Context::setDither(bool enabled) |
| 469 | { |
| 470 | mState.dither = enabled; |
| 471 | } |
| 472 | |
| 473 | bool Context::isDitherEnabled() const |
| 474 | { |
| 475 | return mState.dither; |
| 476 | } |
| 477 | |
| 478 | void Context::setLineWidth(GLfloat width) |
| 479 | { |
| 480 | mState.lineWidth = width; |
| 481 | } |
| 482 | |
| 483 | void Context::setGenerateMipmapHint(GLenum hint) |
| 484 | { |
| 485 | mState.generateMipmapHint = hint; |
| 486 | } |
| 487 | |
| 488 | void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 489 | { |
| 490 | mState.viewportX = x; |
| 491 | mState.viewportY = y; |
| 492 | mState.viewportWidth = width; |
| 493 | mState.viewportHeight = height; |
| 494 | } |
| 495 | |
| 496 | void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 497 | { |
| 498 | mState.scissorX = x; |
| 499 | mState.scissorY = y; |
| 500 | mState.scissorWidth = width; |
| 501 | mState.scissorHeight = height; |
| 502 | } |
| 503 | |
| 504 | void Context::setColorMask(bool red, bool green, bool blue, bool alpha) |
| 505 | { |
| 506 | mState.colorMaskRed = red; |
| 507 | mState.colorMaskGreen = green; |
| 508 | mState.colorMaskBlue = blue; |
| 509 | mState.colorMaskAlpha = alpha; |
| 510 | } |
| 511 | |
| 512 | void Context::setDepthMask(bool mask) |
| 513 | { |
| 514 | mState.depthMask = mask; |
| 515 | } |
| 516 | |
| 517 | void Context::setActiveSampler(int active) |
| 518 | { |
| 519 | mState.activeSampler = active; |
| 520 | } |
| 521 | |
| 522 | GLuint Context::getFramebufferHandle() const |
| 523 | { |
| 524 | return mState.framebuffer; |
| 525 | } |
| 526 | |
| 527 | GLuint Context::getRenderbufferHandle() const |
| 528 | { |
| 529 | return mState.renderbuffer; |
| 530 | } |
| 531 | |
| 532 | GLuint Context::getArrayBufferHandle() const |
| 533 | { |
| 534 | return mState.arrayBuffer; |
| 535 | } |
| 536 | |
| 537 | void Context::setVertexAttribEnabled(unsigned int attribNum, bool enabled) |
| 538 | { |
| 539 | mState.vertexAttribute[attribNum].mEnabled = enabled; |
| 540 | } |
| 541 | |
| 542 | const AttributeState &Context::getVertexAttribState(unsigned int attribNum) |
| 543 | { |
| 544 | return mState.vertexAttribute[attribNum]; |
| 545 | } |
| 546 | |
| 547 | void Context::setVertexAttribState(unsigned int attribNum, GLuint boundBuffer, GLint size, GLenum type, bool normalized, |
| 548 | GLsizei stride, const void *pointer) |
| 549 | { |
| 550 | mState.vertexAttribute[attribNum].mBoundBuffer = boundBuffer; |
| 551 | mState.vertexAttribute[attribNum].mSize = size; |
| 552 | mState.vertexAttribute[attribNum].mType = type; |
| 553 | mState.vertexAttribute[attribNum].mNormalized = normalized; |
| 554 | mState.vertexAttribute[attribNum].mStride = stride; |
| 555 | mState.vertexAttribute[attribNum].mPointer = pointer; |
| 556 | } |
| 557 | |
| 558 | const void *Context::getVertexAttribPointer(unsigned int attribNum) const |
| 559 | { |
| 560 | return mState.vertexAttribute[attribNum].mPointer; |
| 561 | } |
| 562 | |
| 563 | // returns entire set of attributes as a block |
| 564 | const AttributeState *Context::getVertexAttribBlock() |
| 565 | { |
| 566 | return mState.vertexAttribute; |
| 567 | } |
| 568 | |
| 569 | void Context::setPackAlignment(GLint alignment) |
| 570 | { |
| 571 | mState.packAlignment = alignment; |
| 572 | } |
| 573 | |
| 574 | GLint Context::getPackAlignment() const |
| 575 | { |
| 576 | return mState.packAlignment; |
| 577 | } |
| 578 | |
| 579 | void Context::setUnpackAlignment(GLint alignment) |
| 580 | { |
| 581 | mState.unpackAlignment = alignment; |
| 582 | } |
| 583 | |
| 584 | GLint Context::getUnpackAlignment() const |
| 585 | { |
| 586 | return mState.unpackAlignment; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | // Returns an unused buffer name |
| 590 | GLuint Context::createBuffer() |
| 591 | { |
| 592 | unsigned int handle = 1; |
| 593 | |
| 594 | while (mBufferMap.find(handle) != mBufferMap.end()) |
| 595 | { |
| 596 | handle++; |
| 597 | } |
| 598 | |
| 599 | mBufferMap[handle] = NULL; |
| 600 | |
| 601 | return handle; |
| 602 | } |
| 603 | |
| 604 | // Returns an unused shader/program name |
| 605 | GLuint Context::createShader(GLenum type) |
| 606 | { |
| 607 | unsigned int handle = 1; |
| 608 | |
| 609 | while (mShaderMap.find(handle) != mShaderMap.end() || mProgramMap.find(handle) != mProgramMap.end()) // Shared name space |
| 610 | { |
| 611 | handle++; |
| 612 | } |
| 613 | |
| 614 | if (type == GL_VERTEX_SHADER) |
| 615 | { |
daniel@transgaming.com | 9512434 | 2010-04-29 03:38:58 +0000 | [diff] [blame] | 616 | mShaderMap[handle] = new VertexShader(this, handle); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 617 | } |
| 618 | else if (type == GL_FRAGMENT_SHADER) |
| 619 | { |
daniel@transgaming.com | 9512434 | 2010-04-29 03:38:58 +0000 | [diff] [blame] | 620 | mShaderMap[handle] = new FragmentShader(this, handle); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 621 | } |
| 622 | else UNREACHABLE(); |
| 623 | |
| 624 | return handle; |
| 625 | } |
| 626 | |
| 627 | // Returns an unused program/shader name |
| 628 | GLuint Context::createProgram() |
| 629 | { |
| 630 | unsigned int handle = 1; |
| 631 | |
| 632 | while (mProgramMap.find(handle) != mProgramMap.end() || mShaderMap.find(handle) != mShaderMap.end()) // Shared name space |
| 633 | { |
| 634 | handle++; |
| 635 | } |
| 636 | |
| 637 | mProgramMap[handle] = new Program(); |
| 638 | |
| 639 | return handle; |
| 640 | } |
| 641 | |
| 642 | // Returns an unused texture name |
| 643 | GLuint Context::createTexture() |
| 644 | { |
| 645 | unsigned int handle = 1; |
| 646 | |
| 647 | while (mTextureMap.find(handle) != mTextureMap.end()) |
| 648 | { |
| 649 | handle++; |
| 650 | } |
| 651 | |
| 652 | mTextureMap[handle] = NULL; |
| 653 | |
| 654 | return handle; |
| 655 | } |
| 656 | |
| 657 | // Returns an unused framebuffer name |
| 658 | GLuint Context::createFramebuffer() |
| 659 | { |
| 660 | unsigned int handle = 1; |
| 661 | |
| 662 | while (mFramebufferMap.find(handle) != mFramebufferMap.end()) |
| 663 | { |
| 664 | handle++; |
| 665 | } |
| 666 | |
| 667 | mFramebufferMap[handle] = NULL; |
| 668 | |
| 669 | return handle; |
| 670 | } |
| 671 | |
| 672 | // Returns an unused renderbuffer name |
| 673 | GLuint Context::createRenderbuffer() |
| 674 | { |
| 675 | unsigned int handle = 1; |
| 676 | |
daniel@transgaming.com | e2b2212 | 2010-03-11 19:22:14 +0000 | [diff] [blame] | 677 | while (mRenderbufferMap.find(handle) != mRenderbufferMap.end()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 678 | { |
| 679 | handle++; |
| 680 | } |
| 681 | |
| 682 | mRenderbufferMap[handle] = NULL; |
| 683 | |
| 684 | return handle; |
| 685 | } |
| 686 | |
| 687 | void Context::deleteBuffer(GLuint buffer) |
| 688 | { |
| 689 | BufferMap::iterator bufferObject = mBufferMap.find(buffer); |
| 690 | |
| 691 | if (bufferObject != mBufferMap.end()) |
| 692 | { |
| 693 | detachBuffer(buffer); |
| 694 | |
| 695 | delete bufferObject->second; |
| 696 | mBufferMap.erase(bufferObject); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | void Context::deleteShader(GLuint shader) |
| 701 | { |
| 702 | ShaderMap::iterator shaderObject = mShaderMap.find(shader); |
| 703 | |
| 704 | if (shaderObject != mShaderMap.end()) |
| 705 | { |
| 706 | if (!shaderObject->second->isAttached()) |
| 707 | { |
| 708 | delete shaderObject->second; |
| 709 | mShaderMap.erase(shaderObject); |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | shaderObject->second->flagForDeletion(); |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | void Context::deleteProgram(GLuint program) |
| 719 | { |
| 720 | ProgramMap::iterator programObject = mProgramMap.find(program); |
| 721 | |
| 722 | if (programObject != mProgramMap.end()) |
| 723 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 724 | if (program != mState.currentProgram) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 725 | { |
| 726 | delete programObject->second; |
| 727 | mProgramMap.erase(programObject); |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | programObject->second->flagForDeletion(); |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | void Context::deleteTexture(GLuint texture) |
| 737 | { |
| 738 | TextureMap::iterator textureObject = mTextureMap.find(texture); |
| 739 | |
| 740 | if (textureObject != mTextureMap.end()) |
| 741 | { |
| 742 | detachTexture(texture); |
| 743 | |
| 744 | if (texture != 0) |
| 745 | { |
| 746 | delete textureObject->second; |
| 747 | } |
| 748 | |
| 749 | mTextureMap.erase(textureObject); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | void Context::deleteFramebuffer(GLuint framebuffer) |
| 754 | { |
| 755 | FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); |
| 756 | |
| 757 | if (framebufferObject != mFramebufferMap.end()) |
| 758 | { |
| 759 | detachFramebuffer(framebuffer); |
| 760 | |
| 761 | delete framebufferObject->second; |
| 762 | mFramebufferMap.erase(framebufferObject); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | void Context::deleteRenderbuffer(GLuint renderbuffer) |
| 767 | { |
| 768 | RenderbufferMap::iterator renderbufferObject = mRenderbufferMap.find(renderbuffer); |
| 769 | |
| 770 | if (renderbufferObject != mRenderbufferMap.end()) |
| 771 | { |
| 772 | detachRenderbuffer(renderbuffer); |
| 773 | |
| 774 | delete renderbufferObject->second; |
| 775 | mRenderbufferMap.erase(renderbufferObject); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | void Context::bindArrayBuffer(unsigned int buffer) |
| 780 | { |
| 781 | if (buffer != 0 && !getBuffer(buffer)) |
| 782 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 783 | mBufferMap[buffer] = new Buffer(mBufferBackEnd); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 784 | } |
| 785 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 786 | mState.arrayBuffer = buffer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | void Context::bindElementArrayBuffer(unsigned int buffer) |
| 790 | { |
| 791 | if (buffer != 0 && !getBuffer(buffer)) |
| 792 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 793 | mBufferMap[buffer] = new Buffer(mBufferBackEnd); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 794 | } |
| 795 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 796 | mState.elementArrayBuffer = buffer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | void Context::bindTexture2D(GLuint texture) |
| 800 | { |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 801 | if (!getTexture(texture) && texture != 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 802 | { |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 803 | mTextureMap[texture] = new Texture2D(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 804 | } |
| 805 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 806 | mState.texture2D = texture; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 807 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 808 | mState.samplerTexture[SAMPLER_2D][mState.activeSampler] = texture; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void Context::bindTextureCubeMap(GLuint texture) |
| 812 | { |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 813 | if (!getTexture(texture) && texture != 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 814 | { |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 815 | mTextureMap[texture] = new TextureCubeMap(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 816 | } |
| 817 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 818 | mState.textureCubeMap = texture; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 819 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 820 | mState.samplerTexture[SAMPLER_CUBE][mState.activeSampler] = texture; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | void Context::bindFramebuffer(GLuint framebuffer) |
| 824 | { |
| 825 | if (!getFramebuffer(framebuffer)) |
| 826 | { |
| 827 | mFramebufferMap[framebuffer] = new Framebuffer(); |
| 828 | } |
| 829 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 830 | mState.framebuffer = framebuffer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | void Context::bindRenderbuffer(GLuint renderbuffer) |
| 834 | { |
| 835 | if (renderbuffer != 0 && !getRenderbuffer(renderbuffer)) |
| 836 | { |
| 837 | mRenderbufferMap[renderbuffer] = new Renderbuffer(); |
| 838 | } |
| 839 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 840 | mState.renderbuffer = renderbuffer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | void Context::useProgram(GLuint program) |
| 844 | { |
| 845 | Program *programObject = getCurrentProgram(); |
| 846 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 847 | GLuint priorProgram = mState.currentProgram; |
| 848 | mState.currentProgram = program; // Must switch before trying to delete, otherwise it only gets flagged. |
daniel@transgaming.com | 71cd868 | 2010-04-29 03:35:25 +0000 | [diff] [blame] | 849 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 850 | if (programObject && programObject->isFlaggedForDeletion()) |
| 851 | { |
daniel@transgaming.com | 71cd868 | 2010-04-29 03:35:25 +0000 | [diff] [blame] | 852 | deleteProgram(priorProgram); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 853 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | void Context::setFramebufferZero(Framebuffer *buffer) |
| 857 | { |
| 858 | delete mFramebufferMap[0]; |
| 859 | mFramebufferMap[0] = buffer; |
| 860 | } |
| 861 | |
| 862 | void Context::setColorbufferZero(Colorbuffer *buffer) |
| 863 | { |
| 864 | delete mColorbufferZero; |
| 865 | mColorbufferZero = buffer; |
| 866 | } |
| 867 | |
| 868 | void Context::setDepthbufferZero(Depthbuffer *buffer) |
| 869 | { |
| 870 | delete mDepthbufferZero; |
| 871 | mDepthbufferZero = buffer; |
| 872 | } |
| 873 | |
| 874 | void Context::setStencilbufferZero(Stencilbuffer *buffer) |
| 875 | { |
| 876 | delete mStencilbufferZero; |
| 877 | mStencilbufferZero = buffer; |
| 878 | } |
| 879 | |
| 880 | void Context::setRenderbuffer(Renderbuffer *buffer) |
| 881 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 882 | delete mRenderbufferMap[mState.renderbuffer]; |
| 883 | mRenderbufferMap[mState.renderbuffer] = buffer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | Buffer *Context::getBuffer(unsigned int handle) |
| 887 | { |
| 888 | BufferMap::iterator buffer = mBufferMap.find(handle); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 889 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 890 | if (buffer == mBufferMap.end()) |
| 891 | { |
| 892 | return NULL; |
| 893 | } |
| 894 | else |
| 895 | { |
| 896 | return buffer->second; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | Shader *Context::getShader(unsigned int handle) |
| 901 | { |
| 902 | ShaderMap::iterator shader = mShaderMap.find(handle); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 903 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 904 | if (shader == mShaderMap.end()) |
| 905 | { |
| 906 | return NULL; |
| 907 | } |
| 908 | else |
| 909 | { |
| 910 | return shader->second; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | Program *Context::getProgram(unsigned int handle) |
| 915 | { |
| 916 | ProgramMap::iterator program = mProgramMap.find(handle); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 917 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 918 | if (program == mProgramMap.end()) |
| 919 | { |
| 920 | return NULL; |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | return program->second; |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | Texture *Context::getTexture(unsigned int handle) |
| 929 | { |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 930 | if (handle == 0) return NULL; |
| 931 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 932 | TextureMap::iterator texture = mTextureMap.find(handle); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 933 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 934 | if (texture == mTextureMap.end()) |
| 935 | { |
| 936 | return NULL; |
| 937 | } |
| 938 | else |
| 939 | { |
| 940 | return texture->second; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | Framebuffer *Context::getFramebuffer(unsigned int handle) |
| 945 | { |
| 946 | FramebufferMap::iterator framebuffer = mFramebufferMap.find(handle); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 947 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 948 | if (framebuffer == mFramebufferMap.end()) |
| 949 | { |
| 950 | return NULL; |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | return framebuffer->second; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | Renderbuffer *Context::getRenderbuffer(unsigned int handle) |
| 959 | { |
| 960 | RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 961 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 962 | if (renderbuffer == mRenderbufferMap.end()) |
| 963 | { |
| 964 | return NULL; |
| 965 | } |
| 966 | else |
| 967 | { |
| 968 | return renderbuffer->second; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | Colorbuffer *Context::getColorbuffer(GLuint handle) |
| 973 | { |
| 974 | if (handle != 0) |
| 975 | { |
| 976 | Renderbuffer *renderbuffer = getRenderbuffer(handle); |
| 977 | |
daniel@transgaming.com | e2b2212 | 2010-03-11 19:22:14 +0000 | [diff] [blame] | 978 | if (renderbuffer && renderbuffer->isColorbuffer()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 979 | { |
| 980 | return static_cast<Colorbuffer*>(renderbuffer); |
| 981 | } |
| 982 | } |
| 983 | else // Special case: 0 refers to different initial render targets based on the attachment type |
| 984 | { |
| 985 | return mColorbufferZero; |
| 986 | } |
| 987 | |
| 988 | return NULL; |
| 989 | } |
| 990 | |
| 991 | Depthbuffer *Context::getDepthbuffer(GLuint handle) |
| 992 | { |
| 993 | if (handle != 0) |
| 994 | { |
| 995 | Renderbuffer *renderbuffer = getRenderbuffer(handle); |
| 996 | |
daniel@transgaming.com | e2b2212 | 2010-03-11 19:22:14 +0000 | [diff] [blame] | 997 | if (renderbuffer && renderbuffer->isDepthbuffer()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 998 | { |
| 999 | return static_cast<Depthbuffer*>(renderbuffer); |
| 1000 | } |
| 1001 | } |
| 1002 | else // Special case: 0 refers to different initial render targets based on the attachment type |
| 1003 | { |
| 1004 | return mDepthbufferZero; |
| 1005 | } |
| 1006 | |
| 1007 | return NULL; |
| 1008 | } |
| 1009 | |
| 1010 | Stencilbuffer *Context::getStencilbuffer(GLuint handle) |
| 1011 | { |
| 1012 | if (handle != 0) |
| 1013 | { |
| 1014 | Renderbuffer *renderbuffer = getRenderbuffer(handle); |
| 1015 | |
daniel@transgaming.com | e2b2212 | 2010-03-11 19:22:14 +0000 | [diff] [blame] | 1016 | if (renderbuffer && renderbuffer->isStencilbuffer()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1017 | { |
| 1018 | return static_cast<Stencilbuffer*>(renderbuffer); |
| 1019 | } |
| 1020 | } |
| 1021 | else |
| 1022 | { |
| 1023 | return mStencilbufferZero; |
| 1024 | } |
| 1025 | |
| 1026 | return NULL; |
| 1027 | } |
| 1028 | |
| 1029 | Buffer *Context::getArrayBuffer() |
| 1030 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1031 | return getBuffer(mState.arrayBuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | Buffer *Context::getElementArrayBuffer() |
| 1035 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1036 | return getBuffer(mState.elementArrayBuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | Program *Context::getCurrentProgram() |
| 1040 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1041 | return getProgram(mState.currentProgram); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | Texture2D *Context::getTexture2D() |
| 1045 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1046 | if (mState.texture2D == 0) // Special case: 0 refers to different initial textures based on the target |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1047 | { |
| 1048 | return mTexture2DZero; |
| 1049 | } |
| 1050 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1051 | return (Texture2D*)getTexture(mState.texture2D); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | TextureCubeMap *Context::getTextureCubeMap() |
| 1055 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1056 | if (mState.textureCubeMap == 0) // Special case: 0 refers to different initial textures based on the target |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1057 | { |
| 1058 | return mTextureCubeMapZero; |
| 1059 | } |
| 1060 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1061 | return (TextureCubeMap*)getTexture(mState.textureCubeMap); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 1064 | Texture *Context::getSamplerTexture(unsigned int sampler, SamplerType type) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1065 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1066 | GLuint texid = mState.samplerTexture[type][sampler]; |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 1067 | |
| 1068 | if (texid == 0) |
| 1069 | { |
| 1070 | switch (type) |
| 1071 | { |
| 1072 | default: UNREACHABLE(); |
| 1073 | case SAMPLER_2D: return mTexture2DZero; |
| 1074 | case SAMPLER_CUBE: return mTextureCubeMapZero; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | return getTexture(texid); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | Framebuffer *Context::getFramebuffer() |
| 1082 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1083 | return getFramebuffer(mState.framebuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1086 | bool Context::getBooleanv(GLenum pname, GLboolean *params) |
| 1087 | { |
| 1088 | switch (pname) |
| 1089 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1090 | case GL_SHADER_COMPILER: *params = GL_TRUE; break; |
| 1091 | case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break; |
| 1092 | case GL_DEPTH_WRITEMASK: *params = mState.depthMask; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1093 | case GL_COLOR_WRITEMASK: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1094 | params[0] = mState.colorMaskRed; |
| 1095 | params[1] = mState.colorMaskGreen; |
| 1096 | params[2] = mState.colorMaskBlue; |
| 1097 | params[3] = mState.colorMaskAlpha; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1098 | break; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1099 | case GL_CULL_FACE: *params = mState.cullFace; |
| 1100 | case GL_POLYGON_OFFSET_FILL: *params = mState.polygonOffsetFill; |
| 1101 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.sampleAlphaToCoverage; |
| 1102 | case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; |
| 1103 | case GL_SCISSOR_TEST: *params = mState.scissorTest; |
| 1104 | case GL_STENCIL_TEST: *params = mState.stencilTest; |
| 1105 | case GL_DEPTH_TEST: *params = mState.depthTest; |
| 1106 | case GL_BLEND: *params = mState.blend; |
| 1107 | case GL_DITHER: *params = mState.dither; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1108 | default: |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
| 1112 | return true; |
| 1113 | } |
| 1114 | |
| 1115 | bool Context::getFloatv(GLenum pname, GLfloat *params) |
| 1116 | { |
| 1117 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1118 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1119 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1120 | // case, this should make no difference to the calling application. |
| 1121 | switch (pname) |
| 1122 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1123 | case GL_LINE_WIDTH: *params = mState.lineWidth; break; |
| 1124 | case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break; |
| 1125 | case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break; |
| 1126 | case GL_POLYGON_OFFSET_FACTOR: *params = mState.polygonOffsetFactor; break; |
| 1127 | case GL_POLYGON_OFFSET_UNITS: *params = mState.polygonOffsetUnits; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1128 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1129 | params[0] = gl::ALIASED_LINE_WIDTH_RANGE_MIN; |
| 1130 | params[1] = gl::ALIASED_LINE_WIDTH_RANGE_MAX; |
| 1131 | break; |
| 1132 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1133 | params[0] = gl::ALIASED_POINT_SIZE_RANGE_MIN; |
| 1134 | params[1] = gl::ALIASED_POINT_SIZE_RANGE_MAX; |
| 1135 | break; |
| 1136 | case GL_DEPTH_RANGE: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1137 | params[0] = mState.zNear; |
| 1138 | params[1] = mState.zFar; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1139 | break; |
| 1140 | case GL_COLOR_CLEAR_VALUE: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1141 | params[0] = mState.colorClearValue.red; |
| 1142 | params[1] = mState.colorClearValue.green; |
| 1143 | params[2] = mState.colorClearValue.blue; |
| 1144 | params[3] = mState.colorClearValue.alpha; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1145 | break; |
daniel@transgaming.com | c164135 | 2010-04-26 15:33:36 +0000 | [diff] [blame] | 1146 | case GL_BLEND_COLOR: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1147 | params[0] = mState.blendColor.red; |
| 1148 | params[1] = mState.blendColor.green; |
| 1149 | params[2] = mState.blendColor.blue; |
| 1150 | params[3] = mState.blendColor.alpha; |
daniel@transgaming.com | c164135 | 2010-04-26 15:33:36 +0000 | [diff] [blame] | 1151 | break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1152 | default: |
| 1153 | return false; |
| 1154 | } |
| 1155 | |
| 1156 | return true; |
| 1157 | } |
| 1158 | |
| 1159 | bool Context::getIntegerv(GLenum pname, GLint *params) |
| 1160 | { |
| 1161 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1162 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1163 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1164 | // case, this should make no difference to the calling application. You may find it in |
| 1165 | // Context::getFloatv. |
| 1166 | switch (pname) |
| 1167 | { |
| 1168 | case GL_MAX_VERTEX_ATTRIBS: *params = gl::MAX_VERTEX_ATTRIBS; break; |
| 1169 | case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = gl::MAX_VERTEX_UNIFORM_VECTORS; break; |
| 1170 | case GL_MAX_VARYING_VECTORS: *params = gl::MAX_VARYING_VECTORS; break; |
| 1171 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = gl::MAX_COMBINED_TEXTURE_IMAGE_UNITS; break; |
| 1172 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS; break; |
| 1173 | case GL_MAX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_TEXTURE_IMAGE_UNITS; break; |
| 1174 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = gl::MAX_FRAGMENT_UNIFORM_VECTORS; break; |
| 1175 | case GL_MAX_RENDERBUFFER_SIZE: *params = gl::MAX_RENDERBUFFER_SIZE; break; |
| 1176 | case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break; |
| 1177 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: *params = 0; break; |
| 1178 | case GL_COMPRESSED_TEXTURE_FORMATS: /* no compressed texture formats are supported */ break; |
| 1179 | case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ break; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1180 | case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer; break; |
| 1181 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = mState.elementArrayBuffer; break; |
| 1182 | case GL_FRAMEBUFFER_BINDING: *params = mState.framebuffer; break; |
| 1183 | case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer; break; |
| 1184 | case GL_CURRENT_PROGRAM: *params = mState.currentProgram; break; |
| 1185 | case GL_PACK_ALIGNMENT: *params = mState.packAlignment; break; |
| 1186 | case GL_UNPACK_ALIGNMENT: *params = mState.unpackAlignment; break; |
| 1187 | case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; break; |
| 1188 | case GL_ACTIVE_TEXTURE: *params = mState.activeSampler; break; |
| 1189 | case GL_STENCIL_FUNC: *params = mState.stencilFunc; break; |
| 1190 | case GL_STENCIL_REF: *params = mState.stencilRef; break; |
| 1191 | case GL_STENCIL_VALUE_MASK: *params = mState.stencilMask; break; |
| 1192 | case GL_STENCIL_BACK_FUNC: *params = mState.stencilBackFunc; break; |
| 1193 | case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; break; |
| 1194 | case GL_STENCIL_BACK_VALUE_MASK: *params = mState.stencilBackMask; break; |
| 1195 | case GL_STENCIL_FAIL: *params = mState.stencilFail; break; |
| 1196 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.stencilPassDepthFail; break; |
| 1197 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.stencilPassDepthPass; break; |
| 1198 | case GL_STENCIL_BACK_FAIL: *params = mState.stencilBackFail; break; |
| 1199 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.stencilBackPassDepthFail; break; |
| 1200 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.stencilBackPassDepthPass; break; |
| 1201 | case GL_DEPTH_FUNC: *params = mState.depthFunc; break; |
| 1202 | case GL_BLEND_SRC_RGB: *params = mState.sourceBlendRGB; break; |
| 1203 | case GL_BLEND_SRC_ALPHA: *params = mState.sourceBlendAlpha; break; |
| 1204 | case GL_BLEND_DST_RGB: *params = mState.destBlendRGB; break; |
| 1205 | case GL_BLEND_DST_ALPHA: *params = mState.destBlendAlpha; break; |
| 1206 | case GL_BLEND_EQUATION_RGB: *params = mState.blendEquationRGB; break; |
| 1207 | case GL_BLEND_EQUATION_ALPHA: *params = mState.blendEquationAlpha; break; |
| 1208 | case GL_STENCIL_WRITEMASK: *params = mState.stencilWritemask; break; |
| 1209 | case GL_STENCIL_BACK_WRITEMASK: *params = mState.stencilBackWritemask; break; |
| 1210 | case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1211 | case GL_SUBPIXEL_BITS: *params = 4; break; |
| 1212 | case GL_MAX_TEXTURE_SIZE: *params = gl::MAX_TEXTURE_SIZE; break; |
| 1213 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = gl::MAX_CUBE_MAP_TEXTURE_SIZE; break; |
| 1214 | case GL_SAMPLE_BUFFERS: *params = 0; break; |
| 1215 | case GL_SAMPLES: *params = 0; break; |
| 1216 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: *params = gl::IMPLEMENTATION_COLOR_READ_TYPE; break; |
| 1217 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: *params = gl::IMPLEMENTATION_COLOR_READ_FORMAT; break; |
| 1218 | case GL_MAX_VIEWPORT_DIMS: |
| 1219 | { |
| 1220 | int maxDimension = std::max((int)gl::MAX_RENDERBUFFER_SIZE, (int)gl::MAX_TEXTURE_SIZE); |
| 1221 | params[0] = maxDimension; |
| 1222 | params[1] = maxDimension; |
| 1223 | } |
| 1224 | break; |
| 1225 | case GL_VIEWPORT: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1226 | params[0] = mState.viewportX; |
| 1227 | params[1] = mState.viewportY; |
| 1228 | params[2] = mState.viewportWidth; |
| 1229 | params[3] = mState.viewportHeight; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1230 | break; |
| 1231 | case GL_SCISSOR_BOX: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1232 | params[0] = mState.scissorX; |
| 1233 | params[1] = mState.scissorY; |
| 1234 | params[2] = mState.scissorWidth; |
| 1235 | params[3] = mState.scissorHeight; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1236 | break; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1237 | case GL_CULL_FACE_MODE: *params = mState.cullMode; break; |
| 1238 | case GL_FRONT_FACE: *params = mState.frontFace; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1239 | case GL_RED_BITS: |
| 1240 | case GL_GREEN_BITS: |
| 1241 | case GL_BLUE_BITS: |
| 1242 | case GL_ALPHA_BITS: |
| 1243 | { |
| 1244 | gl::Framebuffer *framebuffer = getFramebuffer(); |
| 1245 | gl::Colorbuffer *colorbuffer = framebuffer->getColorbuffer(); |
| 1246 | |
| 1247 | if (colorbuffer) |
| 1248 | { |
| 1249 | switch (pname) |
| 1250 | { |
| 1251 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1252 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1253 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1254 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1255 | } |
| 1256 | } |
| 1257 | else |
| 1258 | { |
| 1259 | *params = 0; |
| 1260 | } |
| 1261 | } |
| 1262 | break; |
| 1263 | case GL_DEPTH_BITS: |
| 1264 | { |
| 1265 | gl::Framebuffer *framebuffer = getFramebuffer(); |
| 1266 | gl::Depthbuffer *depthbuffer = framebuffer->getDepthbuffer(); |
| 1267 | |
| 1268 | if (depthbuffer) |
| 1269 | { |
| 1270 | *params = depthbuffer->getDepthSize(); |
| 1271 | } |
| 1272 | else |
| 1273 | { |
| 1274 | *params = 0; |
| 1275 | } |
| 1276 | } |
| 1277 | break; |
| 1278 | case GL_STENCIL_BITS: |
| 1279 | { |
| 1280 | gl::Framebuffer *framebuffer = getFramebuffer(); |
| 1281 | gl::Stencilbuffer *stencilbuffer = framebuffer->getStencilbuffer(); |
| 1282 | |
| 1283 | if (stencilbuffer) |
| 1284 | { |
| 1285 | *params = stencilbuffer->getStencilSize(); |
| 1286 | } |
| 1287 | else |
| 1288 | { |
| 1289 | *params = 0; |
| 1290 | } |
| 1291 | } |
| 1292 | break; |
| 1293 | case GL_TEXTURE_BINDING_2D: |
| 1294 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1295 | if (mState.activeSampler < 0 || mState.activeSampler > gl::MAX_TEXTURE_IMAGE_UNITS - 1) |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1296 | { |
| 1297 | error(GL_INVALID_OPERATION); |
| 1298 | return false; |
| 1299 | } |
| 1300 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1301 | *params = mState.samplerTexture[SAMPLER_2D][mState.activeSampler]; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1302 | } |
| 1303 | break; |
| 1304 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1305 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1306 | if (mState.activeSampler < 0 || mState.activeSampler > gl::MAX_TEXTURE_IMAGE_UNITS - 1) |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1307 | { |
| 1308 | error(GL_INVALID_OPERATION); |
| 1309 | return false; |
| 1310 | } |
| 1311 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1312 | *params = mState.samplerTexture[SAMPLER_CUBE][mState.activeSampler]; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1313 | } |
| 1314 | break; |
| 1315 | default: |
| 1316 | return false; |
| 1317 | } |
| 1318 | |
| 1319 | return true; |
| 1320 | } |
| 1321 | |
| 1322 | bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) |
| 1323 | { |
| 1324 | // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation |
| 1325 | // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due |
| 1326 | // to the fact that it is stored internally as a float, and so would require conversion |
| 1327 | // if returned from Context::getIntegerv. Since this conversion is already implemented |
| 1328 | // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we |
| 1329 | // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling |
| 1330 | // application. |
| 1331 | switch (pname) |
| 1332 | { |
| 1333 | case GL_COMPRESSED_TEXTURE_FORMATS: /* no compressed texture formats are supported */ |
| 1334 | case GL_SHADER_BINARY_FORMATS: |
| 1335 | { |
| 1336 | *type = GL_INT; |
| 1337 | *numParams = 0; |
| 1338 | } |
| 1339 | break; |
| 1340 | case GL_MAX_VERTEX_ATTRIBS: |
| 1341 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 1342 | case GL_MAX_VARYING_VECTORS: |
| 1343 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: |
| 1344 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: |
| 1345 | case GL_MAX_TEXTURE_IMAGE_UNITS: |
| 1346 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 1347 | case GL_MAX_RENDERBUFFER_SIZE: |
| 1348 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 1349 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 1350 | case GL_ARRAY_BUFFER_BINDING: |
| 1351 | case GL_FRAMEBUFFER_BINDING: |
| 1352 | case GL_RENDERBUFFER_BINDING: |
| 1353 | case GL_CURRENT_PROGRAM: |
| 1354 | case GL_PACK_ALIGNMENT: |
| 1355 | case GL_UNPACK_ALIGNMENT: |
| 1356 | case GL_GENERATE_MIPMAP_HINT: |
| 1357 | case GL_RED_BITS: |
| 1358 | case GL_GREEN_BITS: |
| 1359 | case GL_BLUE_BITS: |
| 1360 | case GL_ALPHA_BITS: |
| 1361 | case GL_DEPTH_BITS: |
| 1362 | case GL_STENCIL_BITS: |
| 1363 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 1364 | case GL_CULL_FACE_MODE: |
| 1365 | case GL_FRONT_FACE: |
| 1366 | case GL_ACTIVE_TEXTURE: |
| 1367 | case GL_STENCIL_FUNC: |
| 1368 | case GL_STENCIL_VALUE_MASK: |
| 1369 | case GL_STENCIL_REF: |
| 1370 | case GL_STENCIL_FAIL: |
| 1371 | case GL_STENCIL_PASS_DEPTH_FAIL: |
| 1372 | case GL_STENCIL_PASS_DEPTH_PASS: |
| 1373 | case GL_STENCIL_BACK_FUNC: |
| 1374 | case GL_STENCIL_BACK_VALUE_MASK: |
| 1375 | case GL_STENCIL_BACK_REF: |
| 1376 | case GL_STENCIL_BACK_FAIL: |
| 1377 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: |
| 1378 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: |
| 1379 | case GL_DEPTH_FUNC: |
| 1380 | case GL_BLEND_SRC_RGB: |
| 1381 | case GL_BLEND_SRC_ALPHA: |
| 1382 | case GL_BLEND_DST_RGB: |
| 1383 | case GL_BLEND_DST_ALPHA: |
| 1384 | case GL_BLEND_EQUATION_RGB: |
| 1385 | case GL_BLEND_EQUATION_ALPHA: |
| 1386 | case GL_STENCIL_WRITEMASK: |
| 1387 | case GL_STENCIL_BACK_WRITEMASK: |
| 1388 | case GL_STENCIL_CLEAR_VALUE: |
| 1389 | case GL_SUBPIXEL_BITS: |
| 1390 | case GL_MAX_TEXTURE_SIZE: |
| 1391 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 1392 | case GL_SAMPLE_BUFFERS: |
| 1393 | case GL_SAMPLES: |
| 1394 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1395 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1396 | case GL_TEXTURE_BINDING_2D: |
| 1397 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1398 | { |
| 1399 | *type = GL_INT; |
| 1400 | *numParams = 1; |
| 1401 | } |
| 1402 | break; |
| 1403 | case GL_MAX_VIEWPORT_DIMS: |
| 1404 | { |
| 1405 | *type = GL_INT; |
| 1406 | *numParams = 2; |
| 1407 | } |
| 1408 | break; |
| 1409 | case GL_VIEWPORT: |
| 1410 | case GL_SCISSOR_BOX: |
| 1411 | { |
| 1412 | *type = GL_INT; |
| 1413 | *numParams = 4; |
| 1414 | } |
| 1415 | break; |
| 1416 | case GL_SHADER_COMPILER: |
| 1417 | case GL_SAMPLE_COVERAGE_INVERT: |
| 1418 | case GL_DEPTH_WRITEMASK: |
daniel@transgaming.com | 79f6677 | 2010-04-13 03:26:09 +0000 | [diff] [blame] | 1419 | case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled, |
| 1420 | case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries. |
| 1421 | case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as bool-natural |
| 1422 | case GL_SAMPLE_COVERAGE: |
| 1423 | case GL_SCISSOR_TEST: |
| 1424 | case GL_STENCIL_TEST: |
| 1425 | case GL_DEPTH_TEST: |
| 1426 | case GL_BLEND: |
| 1427 | case GL_DITHER: |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1428 | { |
| 1429 | *type = GL_BOOL; |
| 1430 | *numParams = 1; |
| 1431 | } |
| 1432 | break; |
| 1433 | case GL_COLOR_WRITEMASK: |
| 1434 | { |
| 1435 | *type = GL_BOOL; |
| 1436 | *numParams = 4; |
| 1437 | } |
| 1438 | break; |
| 1439 | case GL_POLYGON_OFFSET_FACTOR: |
| 1440 | case GL_POLYGON_OFFSET_UNITS: |
| 1441 | case GL_SAMPLE_COVERAGE_VALUE: |
| 1442 | case GL_DEPTH_CLEAR_VALUE: |
| 1443 | case GL_LINE_WIDTH: |
| 1444 | { |
| 1445 | *type = GL_FLOAT; |
| 1446 | *numParams = 1; |
| 1447 | } |
| 1448 | break; |
| 1449 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1450 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1451 | case GL_DEPTH_RANGE: |
| 1452 | { |
| 1453 | *type = GL_FLOAT; |
| 1454 | *numParams = 2; |
| 1455 | } |
| 1456 | break; |
| 1457 | case GL_COLOR_CLEAR_VALUE: |
daniel@transgaming.com | c164135 | 2010-04-26 15:33:36 +0000 | [diff] [blame] | 1458 | case GL_BLEND_COLOR: |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1459 | { |
| 1460 | *type = GL_FLOAT; |
| 1461 | *numParams = 4; |
| 1462 | } |
| 1463 | break; |
| 1464 | default: |
| 1465 | return false; |
| 1466 | } |
| 1467 | |
| 1468 | return true; |
| 1469 | } |
| 1470 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1471 | // Applies the render target surface, depth stencil surface, viewport rectangle and |
| 1472 | // scissor rectangle to the Direct3D 9 device |
| 1473 | bool Context::applyRenderTarget(bool ignoreViewport) |
| 1474 | { |
| 1475 | IDirect3DDevice9 *device = getDevice(); |
| 1476 | Framebuffer *framebufferObject = getFramebuffer(); |
| 1477 | |
| 1478 | if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1479 | { |
| 1480 | return false; |
| 1481 | } |
| 1482 | |
| 1483 | IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); |
| 1484 | IDirect3DSurface9 *depthStencil = framebufferObject->getDepthStencil(); |
| 1485 | |
| 1486 | device->SetRenderTarget(0, renderTarget); |
| 1487 | device->SetDepthStencilSurface(depthStencil); |
| 1488 | |
| 1489 | D3DVIEWPORT9 viewport; |
| 1490 | D3DSURFACE_DESC desc; |
| 1491 | renderTarget->GetDesc(&desc); |
| 1492 | |
| 1493 | if (ignoreViewport) |
| 1494 | { |
| 1495 | viewport.X = 0; |
| 1496 | viewport.Y = 0; |
| 1497 | viewport.Width = desc.Width; |
| 1498 | viewport.Height = desc.Height; |
| 1499 | viewport.MinZ = 0.0f; |
| 1500 | viewport.MaxZ = 1.0f; |
| 1501 | } |
| 1502 | else |
| 1503 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1504 | viewport.X = std::max(mState.viewportX, 0); |
| 1505 | viewport.Y = std::max(mState.viewportY, 0); |
| 1506 | viewport.Width = std::min(mState.viewportWidth, (int)desc.Width - (int)viewport.X); |
| 1507 | viewport.Height = std::min(mState.viewportHeight, (int)desc.Height - (int)viewport.Y); |
| 1508 | viewport.MinZ = clamp01(mState.zNear); |
| 1509 | viewport.MaxZ = clamp01(mState.zFar); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | device->SetViewport(&viewport); |
| 1513 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1514 | if (mState.scissorTest) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1515 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1516 | RECT rect = {mState.scissorX, |
| 1517 | mState.scissorY, |
| 1518 | mState.scissorX + mState.scissorWidth, |
| 1519 | mState.scissorY + mState.scissorHeight}; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1520 | |
| 1521 | device->SetScissorRect(&rect); |
| 1522 | device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); |
| 1523 | } |
| 1524 | else |
| 1525 | { |
| 1526 | device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); |
| 1527 | } |
| 1528 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1529 | if (mState.currentProgram) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1530 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1531 | Program *programObject = getCurrentProgram(); |
| 1532 | |
daniel@transgaming.com | 09fbfef | 2010-04-22 13:35:31 +0000 | [diff] [blame] | 1533 | GLint halfPixelSize = programObject->getUniformLocation("dx_HalfPixelSize"); |
daniel@transgaming.com | 8ee00ea | 2010-04-29 03:38:47 +0000 | [diff] [blame] | 1534 | GLfloat xy[2] = {1.0f / viewport.Width, 1.0f / viewport.Height}; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1535 | programObject->setUniform2fv(halfPixelSize, 1, (GLfloat*)&xy); |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 1536 | |
daniel@transgaming.com | 09fbfef | 2010-04-22 13:35:31 +0000 | [diff] [blame] | 1537 | GLint window = programObject->getUniformLocation("dx_Window"); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1538 | GLfloat whxy[4] = {mState.viewportWidth / 2.0f, mState.viewportHeight / 2.0f, |
| 1539 | (float)mState.viewportX + mState.viewportWidth / 2.0f, |
| 1540 | (float)mState.viewportY + mState.viewportHeight / 2.0f}; |
daniel@transgaming.com | 9b5f544 | 2010-03-16 05:43:55 +0000 | [diff] [blame] | 1541 | programObject->setUniform4fv(window, 1, (GLfloat*)&whxy); |
| 1542 | |
daniel@transgaming.com | 09fbfef | 2010-04-22 13:35:31 +0000 | [diff] [blame] | 1543 | GLint depth = programObject->getUniformLocation("dx_Depth"); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1544 | GLfloat dz[2] = {(mState.zFar - mState.zNear) / 2.0f, (mState.zNear + mState.zFar) / 2.0f}; |
daniel@transgaming.com | 9b5f544 | 2010-03-16 05:43:55 +0000 | [diff] [blame] | 1545 | programObject->setUniform2fv(depth, 1, (GLfloat*)&dz); |
| 1546 | |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1547 | GLint near = programObject->getUniformLocation("gl_DepthRange.near"); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1548 | programObject->setUniform1fv(near, 1, &mState.zNear); |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 1549 | |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1550 | GLint far = programObject->getUniformLocation("gl_DepthRange.far"); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1551 | programObject->setUniform1fv(far, 1, &mState.zFar); |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 1552 | |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1553 | GLint diff = programObject->getUniformLocation("gl_DepthRange.diff"); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1554 | GLfloat zDiff = mState.zFar - mState.zNear; |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 1555 | programObject->setUniform1fv(diff, 1, &zDiff); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | return true; |
| 1559 | } |
| 1560 | |
| 1561 | // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 1562 | void Context::applyState(GLenum drawMode) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1563 | { |
| 1564 | IDirect3DDevice9 *device = getDevice(); |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1565 | Program *programObject = getCurrentProgram(); |
| 1566 | |
daniel@transgaming.com | 09fbfef | 2010-04-22 13:35:31 +0000 | [diff] [blame] | 1567 | GLint frontCCW = programObject->getUniformLocation("dx_FrontCCW"); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1568 | GLint ccw = (mState.frontFace == GL_CCW); |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1569 | programObject->setUniform1iv(frontCCW, 1, &ccw); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1570 | |
daniel@transgaming.com | 09fbfef | 2010-04-22 13:35:31 +0000 | [diff] [blame] | 1571 | GLint pointsOrLines = programObject->getUniformLocation("dx_PointsOrLines"); |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 1572 | GLint alwaysFront = !isTriangleMode(drawMode); |
| 1573 | programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront); |
| 1574 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1575 | if (mState.cullFace) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1576 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1577 | device->SetRenderState(D3DRS_CULLMODE, es2dx::ConvertCullMode(mState.cullMode, mState.frontFace)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1578 | } |
| 1579 | else |
| 1580 | { |
| 1581 | device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 1582 | } |
| 1583 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1584 | if (mState.depthTest) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1585 | { |
| 1586 | device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1587 | device->SetRenderState(D3DRS_ZFUNC, es2dx::ConvertComparison(mState.depthFunc)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1588 | } |
| 1589 | else |
| 1590 | { |
| 1591 | device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); |
| 1592 | } |
| 1593 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1594 | if (mState.blend) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1595 | { |
| 1596 | device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
| 1597 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1598 | if (mState.sourceBlendRGB != GL_CONSTANT_ALPHA && mState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && |
| 1599 | mState.destBlendRGB != GL_CONSTANT_ALPHA && mState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1600 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1601 | device->SetRenderState(D3DRS_BLENDFACTOR, es2dx::ConvertColor(mState.blendColor)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1602 | } |
| 1603 | else |
| 1604 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1605 | device->SetRenderState(D3DRS_BLENDFACTOR, D3DCOLOR_RGBA(unorm<8>(mState.blendColor.alpha), |
| 1606 | unorm<8>(mState.blendColor.alpha), |
| 1607 | unorm<8>(mState.blendColor.alpha), |
| 1608 | unorm<8>(mState.blendColor.alpha))); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1611 | device->SetRenderState(D3DRS_SRCBLEND, es2dx::ConvertBlendFunc(mState.sourceBlendRGB)); |
| 1612 | device->SetRenderState(D3DRS_DESTBLEND, es2dx::ConvertBlendFunc(mState.destBlendRGB)); |
| 1613 | device->SetRenderState(D3DRS_BLENDOP, es2dx::ConvertBlendOp(mState.blendEquationRGB)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1614 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1615 | if (mState.sourceBlendRGB != mState.sourceBlendAlpha || |
| 1616 | mState.destBlendRGB != mState.destBlendAlpha || |
| 1617 | mState.blendEquationRGB != mState.blendEquationAlpha) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1618 | { |
| 1619 | device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 1620 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1621 | device->SetRenderState(D3DRS_SRCBLENDALPHA, es2dx::ConvertBlendFunc(mState.sourceBlendAlpha)); |
| 1622 | device->SetRenderState(D3DRS_DESTBLENDALPHA, es2dx::ConvertBlendFunc(mState.destBlendAlpha)); |
| 1623 | device->SetRenderState(D3DRS_BLENDOPALPHA, es2dx::ConvertBlendOp(mState.blendEquationAlpha)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1624 | |
| 1625 | } |
| 1626 | else |
| 1627 | { |
| 1628 | device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE); |
| 1629 | } |
| 1630 | } |
| 1631 | else |
| 1632 | { |
| 1633 | device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 1634 | } |
| 1635 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1636 | if (mState.stencilTest) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1637 | { |
| 1638 | device->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 1639 | device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE); |
| 1640 | |
| 1641 | // FIXME: Unsupported by D3D9 |
| 1642 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF; |
| 1643 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK; |
| 1644 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1645 | if (mState.stencilWritemask != mState.stencilBackWritemask || |
| 1646 | mState.stencilRef != mState.stencilBackRef || |
| 1647 | mState.stencilMask != mState.stencilBackMask) |
daniel@transgaming.com | 1436e26 | 2010-03-17 03:58:56 +0000 | [diff] [blame] | 1648 | { |
| 1649 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL."); |
| 1650 | return error(GL_INVALID_OPERATION); |
| 1651 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1652 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1653 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask); |
| 1654 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, |
| 1655 | es2dx::ConvertComparison(mState.stencilFunc)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1656 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1657 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, mState.stencilRef); // FIXME: Clamp to range |
| 1658 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilMask); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1659 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1660 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, |
| 1661 | es2dx::ConvertStencilOp(mState.stencilFail)); |
| 1662 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, |
| 1663 | es2dx::ConvertStencilOp(mState.stencilPassDepthFail)); |
| 1664 | device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, |
| 1665 | es2dx::ConvertStencilOp(mState.stencilPassDepthPass)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1666 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1667 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilBackWritemask); |
| 1668 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, |
| 1669 | es2dx::ConvertComparison(mState.stencilBackFunc)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1670 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1671 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, mState.stencilBackRef); // FIXME: Clamp to range |
| 1672 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilBackMask); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1673 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1674 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, |
| 1675 | es2dx::ConvertStencilOp(mState.stencilBackFail)); |
| 1676 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, |
| 1677 | es2dx::ConvertStencilOp(mState.stencilBackPassDepthFail)); |
| 1678 | device->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, |
| 1679 | es2dx::ConvertStencilOp(mState.stencilBackPassDepthPass)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1680 | } |
| 1681 | else |
| 1682 | { |
| 1683 | device->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 1684 | } |
| 1685 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1686 | device->SetRenderState(D3DRS_COLORWRITEENABLE, es2dx::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, |
| 1687 | mState.colorMaskBlue, mState.colorMaskAlpha)); |
| 1688 | device->SetRenderState(D3DRS_ZWRITEENABLE, mState.depthMask ? TRUE : FALSE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1689 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1690 | if (mState.polygonOffsetFill) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1691 | { |
daniel@transgaming.com | aede630 | 2010-04-29 03:35:48 +0000 | [diff] [blame] | 1692 | gl::Depthbuffer *depthbuffer = getFramebuffer()->getDepthbuffer(); |
| 1693 | if (depthbuffer) |
| 1694 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1695 | device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor)); |
| 1696 | float depthBias = ldexp(mState.polygonOffsetUnits, -(int)(depthbuffer->getDepthSize())); |
daniel@transgaming.com | aede630 | 2010-04-29 03:35:48 +0000 | [diff] [blame] | 1697 | device->SetRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&depthBias)); |
| 1698 | } |
| 1699 | } |
| 1700 | else |
| 1701 | { |
| 1702 | device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, 0); |
| 1703 | device->SetRenderState(D3DRS_DEPTHBIAS, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
daniel@transgaming.com | a87bdf5 | 2010-04-29 03:38:55 +0000 | [diff] [blame] | 1706 | if (mConfig->mMultiSample != 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1707 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1708 | if (mState.sampleAlphaToCoverage) |
daniel@transgaming.com | a87bdf5 | 2010-04-29 03:38:55 +0000 | [diff] [blame] | 1709 | { |
| 1710 | FIXME("Sample alpha to coverage is unimplemented."); |
| 1711 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1712 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1713 | if (mState.sampleCoverage) |
daniel@transgaming.com | a87bdf5 | 2010-04-29 03:38:55 +0000 | [diff] [blame] | 1714 | { |
| 1715 | FIXME("Sample coverage is unimplemented."); |
| 1716 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1719 | device->SetRenderState(D3DRS_DITHERENABLE, mState.dither ? TRUE : FALSE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 1722 | // Fill in the semanticIndex field of the array of TranslatedAttributes based on the active GLSL program. |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1723 | void Context::lookupAttributeMapping(TranslatedAttribute *attributes) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1724 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1725 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1726 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1727 | if (attributes[i].enabled) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1728 | { |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 1729 | attributes[i].semanticIndex = getCurrentProgram()->getSemanticIndex(i); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1730 | } |
| 1731 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1732 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1733 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1734 | // The indices parameter to glDrawElements can have two interpretations: |
| 1735 | // - as a pointer into client memory |
| 1736 | // - as an offset into the current GL_ELEMENT_ARRAY_BUFFER buffer |
| 1737 | // Handle these cases here and return a pointer to the index data. |
| 1738 | const Index *Context::adjustIndexPointer(const void *indices) |
| 1739 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1740 | if (mState.elementArrayBuffer) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1741 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1742 | Buffer *buffer = getBuffer(mState.elementArrayBuffer); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1743 | return reinterpret_cast<const Index*>(static_cast<unsigned char*>(buffer->data()) + reinterpret_cast<GLsizei>(indices)); |
| 1744 | } |
| 1745 | else |
| 1746 | { |
| 1747 | return static_cast<const Index*>(indices); |
| 1748 | } |
| 1749 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1750 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1751 | void Context::applyVertexBuffer(GLint first, GLsizei count) |
| 1752 | { |
| 1753 | TranslatedAttribute translated[MAX_VERTEX_ATTRIBS]; |
| 1754 | |
| 1755 | mVertexDataManager->preRenderValidate(first, count, translated); |
| 1756 | |
| 1757 | lookupAttributeMapping(translated); |
| 1758 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1759 | mBufferBackEnd->setupAttributesPreDraw(translated); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1762 | void Context::applyVertexBuffer(const TranslatedIndexData &indexInfo) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1763 | { |
| 1764 | TranslatedAttribute translated[MAX_VERTEX_ATTRIBS]; |
| 1765 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1766 | mVertexDataManager->preRenderValidate(indexInfo, translated); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1767 | |
| 1768 | lookupAttributeMapping(translated); |
| 1769 | |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1770 | mBufferBackEnd->setupAttributesPreDraw(translated); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | // Applies the indices and element array bindings to the Direct3D 9 device |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1774 | TranslatedIndexData Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1775 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1776 | TranslatedIndexData indexInfo = mIndexDataManager->preRenderValidate(mode, type, count, getBuffer(mState.elementArrayBuffer), indices); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 1777 | mBufferBackEnd->setupIndicesPreDraw(indexInfo); |
| 1778 | return indexInfo; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | // Applies the shaders and shader constants to the Direct3D 9 device |
| 1782 | void Context::applyShaders() |
| 1783 | { |
| 1784 | IDirect3DDevice9 *device = getDevice(); |
| 1785 | Program *programObject = getCurrentProgram(); |
| 1786 | IDirect3DVertexShader9 *vertexShader = programObject->getVertexShader(); |
| 1787 | IDirect3DPixelShader9 *pixelShader = programObject->getPixelShader(); |
| 1788 | |
| 1789 | device->SetVertexShader(vertexShader); |
| 1790 | device->SetPixelShader(pixelShader); |
| 1791 | |
| 1792 | programObject->applyUniforms(); |
| 1793 | } |
| 1794 | |
| 1795 | // Applies the textures and sampler states to the Direct3D 9 device |
| 1796 | void Context::applyTextures() |
| 1797 | { |
| 1798 | IDirect3DDevice9 *device = getDevice(); |
| 1799 | Program *programObject = getCurrentProgram(); |
| 1800 | |
| 1801 | for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++) |
| 1802 | { |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 1803 | int textureUnit = programObject->getSamplerMapping(sampler); |
| 1804 | if (textureUnit != -1) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1805 | { |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 1806 | SamplerType textureType = programObject->getSamplerType(sampler); |
| 1807 | |
| 1808 | Texture *texture = getSamplerTexture(textureUnit, textureType); |
| 1809 | |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 1810 | if (texture->isComplete()) |
| 1811 | { |
| 1812 | GLenum wrapS = texture->getWrapS(); |
| 1813 | GLenum wrapT = texture->getWrapT(); |
| 1814 | GLenum minFilter = texture->getMinFilter(); |
| 1815 | GLenum magFilter = texture->getMagFilter(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1816 | |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 1817 | device->SetSamplerState(sampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(wrapS)); |
| 1818 | device->SetSamplerState(sampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(wrapT)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1819 | |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 1820 | device->SetSamplerState(sampler, D3DSAMP_MAGFILTER, es2dx::ConvertMagFilter(magFilter)); |
| 1821 | D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter; |
| 1822 | es2dx::ConvertMinFilter(minFilter, &d3dMinFilter, &d3dMipFilter); |
| 1823 | device->SetSamplerState(sampler, D3DSAMP_MINFILTER, d3dMinFilter); |
| 1824 | device->SetSamplerState(sampler, D3DSAMP_MIPFILTER, d3dMipFilter); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1825 | |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 1826 | device->SetTexture(sampler, texture->getTexture()); |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | device->SetTexture(sampler, getIncompleteTexture(textureType)->getTexture()); |
| 1831 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1832 | } |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 1833 | else |
| 1834 | { |
| 1835 | device->SetTexture(sampler, NULL); |
| 1836 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) |
| 1841 | { |
| 1842 | Framebuffer *framebuffer = getFramebuffer(); |
| 1843 | IDirect3DSurface9 *renderTarget = framebuffer->getRenderTarget(); |
| 1844 | IDirect3DDevice9 *device = getDevice(); |
| 1845 | |
| 1846 | D3DSURFACE_DESC desc; |
| 1847 | renderTarget->GetDesc(&desc); |
| 1848 | |
| 1849 | IDirect3DSurface9 *systemSurface; |
| 1850 | HRESULT result = device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &systemSurface, NULL); |
| 1851 | |
| 1852 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 1853 | { |
| 1854 | return error(GL_OUT_OF_MEMORY); |
| 1855 | } |
| 1856 | |
| 1857 | ASSERT(SUCCEEDED(result)); |
| 1858 | |
| 1859 | if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) |
| 1860 | { |
| 1861 | UNIMPLEMENTED(); // FIXME: Requires resolve using StretchRect into non-multisampled render target |
| 1862 | } |
| 1863 | |
| 1864 | result = device->GetRenderTargetData(renderTarget, systemSurface); |
| 1865 | |
| 1866 | if (result == D3DERR_DRIVERINTERNALERROR) |
| 1867 | { |
| 1868 | systemSurface->Release(); |
| 1869 | |
| 1870 | return error(GL_OUT_OF_MEMORY); |
| 1871 | } |
| 1872 | |
| 1873 | if (FAILED(result)) |
| 1874 | { |
| 1875 | UNREACHABLE(); |
| 1876 | systemSurface->Release(); |
| 1877 | |
| 1878 | return; // No sensible error to generate |
| 1879 | } |
| 1880 | |
| 1881 | D3DLOCKED_RECT lock; |
daniel@transgaming.com | 1697302 | 2010-03-11 19:22:19 +0000 | [diff] [blame] | 1882 | RECT rect = {std::max(x, 0), |
| 1883 | std::max(y, 0), |
| 1884 | std::min(x + width, (int)desc.Width), |
| 1885 | std::min(y + height, (int)desc.Height)}; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1886 | |
| 1887 | result = systemSurface->LockRect(&lock, &rect, D3DLOCK_READONLY); |
| 1888 | |
| 1889 | if (FAILED(result)) |
| 1890 | { |
| 1891 | UNREACHABLE(); |
| 1892 | systemSurface->Release(); |
| 1893 | |
| 1894 | return; // No sensible error to generate |
| 1895 | } |
| 1896 | |
| 1897 | unsigned char *source = (unsigned char*)lock.pBits; |
| 1898 | unsigned char *dest = (unsigned char*)pixels; |
daniel@transgaming.com | afb2395 | 2010-04-13 03:25:54 +0000 | [diff] [blame] | 1899 | unsigned short *dest16 = (unsigned short*)pixels; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1900 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1901 | GLsizei outputPitch = ComputePitch(width, format, type, mState.packAlignment); |
daniel@transgaming.com | 713914b | 2010-05-04 03:35:17 +0000 | [diff] [blame] | 1902 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1903 | for (int j = 0; j < rect.bottom - rect.top; j++) |
| 1904 | { |
| 1905 | for (int i = 0; i < rect.right - rect.left; i++) |
| 1906 | { |
| 1907 | float r; |
| 1908 | float g; |
| 1909 | float b; |
| 1910 | float a; |
| 1911 | |
| 1912 | switch (desc.Format) |
| 1913 | { |
| 1914 | case D3DFMT_R5G6B5: |
| 1915 | { |
| 1916 | unsigned short rgb = *(unsigned short*)(source + 2 * i + j * lock.Pitch); |
| 1917 | |
| 1918 | a = 1.0f; |
| 1919 | b = (rgb & 0x001F) * (1.0f / 0x001F); |
| 1920 | g = (rgb & 0x07E0) * (1.0f / 0x07E0); |
| 1921 | r = (rgb & 0xF800) * (1.0f / 0xF800); |
| 1922 | } |
| 1923 | break; |
| 1924 | case D3DFMT_X1R5G5B5: |
| 1925 | { |
| 1926 | unsigned short xrgb = *(unsigned short*)(source + 2 * i + j * lock.Pitch); |
| 1927 | |
| 1928 | a = 1.0f; |
| 1929 | b = (xrgb & 0x001F) * (1.0f / 0x001F); |
| 1930 | g = (xrgb & 0x03E0) * (1.0f / 0x03E0); |
| 1931 | r = (xrgb & 0x7C00) * (1.0f / 0x7C00); |
| 1932 | } |
| 1933 | break; |
| 1934 | case D3DFMT_A1R5G5B5: |
| 1935 | { |
| 1936 | unsigned short argb = *(unsigned short*)(source + 2 * i + j * lock.Pitch); |
| 1937 | |
| 1938 | a = (argb & 0x8000) ? 1.0f : 0.0f; |
| 1939 | b = (argb & 0x001F) * (1.0f / 0x001F); |
| 1940 | g = (argb & 0x03E0) * (1.0f / 0x03E0); |
| 1941 | r = (argb & 0x7C00) * (1.0f / 0x7C00); |
| 1942 | } |
| 1943 | break; |
| 1944 | case D3DFMT_A8R8G8B8: |
| 1945 | { |
| 1946 | unsigned int argb = *(unsigned int*)(source + 4 * i + j * lock.Pitch); |
| 1947 | |
| 1948 | a = (argb & 0xFF000000) * (1.0f / 0xFF000000); |
| 1949 | b = (argb & 0x000000FF) * (1.0f / 0x000000FF); |
| 1950 | g = (argb & 0x0000FF00) * (1.0f / 0x0000FF00); |
| 1951 | r = (argb & 0x00FF0000) * (1.0f / 0x00FF0000); |
| 1952 | } |
| 1953 | break; |
| 1954 | case D3DFMT_X8R8G8B8: |
| 1955 | { |
| 1956 | unsigned int xrgb = *(unsigned int*)(source + 4 * i + j * lock.Pitch); |
| 1957 | |
| 1958 | a = 1.0f; |
| 1959 | b = (xrgb & 0x000000FF) * (1.0f / 0x000000FF); |
| 1960 | g = (xrgb & 0x0000FF00) * (1.0f / 0x0000FF00); |
| 1961 | r = (xrgb & 0x00FF0000) * (1.0f / 0x00FF0000); |
| 1962 | } |
| 1963 | break; |
| 1964 | case D3DFMT_A2R10G10B10: |
| 1965 | { |
| 1966 | unsigned int argb = *(unsigned int*)(source + 4 * i + j * lock.Pitch); |
| 1967 | |
| 1968 | a = (argb & 0xC0000000) * (1.0f / 0xC0000000); |
| 1969 | b = (argb & 0x000003FF) * (1.0f / 0x000003FF); |
| 1970 | g = (argb & 0x000FFC00) * (1.0f / 0x000FFC00); |
| 1971 | r = (argb & 0x3FF00000) * (1.0f / 0x3FF00000); |
| 1972 | } |
| 1973 | break; |
| 1974 | default: |
| 1975 | UNIMPLEMENTED(); // FIXME |
| 1976 | UNREACHABLE(); |
| 1977 | } |
| 1978 | |
| 1979 | switch (format) |
| 1980 | { |
| 1981 | case GL_RGBA: |
| 1982 | switch (type) |
| 1983 | { |
| 1984 | case GL_UNSIGNED_BYTE: |
daniel@transgaming.com | 713914b | 2010-05-04 03:35:17 +0000 | [diff] [blame] | 1985 | dest[4 * i + j * outputPitch + 0] = (unsigned char)(255 * r + 0.5f); |
| 1986 | dest[4 * i + j * outputPitch + 1] = (unsigned char)(255 * g + 0.5f); |
| 1987 | dest[4 * i + j * outputPitch + 2] = (unsigned char)(255 * b + 0.5f); |
| 1988 | dest[4 * i + j * outputPitch + 3] = (unsigned char)(255 * a + 0.5f); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1989 | break; |
| 1990 | default: UNREACHABLE(); |
| 1991 | } |
| 1992 | break; |
daniel@transgaming.com | afb2395 | 2010-04-13 03:25:54 +0000 | [diff] [blame] | 1993 | case GL_RGB: // IMPLEMENTATION_COLOR_READ_FORMAT |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1994 | switch (type) |
| 1995 | { |
daniel@transgaming.com | afb2395 | 2010-04-13 03:25:54 +0000 | [diff] [blame] | 1996 | case GL_UNSIGNED_SHORT_5_6_5: // IMPLEMENTATION_COLOR_READ_TYPE |
daniel@transgaming.com | 713914b | 2010-05-04 03:35:17 +0000 | [diff] [blame] | 1997 | dest16[i + j * outputPitch / sizeof(unsigned short)] = |
| 1998 | ((unsigned short)(31 * b + 0.5f) << 0) | |
| 1999 | ((unsigned short)(63 * g + 0.5f) << 5) | |
| 2000 | ((unsigned short)(31 * r + 0.5f) << 11); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2001 | break; |
| 2002 | default: UNREACHABLE(); |
| 2003 | } |
| 2004 | break; |
| 2005 | default: UNREACHABLE(); |
| 2006 | } |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | systemSurface->UnlockRect(); |
| 2011 | |
| 2012 | systemSurface->Release(); |
| 2013 | } |
| 2014 | |
| 2015 | void Context::clear(GLbitfield mask) |
| 2016 | { |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2017 | egl::Display *display = getDisplay(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2018 | IDirect3DDevice9 *device = getDevice(); |
| 2019 | DWORD flags = 0; |
| 2020 | |
| 2021 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2022 | { |
| 2023 | mask &= ~GL_COLOR_BUFFER_BIT; |
| 2024 | flags |= D3DCLEAR_TARGET; |
| 2025 | } |
| 2026 | |
| 2027 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 2028 | { |
| 2029 | mask &= ~GL_DEPTH_BUFFER_BIT; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2030 | if (mState.depthMask) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2031 | { |
| 2032 | flags |= D3DCLEAR_ZBUFFER; |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | Framebuffer *framebufferObject = getFramebuffer(); |
| 2037 | IDirect3DSurface9 *depthStencil = framebufferObject->getDepthStencil(); |
| 2038 | |
| 2039 | GLuint stencilUnmasked = 0x0; |
| 2040 | |
| 2041 | if ((mask & GL_STENCIL_BUFFER_BIT) && depthStencil) |
| 2042 | { |
| 2043 | D3DSURFACE_DESC desc; |
| 2044 | depthStencil->GetDesc(&desc); |
| 2045 | |
| 2046 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 2047 | unsigned int stencilSize = es2dx::GetStencilSize(desc.Format); |
| 2048 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 2049 | |
| 2050 | if (stencilUnmasked != 0x0) |
| 2051 | { |
| 2052 | flags |= D3DCLEAR_STENCIL; |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | if (mask != 0) |
| 2057 | { |
| 2058 | return error(GL_INVALID_VALUE); |
| 2059 | } |
| 2060 | |
| 2061 | applyRenderTarget(true); // Clips the clear to the scissor rectangle but not the viewport |
| 2062 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2063 | D3DCOLOR color = D3DCOLOR_ARGB(unorm<8>(mState.colorClearValue.alpha), |
| 2064 | unorm<8>(mState.colorClearValue.red), |
| 2065 | unorm<8>(mState.colorClearValue.green), |
| 2066 | unorm<8>(mState.colorClearValue.blue)); |
| 2067 | float depth = clamp01(mState.depthClearValue); |
| 2068 | int stencil = mState.stencilClearValue & 0x000000FF; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2069 | |
| 2070 | IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); |
| 2071 | |
| 2072 | D3DSURFACE_DESC desc; |
| 2073 | renderTarget->GetDesc(&desc); |
| 2074 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2075 | bool alphaUnmasked = (es2dx::GetAlphaSize(desc.Format) == 0) || mState.colorMaskAlpha; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2076 | |
| 2077 | const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) && |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2078 | (mState.stencilWritemask & stencilUnmasked) != stencilUnmasked; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2079 | const bool needMaskedColorClear = (flags & D3DCLEAR_TARGET) && |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2080 | !(mState.colorMaskRed && mState.colorMaskGreen && |
| 2081 | mState.colorMaskBlue && alphaUnmasked); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2082 | |
| 2083 | if (needMaskedColorClear || needMaskedStencilClear) |
| 2084 | { |
| 2085 | device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 2086 | device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 2087 | device->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 2088 | device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 2089 | device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 2090 | device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 2091 | device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 2092 | device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 2093 | |
| 2094 | if (flags & D3DCLEAR_TARGET) |
| 2095 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2096 | device->SetRenderState(D3DRS_COLORWRITEENABLE, (mState.colorMaskRed ? D3DCOLORWRITEENABLE_RED : 0) | |
| 2097 | (mState.colorMaskGreen ? D3DCOLORWRITEENABLE_GREEN : 0) | |
| 2098 | (mState.colorMaskBlue ? D3DCOLORWRITEENABLE_BLUE : 0) | |
| 2099 | (mState.colorMaskAlpha ? D3DCOLORWRITEENABLE_ALPHA : 0)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2100 | } |
| 2101 | else |
| 2102 | { |
| 2103 | device->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 2104 | } |
| 2105 | |
| 2106 | if (stencilUnmasked != 0x0 && (flags & D3DCLEAR_STENCIL)) |
| 2107 | { |
| 2108 | device->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 2109 | device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); |
| 2110 | device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); |
| 2111 | device->SetRenderState(D3DRS_STENCILREF, stencil); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2112 | device->SetRenderState(D3DRS_STENCILWRITEMASK, mState.stencilWritemask); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2113 | device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2114 | device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); |
| 2115 | device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); |
| 2116 | } |
| 2117 | else |
| 2118 | { |
| 2119 | device->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 2120 | } |
| 2121 | |
| 2122 | device->SetPixelShader(NULL); |
| 2123 | device->SetVertexShader(NULL); |
| 2124 | device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); |
| 2125 | |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2126 | struct Vertex |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2127 | { |
| 2128 | float x, y, z, w; |
| 2129 | D3DCOLOR diffuse; |
| 2130 | }; |
| 2131 | |
| 2132 | Vertex quad[4]; |
| 2133 | quad[0].x = 0.0f; |
| 2134 | quad[0].y = (float)desc.Height; |
| 2135 | quad[0].z = 0.0f; |
| 2136 | quad[0].w = 1.0f; |
| 2137 | quad[0].diffuse = color; |
| 2138 | |
| 2139 | quad[1].x = (float)desc.Width; |
| 2140 | quad[1].y = (float)desc.Height; |
| 2141 | quad[1].z = 0.0f; |
| 2142 | quad[1].w = 1.0f; |
| 2143 | quad[1].diffuse = color; |
| 2144 | |
| 2145 | quad[2].x = 0.0f; |
| 2146 | quad[2].y = 0.0f; |
| 2147 | quad[2].z = 0.0f; |
| 2148 | quad[2].w = 1.0f; |
| 2149 | quad[2].diffuse = color; |
| 2150 | |
| 2151 | quad[3].x = (float)desc.Width; |
| 2152 | quad[3].y = 0.0f; |
| 2153 | quad[3].z = 0.0f; |
| 2154 | quad[3].w = 1.0f; |
| 2155 | quad[3].diffuse = color; |
| 2156 | |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2157 | display->startScene(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2158 | device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(Vertex)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2159 | |
| 2160 | if (flags & D3DCLEAR_ZBUFFER) |
| 2161 | { |
| 2162 | device->SetRenderState(D3DRS_ZENABLE, TRUE); |
| 2163 | device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); |
| 2164 | device->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil); |
| 2165 | } |
| 2166 | } |
| 2167 | else |
| 2168 | { |
| 2169 | device->Clear(0, NULL, flags, color, depth, stencil); |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count) |
| 2174 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2175 | if (!mState.currentProgram) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2176 | { |
| 2177 | return error(GL_INVALID_OPERATION); |
| 2178 | } |
| 2179 | |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2180 | egl::Display *display = getDisplay(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2181 | IDirect3DDevice9 *device = getDevice(); |
| 2182 | D3DPRIMITIVETYPE primitiveType; |
| 2183 | int primitiveCount; |
| 2184 | |
| 2185 | if(!es2dx::ConvertPrimitiveType(mode, count, &primitiveType, &primitiveCount)) |
| 2186 | return error(GL_INVALID_ENUM); |
| 2187 | |
| 2188 | if (primitiveCount <= 0) |
| 2189 | { |
| 2190 | return; |
| 2191 | } |
| 2192 | |
| 2193 | if (!applyRenderTarget(false)) |
| 2194 | { |
| 2195 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 2196 | } |
| 2197 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 2198 | applyState(mode); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2199 | applyVertexBuffer(first, count); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2200 | applyShaders(); |
| 2201 | applyTextures(); |
| 2202 | |
daniel@transgaming.com | c3a0e94 | 2010-04-29 03:35:45 +0000 | [diff] [blame] | 2203 | if (!getCurrentProgram()->validateSamplers()) |
| 2204 | { |
| 2205 | return error(GL_INVALID_OPERATION); |
| 2206 | } |
| 2207 | |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2208 | if (!cullSkipsDraw(mode)) |
| 2209 | { |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2210 | display->startScene(); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 2211 | device->DrawPrimitive(primitiveType, 0, primitiveCount); |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2212 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) |
| 2216 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2217 | if (!mState.currentProgram) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2218 | { |
| 2219 | return error(GL_INVALID_OPERATION); |
| 2220 | } |
| 2221 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2222 | if (!indices && !mState.elementArrayBuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2223 | { |
| 2224 | return error(GL_INVALID_OPERATION); |
| 2225 | } |
| 2226 | |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2227 | egl::Display *display = getDisplay(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2228 | IDirect3DDevice9 *device = getDevice(); |
| 2229 | D3DPRIMITIVETYPE primitiveType; |
| 2230 | int primitiveCount; |
| 2231 | |
| 2232 | if(!es2dx::ConvertPrimitiveType(mode, count, &primitiveType, &primitiveCount)) |
| 2233 | return error(GL_INVALID_ENUM); |
| 2234 | |
| 2235 | if (primitiveCount <= 0) |
| 2236 | { |
| 2237 | return; |
| 2238 | } |
| 2239 | |
| 2240 | if (!applyRenderTarget(false)) |
| 2241 | { |
| 2242 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 2243 | } |
| 2244 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 2245 | applyState(mode); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 2246 | TranslatedIndexData indexInfo = applyIndexBuffer(indices, count, mode, type); |
| 2247 | applyVertexBuffer(indexInfo); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2248 | applyShaders(); |
| 2249 | applyTextures(); |
| 2250 | |
daniel@transgaming.com | c3a0e94 | 2010-04-29 03:35:45 +0000 | [diff] [blame] | 2251 | if (!getCurrentProgram()->validateSamplers()) |
| 2252 | { |
| 2253 | return error(GL_INVALID_OPERATION); |
| 2254 | } |
| 2255 | |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2256 | if (!cullSkipsDraw(mode)) |
| 2257 | { |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2258 | display->startScene(); |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 2259 | device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, indexInfo.maxIndex-indexInfo.minIndex+1, indexInfo.offset/sizeof(Index), primitiveCount); |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2260 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | void Context::finish() |
| 2264 | { |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2265 | egl::Display *display = getDisplay(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2266 | IDirect3DDevice9 *device = getDevice(); |
| 2267 | IDirect3DQuery9 *occlusionQuery = NULL; |
| 2268 | |
| 2269 | HRESULT result = device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery); |
| 2270 | |
| 2271 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 2272 | { |
| 2273 | return error(GL_OUT_OF_MEMORY); |
| 2274 | } |
| 2275 | |
| 2276 | ASSERT(SUCCEEDED(result)); |
| 2277 | |
| 2278 | if (occlusionQuery) |
| 2279 | { |
| 2280 | occlusionQuery->Issue(D3DISSUE_BEGIN); |
| 2281 | |
| 2282 | // Render something outside the render target |
| 2283 | device->SetPixelShader(NULL); |
| 2284 | device->SetVertexShader(NULL); |
| 2285 | device->SetFVF(D3DFVF_XYZRHW); |
| 2286 | float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f}; |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame^] | 2287 | display->startScene(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2288 | device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2289 | |
| 2290 | occlusionQuery->Issue(D3DISSUE_END); |
| 2291 | |
| 2292 | while (occlusionQuery->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE) |
| 2293 | { |
| 2294 | // Keep polling, but allow other threads to do something useful first |
| 2295 | Sleep(0); |
| 2296 | } |
| 2297 | |
| 2298 | occlusionQuery->Release(); |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | void Context::flush() |
| 2303 | { |
| 2304 | IDirect3DDevice9 *device = getDevice(); |
| 2305 | IDirect3DQuery9 *eventQuery = NULL; |
| 2306 | |
| 2307 | HRESULT result = device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); |
| 2308 | |
| 2309 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 2310 | { |
| 2311 | return error(GL_OUT_OF_MEMORY); |
| 2312 | } |
| 2313 | |
| 2314 | ASSERT(SUCCEEDED(result)); |
| 2315 | |
| 2316 | if (eventQuery) |
| 2317 | { |
| 2318 | eventQuery->Issue(D3DISSUE_END); |
| 2319 | |
| 2320 | while (eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE) |
| 2321 | { |
| 2322 | // Keep polling, but allow other threads to do something useful first |
| 2323 | Sleep(0); |
| 2324 | } |
| 2325 | |
| 2326 | eventQuery->Release(); |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | void Context::recordInvalidEnum() |
| 2331 | { |
| 2332 | mInvalidEnum = true; |
| 2333 | } |
| 2334 | |
| 2335 | void Context::recordInvalidValue() |
| 2336 | { |
| 2337 | mInvalidValue = true; |
| 2338 | } |
| 2339 | |
| 2340 | void Context::recordInvalidOperation() |
| 2341 | { |
| 2342 | mInvalidOperation = true; |
| 2343 | } |
| 2344 | |
| 2345 | void Context::recordOutOfMemory() |
| 2346 | { |
| 2347 | mOutOfMemory = true; |
| 2348 | } |
| 2349 | |
| 2350 | void Context::recordInvalidFramebufferOperation() |
| 2351 | { |
| 2352 | mInvalidFramebufferOperation = true; |
| 2353 | } |
| 2354 | |
| 2355 | // Get one of the recorded errors and clear its flag, if any. |
| 2356 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 2357 | GLenum Context::getError() |
| 2358 | { |
| 2359 | if (mInvalidEnum) |
| 2360 | { |
| 2361 | mInvalidEnum = false; |
| 2362 | |
| 2363 | return GL_INVALID_ENUM; |
| 2364 | } |
| 2365 | |
| 2366 | if (mInvalidValue) |
| 2367 | { |
| 2368 | mInvalidValue = false; |
| 2369 | |
| 2370 | return GL_INVALID_VALUE; |
| 2371 | } |
| 2372 | |
| 2373 | if (mInvalidOperation) |
| 2374 | { |
| 2375 | mInvalidOperation = false; |
| 2376 | |
| 2377 | return GL_INVALID_OPERATION; |
| 2378 | } |
| 2379 | |
| 2380 | if (mOutOfMemory) |
| 2381 | { |
| 2382 | mOutOfMemory = false; |
| 2383 | |
| 2384 | return GL_OUT_OF_MEMORY; |
| 2385 | } |
| 2386 | |
| 2387 | if (mInvalidFramebufferOperation) |
| 2388 | { |
| 2389 | mInvalidFramebufferOperation = false; |
| 2390 | |
| 2391 | return GL_INVALID_FRAMEBUFFER_OPERATION; |
| 2392 | } |
| 2393 | |
| 2394 | return GL_NO_ERROR; |
| 2395 | } |
| 2396 | |
daniel@transgaming.com | 296ca9c | 2010-04-03 20:56:07 +0000 | [diff] [blame] | 2397 | const char *Context::getPixelShaderProfile() |
| 2398 | { |
| 2399 | return mPsProfile; |
| 2400 | } |
| 2401 | |
| 2402 | const char *Context::getVertexShaderProfile() |
| 2403 | { |
| 2404 | return mVsProfile; |
| 2405 | } |
| 2406 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2407 | void Context::detachBuffer(GLuint buffer) |
| 2408 | { |
| 2409 | // [OpenGL ES 2.0.24] section 2.9 page 22: |
| 2410 | // If a buffer object is deleted while it is bound, all bindings to that object in the current context |
| 2411 | // (i.e. in the thread that called Delete-Buffers) are reset to zero. |
| 2412 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2413 | if (mState.arrayBuffer == buffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2414 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2415 | mState.arrayBuffer = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2418 | if (mState.elementArrayBuffer == buffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2419 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2420 | mState.elementArrayBuffer = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++) |
| 2424 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2425 | if (mState.vertexAttribute[attribute].mBoundBuffer == buffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2426 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2427 | mState.vertexAttribute[attribute].mBoundBuffer = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | void Context::detachTexture(GLuint texture) |
| 2433 | { |
| 2434 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 2435 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 2436 | // rebound to texture object zero |
| 2437 | |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2438 | for (int type = 0; type < SAMPLER_TYPE_COUNT; type++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2439 | { |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2440 | for (int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2441 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2442 | if (mState.samplerTexture[type][sampler] == texture) |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2443 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2444 | mState.samplerTexture[type][sampler] = 0; |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2445 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 2450 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 2451 | // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this |
| 2452 | // image was attached in the currently bound framebuffer. |
| 2453 | |
| 2454 | Framebuffer *framebuffer = getFramebuffer(); |
| 2455 | |
| 2456 | if (framebuffer) |
| 2457 | { |
| 2458 | framebuffer->detachTexture(texture); |
| 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | void Context::detachFramebuffer(GLuint framebuffer) |
| 2463 | { |
| 2464 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
| 2465 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though |
| 2466 | // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. |
| 2467 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2468 | if (mState.framebuffer == framebuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2469 | { |
| 2470 | bindFramebuffer(0); |
| 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 2475 | { |
| 2476 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 2477 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 2478 | // had been executed with the target RENDERBUFFER and name of zero. |
| 2479 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2480 | if (mState.renderbuffer == renderbuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2481 | { |
| 2482 | bindRenderbuffer(0); |
| 2483 | } |
| 2484 | |
| 2485 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 2486 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 2487 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 2488 | // point to which this image was attached in the currently bound framebuffer. |
| 2489 | |
| 2490 | Framebuffer *framebuffer = getFramebuffer(); |
| 2491 | |
| 2492 | if (framebuffer) |
| 2493 | { |
| 2494 | framebuffer->detachRenderbuffer(renderbuffer); |
| 2495 | } |
| 2496 | } |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 2497 | |
| 2498 | Texture *Context::getIncompleteTexture(SamplerType type) |
| 2499 | { |
| 2500 | Texture *t = mIncompleteTextures[type]; |
| 2501 | |
| 2502 | if (t == NULL) |
| 2503 | { |
| 2504 | static const GLubyte color[] = { 0, 0, 0, 255 }; |
| 2505 | |
| 2506 | switch (type) |
| 2507 | { |
| 2508 | default: |
| 2509 | UNREACHABLE(); |
| 2510 | // default falls through to SAMPLER_2D |
| 2511 | |
| 2512 | case SAMPLER_2D: |
| 2513 | { |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 2514 | Texture2D *incomplete2d = new Texture2D(this); |
daniel@transgaming.com | 3489e3a | 2010-03-21 04:31:11 +0000 | [diff] [blame] | 2515 | incomplete2d->setImage(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 2516 | t = incomplete2d; |
| 2517 | } |
| 2518 | break; |
| 2519 | |
| 2520 | case SAMPLER_CUBE: |
| 2521 | { |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 2522 | TextureCubeMap *incompleteCube = new TextureCubeMap(this); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 2523 | |
daniel@transgaming.com | 3489e3a | 2010-03-21 04:31:11 +0000 | [diff] [blame] | 2524 | incompleteCube->setImagePosX(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2525 | incompleteCube->setImageNegX(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2526 | incompleteCube->setImagePosY(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2527 | incompleteCube->setImageNegY(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2528 | incompleteCube->setImagePosZ(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2529 | incompleteCube->setImageNegZ(0, GL_RGBA, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 2530 | |
| 2531 | t = incompleteCube; |
| 2532 | } |
| 2533 | break; |
| 2534 | } |
| 2535 | |
| 2536 | mIncompleteTextures[type] = t; |
| 2537 | } |
| 2538 | |
| 2539 | return t; |
| 2540 | } |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2541 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 2542 | bool Context::cullSkipsDraw(GLenum drawMode) |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2543 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2544 | return mState.cullFace && mState.cullMode == GL_FRONT_AND_BACK && isTriangleMode(drawMode); |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 2547 | bool Context::isTriangleMode(GLenum drawMode) |
| 2548 | { |
| 2549 | switch (drawMode) |
| 2550 | { |
| 2551 | case GL_TRIANGLES: |
| 2552 | case GL_TRIANGLE_FAN: |
| 2553 | case GL_TRIANGLE_STRIP: |
| 2554 | return true; |
| 2555 | case GL_POINTS: |
| 2556 | case GL_LINES: |
| 2557 | case GL_LINE_LOOP: |
| 2558 | case GL_LINE_STRIP: |
| 2559 | return false; |
| 2560 | default: UNREACHABLE(); |
| 2561 | } |
| 2562 | |
| 2563 | return false; |
| 2564 | } |
daniel@transgaming.com | e4b08c8 | 2010-04-20 18:53:06 +0000 | [diff] [blame] | 2565 | |
| 2566 | void Context::setVertexAttrib(GLuint index, const GLfloat *values) |
| 2567 | { |
| 2568 | ASSERT(index < gl::MAX_VERTEX_ATTRIBS); |
| 2569 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2570 | mState.vertexAttribute[index].mCurrentValue[0] = values[0]; |
| 2571 | mState.vertexAttribute[index].mCurrentValue[1] = values[1]; |
| 2572 | mState.vertexAttribute[index].mCurrentValue[2] = values[2]; |
| 2573 | mState.vertexAttribute[index].mCurrentValue[3] = values[3]; |
daniel@transgaming.com | e4b08c8 | 2010-04-20 18:53:06 +0000 | [diff] [blame] | 2574 | |
| 2575 | mVertexDataManager->dirtyCurrentValues(); |
| 2576 | } |
| 2577 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | extern "C" |
| 2581 | { |
| 2582 | gl::Context *glCreateContext(const egl::Config *config) |
| 2583 | { |
| 2584 | return new gl::Context(config); |
| 2585 | } |
| 2586 | |
| 2587 | void glDestroyContext(gl::Context *context) |
| 2588 | { |
| 2589 | delete context; |
| 2590 | |
| 2591 | if (context == gl::getContext()) |
| 2592 | { |
| 2593 | gl::makeCurrent(NULL, NULL, NULL); |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface) |
| 2598 | { |
| 2599 | gl::makeCurrent(context, display, surface); |
| 2600 | } |
| 2601 | |
| 2602 | gl::Context *glGetCurrentContext() |
| 2603 | { |
| 2604 | return gl::getContext(); |
| 2605 | } |
| 2606 | } |