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