daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
daniel@transgaming.com | af29cac | 2011-05-11 15:36:31 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 20 | #include "libGLESv2/ResourceManager.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 21 | #include "libGLESv2/Buffer.h" |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 22 | #include "libGLESv2/Fence.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 23 | #include "libGLESv2/FrameBuffer.h" |
| 24 | #include "libGLESv2/Program.h" |
| 25 | #include "libGLESv2/RenderBuffer.h" |
| 26 | #include "libGLESv2/Shader.h" |
| 27 | #include "libGLESv2/Texture.h" |
daniel@transgaming.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 28 | #include "libGLESv2/VertexDataManager.h" |
| 29 | #include "libGLESv2/IndexDataManager.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 | |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 34 | namespace |
| 35 | { |
| 36 | enum { CLOSING_INDEX_BUFFER_SIZE = 4096 }; |
| 37 | } |
| 38 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 39 | namespace gl |
| 40 | { |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 41 | Context::Context(const egl::Config *config, const gl::Context *shareContext) : mConfig(config) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 42 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 43 | mDisplay = NULL; |
| 44 | mDevice = NULL; |
| 45 | |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 46 | mFenceHandleAllocator.setBaseHandle(0); |
| 47 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 48 | setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 49 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 50 | mState.depthClearValue = 1.0f; |
| 51 | mState.stencilClearValue = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 52 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 53 | mState.cullFace = false; |
| 54 | mState.cullMode = GL_BACK; |
| 55 | mState.frontFace = GL_CCW; |
| 56 | mState.depthTest = false; |
| 57 | mState.depthFunc = GL_LESS; |
| 58 | mState.blend = false; |
| 59 | mState.sourceBlendRGB = GL_ONE; |
| 60 | mState.sourceBlendAlpha = GL_ONE; |
| 61 | mState.destBlendRGB = GL_ZERO; |
| 62 | mState.destBlendAlpha = GL_ZERO; |
| 63 | mState.blendEquationRGB = GL_FUNC_ADD; |
| 64 | mState.blendEquationAlpha = GL_FUNC_ADD; |
| 65 | mState.blendColor.red = 0; |
| 66 | mState.blendColor.green = 0; |
| 67 | mState.blendColor.blue = 0; |
| 68 | mState.blendColor.alpha = 0; |
| 69 | mState.stencilTest = false; |
| 70 | mState.stencilFunc = GL_ALWAYS; |
| 71 | mState.stencilRef = 0; |
| 72 | mState.stencilMask = -1; |
| 73 | mState.stencilWritemask = -1; |
| 74 | mState.stencilBackFunc = GL_ALWAYS; |
| 75 | mState.stencilBackRef = 0; |
| 76 | mState.stencilBackMask = - 1; |
| 77 | mState.stencilBackWritemask = -1; |
| 78 | mState.stencilFail = GL_KEEP; |
| 79 | mState.stencilPassDepthFail = GL_KEEP; |
| 80 | mState.stencilPassDepthPass = GL_KEEP; |
| 81 | mState.stencilBackFail = GL_KEEP; |
| 82 | mState.stencilBackPassDepthFail = GL_KEEP; |
| 83 | mState.stencilBackPassDepthPass = GL_KEEP; |
| 84 | mState.polygonOffsetFill = false; |
| 85 | mState.polygonOffsetFactor = 0.0f; |
| 86 | mState.polygonOffsetUnits = 0.0f; |
| 87 | mState.sampleAlphaToCoverage = false; |
| 88 | mState.sampleCoverage = false; |
| 89 | mState.sampleCoverageValue = 1.0f; |
daniel@transgaming.com | a36f98e | 2010-05-18 18:51:09 +0000 | [diff] [blame] | 90 | mState.sampleCoverageInvert = false; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 91 | mState.scissorTest = false; |
| 92 | mState.dither = true; |
| 93 | mState.generateMipmapHint = GL_DONT_CARE; |
alokp@chromium.org | d303ef9 | 2010-09-09 17:30:15 +0000 | [diff] [blame] | 94 | mState.fragmentShaderDerivativeHint = GL_DONT_CARE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 95 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 96 | mState.lineWidth = 1.0f; |
daniel@transgaming.com | 32e58cd | 2010-03-24 09:44:10 +0000 | [diff] [blame] | 97 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 98 | mState.viewportX = 0; |
| 99 | mState.viewportY = 0; |
| 100 | mState.viewportWidth = config->mDisplayMode.Width; |
| 101 | mState.viewportHeight = config->mDisplayMode.Height; |
| 102 | mState.zNear = 0.0f; |
| 103 | mState.zFar = 1.0f; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 104 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 105 | mState.scissorX = 0; |
| 106 | mState.scissorY = 0; |
| 107 | mState.scissorWidth = config->mDisplayMode.Width; |
| 108 | mState.scissorHeight = config->mDisplayMode.Height; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 109 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 110 | mState.colorMaskRed = true; |
| 111 | mState.colorMaskGreen = true; |
| 112 | mState.colorMaskBlue = true; |
| 113 | mState.colorMaskAlpha = true; |
| 114 | mState.depthMask = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 115 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 116 | if (shareContext != NULL) |
| 117 | { |
| 118 | mResourceManager = shareContext->mResourceManager; |
| 119 | mResourceManager->addRef(); |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | mResourceManager = new ResourceManager(); |
| 124 | } |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 125 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 126 | // [OpenGL ES 2.0.24] section 3.7 page 83: |
| 127 | // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional |
| 128 | // and cube map texture state vectors respectively associated with them. |
| 129 | // In order that access to these initial textures not be lost, they are treated as texture |
| 130 | // objects all of whose names are 0. |
| 131 | |
apatrick@chromium.org | 4e3bad4 | 2010-09-15 17:31:48 +0000 | [diff] [blame] | 132 | mTexture2DZero.set(new Texture2D(0)); |
| 133 | mTextureCubeMapZero.set(new TextureCubeMap(0)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 134 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 135 | mState.activeSampler = 0; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 136 | bindArrayBuffer(0); |
| 137 | bindElementArrayBuffer(0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 138 | bindTextureCubeMap(0); |
| 139 | bindTexture2D(0); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 140 | bindReadFramebuffer(0); |
| 141 | bindDrawFramebuffer(0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 142 | bindRenderbuffer(0); |
| 143 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 144 | mState.currentProgram = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 145 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 146 | mState.packAlignment = 4; |
| 147 | mState.unpackAlignment = 4; |
daniel@transgaming.com | 3489e3a | 2010-03-21 04:31:11 +0000 | [diff] [blame] | 148 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 149 | mVertexDataManager = NULL; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 150 | mIndexDataManager = NULL; |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 151 | mBlit = NULL; |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 152 | mClosingIB = NULL; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 153 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 154 | mInvalidEnum = false; |
| 155 | mInvalidValue = false; |
| 156 | mInvalidOperation = false; |
| 157 | mOutOfMemory = false; |
| 158 | mInvalidFramebufferOperation = false; |
daniel@transgaming.com | 159acdf | 2010-03-21 04:31:24 +0000 | [diff] [blame] | 159 | |
| 160 | mHasBeenCurrent = false; |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame^] | 161 | mContextLost = false; |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 162 | |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 163 | mSupportsDXT1Textures = false; |
| 164 | mSupportsDXT3Textures = false; |
| 165 | mSupportsDXT5Textures = false; |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 166 | mSupportsEventQueries = false; |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 167 | mNumCompressedTextureFormats = 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 168 | mMaxSupportedSamples = 0; |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 169 | mMaskedClearSavedState = NULL; |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 170 | markAllStateDirty(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | Context::~Context() |
| 174 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 175 | if (mState.currentProgram != 0) |
| 176 | { |
| 177 | Program *programObject = mResourceManager->getProgram(mState.currentProgram); |
| 178 | if (programObject) |
| 179 | { |
| 180 | programObject->release(); |
| 181 | } |
| 182 | mState.currentProgram = 0; |
| 183 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 184 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 185 | while (!mFramebufferMap.empty()) |
| 186 | { |
| 187 | deleteFramebuffer(mFramebufferMap.begin()->first); |
| 188 | } |
| 189 | |
daniel@transgaming.com | fe20888 | 2010-09-01 15:47:57 +0000 | [diff] [blame] | 190 | while (!mFenceMap.empty()) |
| 191 | { |
| 192 | deleteFence(mFenceMap.begin()->first); |
| 193 | } |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 194 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 195 | while (!mMultiSampleSupport.empty()) |
| 196 | { |
| 197 | delete [] mMultiSampleSupport.begin()->second; |
| 198 | mMultiSampleSupport.erase(mMultiSampleSupport.begin()); |
| 199 | } |
| 200 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 201 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 202 | { |
daniel@transgaming.com | 3f74c7a | 2011-05-11 15:36:51 +0000 | [diff] [blame] | 203 | for (int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; sampler++) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 204 | { |
| 205 | mState.samplerTexture[type][sampler].set(NULL); |
| 206 | } |
| 207 | } |
| 208 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 209 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 210 | { |
apatrick@chromium.org | 4e3bad4 | 2010-09-15 17:31:48 +0000 | [diff] [blame] | 211 | mIncompleteTextures[type].set(NULL); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 212 | } |
| 213 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 214 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 215 | { |
| 216 | mState.vertexAttribute[i].mBoundBuffer.set(NULL); |
| 217 | } |
| 218 | |
| 219 | mState.arrayBuffer.set(NULL); |
| 220 | mState.elementArrayBuffer.set(NULL); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 221 | mState.renderbuffer.set(NULL); |
| 222 | |
apatrick@chromium.org | 4e3bad4 | 2010-09-15 17:31:48 +0000 | [diff] [blame] | 223 | mTexture2DZero.set(NULL); |
| 224 | mTextureCubeMapZero.set(NULL); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 225 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 226 | delete mVertexDataManager; |
daniel@transgaming.com | f8b58a0 | 2010-03-26 04:08:45 +0000 | [diff] [blame] | 227 | delete mIndexDataManager; |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 228 | delete mBlit; |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 229 | delete mClosingIB; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 230 | |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 231 | if (mMaskedClearSavedState) |
| 232 | { |
| 233 | mMaskedClearSavedState->Release(); |
| 234 | } |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 235 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 236 | mResourceManager->release(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void Context::makeCurrent(egl::Display *display, egl::Surface *surface) |
| 240 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 241 | mDisplay = display; |
| 242 | mDevice = mDisplay->getDevice(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 243 | |
daniel@transgaming.com | c808c5a | 2010-05-14 17:31:01 +0000 | [diff] [blame] | 244 | if (!mHasBeenCurrent) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 245 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 246 | mDeviceCaps = mDisplay->getDeviceCaps(); |
daniel@transgaming.com | c808c5a | 2010-05-14 17:31:01 +0000 | [diff] [blame] | 247 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 248 | mVertexDataManager = new VertexDataManager(this, mDevice); |
| 249 | mIndexDataManager = new IndexDataManager(this, mDevice); |
daniel@transgaming.com | b8c28ed | 2010-04-13 03:26:32 +0000 | [diff] [blame] | 250 | mBlit = new Blit(this); |
daniel@transgaming.com | c808c5a | 2010-05-14 17:31:01 +0000 | [diff] [blame] | 251 | |
daniel@transgaming.com | 5d752f2 | 2010-10-07 13:37:20 +0000 | [diff] [blame] | 252 | mSupportsShaderModel3 = mDeviceCaps.PixelShaderVersion == D3DPS_VERSION(3, 0); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 253 | mSupportsVertexTexture = mDisplay->getVertexTextureSupport(); |
| 254 | mSupportsNonPower2Texture = mDisplay->getNonPower2TextureSupport(); |
daniel@transgaming.com | 5d752f2 | 2010-10-07 13:37:20 +0000 | [diff] [blame] | 255 | |
| 256 | mMaxTextureDimension = std::min(std::min((int)mDeviceCaps.MaxTextureWidth, (int)mDeviceCaps.MaxTextureHeight), |
| 257 | (int)gl::IMPLEMENTATION_MAX_TEXTURE_SIZE); |
| 258 | mMaxCubeTextureDimension = std::min(mMaxTextureDimension, (int)gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE); |
| 259 | mMaxRenderbufferDimension = mMaxTextureDimension; |
| 260 | mMaxTextureLevel = log2(mMaxTextureDimension) + 1; |
| 261 | TRACE("MaxTextureDimension=%d, MaxCubeTextureDimension=%d, MaxRenderbufferDimension=%d, MaxTextureLevel=%d", |
| 262 | mMaxTextureDimension, mMaxCubeTextureDimension, mMaxRenderbufferDimension, mMaxTextureLevel); |
| 263 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 264 | const D3DFORMAT renderBufferFormats[] = |
| 265 | { |
| 266 | D3DFMT_A8R8G8B8, |
daniel@transgaming.com | 6397754 | 2010-08-24 19:21:02 +0000 | [diff] [blame] | 267 | D3DFMT_X8R8G8B8, |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 268 | D3DFMT_R5G6B5, |
| 269 | D3DFMT_D24S8 |
| 270 | }; |
| 271 | |
| 272 | int max = 0; |
| 273 | for (int i = 0; i < sizeof(renderBufferFormats) / sizeof(D3DFORMAT); ++i) |
| 274 | { |
| 275 | bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1]; |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 276 | mDisplay->getMultiSampleSupport(renderBufferFormats[i], multisampleArray); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 277 | mMultiSampleSupport[renderBufferFormats[i]] = multisampleArray; |
| 278 | |
| 279 | for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j) |
| 280 | { |
| 281 | if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max) |
| 282 | { |
| 283 | max = j; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | mMaxSupportedSamples = max; |
| 289 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 290 | mSupportsEventQueries = mDisplay->getEventQuerySupport(); |
| 291 | mSupportsDXT1Textures = mDisplay->getDXT1TextureSupport(); |
| 292 | mSupportsDXT3Textures = mDisplay->getDXT3TextureSupport(); |
| 293 | mSupportsDXT5Textures = mDisplay->getDXT5TextureSupport(); |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 294 | mSupportsFloat32Textures = mDisplay->getFloat32TextureSupport(&mSupportsFloat32LinearFilter, &mSupportsFloat32RenderableTextures); |
| 295 | mSupportsFloat16Textures = mDisplay->getFloat16TextureSupport(&mSupportsFloat16LinearFilter, &mSupportsFloat16RenderableTextures); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 296 | mSupportsLuminanceTextures = mDisplay->getLuminanceTextureSupport(); |
| 297 | mSupportsLuminanceAlphaTextures = mDisplay->getLuminanceAlphaTextureSupport(); |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 298 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 299 | mSupports32bitIndices = mDeviceCaps.MaxVertexIndex >= (1 << 16); |
| 300 | |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 301 | mNumCompressedTextureFormats = 0; |
| 302 | if (supportsDXT1Textures()) |
| 303 | { |
| 304 | mNumCompressedTextureFormats += 2; |
| 305 | } |
| 306 | if (supportsDXT3Textures()) |
| 307 | { |
| 308 | mNumCompressedTextureFormats += 1; |
| 309 | } |
| 310 | if (supportsDXT5Textures()) |
| 311 | { |
| 312 | mNumCompressedTextureFormats += 1; |
| 313 | } |
| 314 | |
daniel@transgaming.com | c808c5a | 2010-05-14 17:31:01 +0000 | [diff] [blame] | 315 | initExtensionString(); |
daniel@transgaming.com | c23ff64 | 2011-08-16 20:28:45 +0000 | [diff] [blame] | 316 | initRendererString(); |
daniel@transgaming.com | c808c5a | 2010-05-14 17:31:01 +0000 | [diff] [blame] | 317 | |
| 318 | mState.viewportX = 0; |
| 319 | mState.viewportY = 0; |
| 320 | mState.viewportWidth = surface->getWidth(); |
| 321 | mState.viewportHeight = surface->getHeight(); |
| 322 | |
| 323 | mState.scissorX = 0; |
| 324 | mState.scissorY = 0; |
| 325 | mState.scissorWidth = surface->getWidth(); |
| 326 | mState.scissorHeight = surface->getHeight(); |
| 327 | |
| 328 | mHasBeenCurrent = true; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 329 | } |
| 330 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 331 | // Wrap the existing Direct3D 9 resources into GL objects and assign them to the '0' names |
| 332 | IDirect3DSurface9 *defaultRenderTarget = surface->getRenderTarget(); |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 333 | IDirect3DSurface9 *depthStencil = surface->getDepthStencil(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 334 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 335 | Colorbuffer *colorbufferZero = new Colorbuffer(defaultRenderTarget); |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 336 | DepthStencilbuffer *depthStencilbufferZero = new DepthStencilbuffer(depthStencil); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 337 | Framebuffer *framebufferZero = new DefaultFramebuffer(colorbufferZero, depthStencilbufferZero); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 338 | |
| 339 | setFramebufferZero(framebufferZero); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 340 | |
daniel@transgaming.com | d36c6a0 | 2010-08-31 12:15:09 +0000 | [diff] [blame] | 341 | if (defaultRenderTarget) |
| 342 | { |
| 343 | defaultRenderTarget->Release(); |
| 344 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 345 | |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 346 | if (depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 347 | { |
daniel@transgaming.com | 0009d62 | 2010-03-16 06:23:31 +0000 | [diff] [blame] | 348 | depthStencil->Release(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 349 | } |
daniel@transgaming.com | 296ca9c | 2010-04-03 20:56:07 +0000 | [diff] [blame] | 350 | |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 351 | markAllStateDirty(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 352 | } |
| 353 | |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 354 | // 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] | 355 | void Context::markAllStateDirty() |
| 356 | { |
daniel@transgaming.com | 38e76e5 | 2011-03-21 16:39:10 +0000 | [diff] [blame] | 357 | for (int t = 0; t < MAX_TEXTURE_IMAGE_UNITS; t++) |
| 358 | { |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 359 | mAppliedTextureSerialPS[t] = 0; |
| 360 | } |
| 361 | |
| 362 | for (int t = 0; t < MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; t++) |
| 363 | { |
| 364 | mAppliedTextureSerialVS[t] = 0; |
daniel@transgaming.com | 38e76e5 | 2011-03-21 16:39:10 +0000 | [diff] [blame] | 365 | } |
| 366 | |
daniel@transgaming.com | a9eb5da | 2011-03-21 16:39:16 +0000 | [diff] [blame] | 367 | mAppliedProgramSerial = 0; |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 368 | mAppliedRenderTargetSerial = 0; |
daniel@transgaming.com | 339ae70 | 2010-05-12 03:40:20 +0000 | [diff] [blame] | 369 | mAppliedDepthbufferSerial = 0; |
apatrick@chromium.org | 85dc42b | 2010-09-14 03:10:08 +0000 | [diff] [blame] | 370 | mAppliedStencilbufferSerial = 0; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 371 | mAppliedIBSerial = 0; |
vangelis@chromium.org | cf66ebb | 2010-09-14 22:15:43 +0000 | [diff] [blame] | 372 | mDepthStencilInitialized = false; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 373 | mViewportInitialized = false; |
| 374 | mRenderTargetDescInitialized = false; |
| 375 | |
| 376 | mVertexDeclarationCache.markStateDirty(); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 377 | |
| 378 | mClearStateDirty = true; |
| 379 | mCullStateDirty = true; |
| 380 | mDepthStateDirty = true; |
| 381 | mMaskStateDirty = true; |
| 382 | mBlendStateDirty = true; |
| 383 | mStencilStateDirty = true; |
| 384 | mPolygonOffsetStateDirty = true; |
| 385 | mScissorStateDirty = true; |
| 386 | mSampleStateDirty = true; |
| 387 | mDitherStateDirty = true; |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 388 | mFrontFaceDirty = true; |
jbauman@chromium.org | 54f59ef | 2011-10-12 17:03:34 +0000 | [diff] [blame] | 389 | mDxUniformsDirty = true; |
jbauman@chromium.org | c620985 | 2011-10-07 15:19:26 +0000 | [diff] [blame] | 390 | mCachedCurrentProgram = NULL; |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 391 | } |
| 392 | |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame^] | 393 | void Context::markContextLost() |
| 394 | { |
| 395 | mContextLost = true; |
| 396 | } |
| 397 | |
| 398 | bool Context::isContextLost() |
| 399 | { |
| 400 | return mContextLost; |
| 401 | } |
| 402 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 403 | void Context::setClearColor(float red, float green, float blue, float alpha) |
| 404 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 405 | mState.colorClearValue.red = red; |
| 406 | mState.colorClearValue.green = green; |
| 407 | mState.colorClearValue.blue = blue; |
| 408 | mState.colorClearValue.alpha = alpha; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void Context::setClearDepth(float depth) |
| 412 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 413 | mState.depthClearValue = depth; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void Context::setClearStencil(int stencil) |
| 417 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 418 | mState.stencilClearValue = stencil; |
| 419 | } |
| 420 | |
| 421 | void Context::setCullFace(bool enabled) |
| 422 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 423 | if (mState.cullFace != enabled) |
| 424 | { |
| 425 | mState.cullFace = enabled; |
| 426 | mCullStateDirty = true; |
| 427 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | bool Context::isCullFaceEnabled() const |
| 431 | { |
| 432 | return mState.cullFace; |
| 433 | } |
| 434 | |
| 435 | void Context::setCullMode(GLenum mode) |
| 436 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 437 | if (mState.cullMode != mode) |
| 438 | { |
| 439 | mState.cullMode = mode; |
| 440 | mCullStateDirty = true; |
| 441 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void Context::setFrontFace(GLenum front) |
| 445 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 446 | if (mState.frontFace != front) |
| 447 | { |
| 448 | mState.frontFace = front; |
| 449 | mFrontFaceDirty = true; |
| 450 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void Context::setDepthTest(bool enabled) |
| 454 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 455 | if (mState.depthTest != enabled) |
| 456 | { |
| 457 | mState.depthTest = enabled; |
| 458 | mDepthStateDirty = true; |
| 459 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | bool Context::isDepthTestEnabled() const |
| 463 | { |
| 464 | return mState.depthTest; |
| 465 | } |
| 466 | |
| 467 | void Context::setDepthFunc(GLenum depthFunc) |
| 468 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 469 | if (mState.depthFunc != depthFunc) |
| 470 | { |
| 471 | mState.depthFunc = depthFunc; |
| 472 | mDepthStateDirty = true; |
| 473 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void Context::setDepthRange(float zNear, float zFar) |
| 477 | { |
| 478 | mState.zNear = zNear; |
| 479 | mState.zFar = zFar; |
| 480 | } |
| 481 | |
| 482 | void Context::setBlend(bool enabled) |
| 483 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 484 | if (mState.blend != enabled) |
| 485 | { |
| 486 | mState.blend = enabled; |
| 487 | mBlendStateDirty = true; |
| 488 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | bool Context::isBlendEnabled() const |
| 492 | { |
| 493 | return mState.blend; |
| 494 | } |
| 495 | |
| 496 | void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) |
| 497 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 498 | if (mState.sourceBlendRGB != sourceRGB || |
| 499 | mState.sourceBlendAlpha != sourceAlpha || |
| 500 | mState.destBlendRGB != destRGB || |
| 501 | mState.destBlendAlpha != destAlpha) |
| 502 | { |
| 503 | mState.sourceBlendRGB = sourceRGB; |
| 504 | mState.destBlendRGB = destRGB; |
| 505 | mState.sourceBlendAlpha = sourceAlpha; |
| 506 | mState.destBlendAlpha = destAlpha; |
| 507 | mBlendStateDirty = true; |
| 508 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | void Context::setBlendColor(float red, float green, float blue, float alpha) |
| 512 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 513 | if (mState.blendColor.red != red || |
| 514 | mState.blendColor.green != green || |
| 515 | mState.blendColor.blue != blue || |
| 516 | mState.blendColor.alpha != alpha) |
| 517 | { |
| 518 | mState.blendColor.red = red; |
| 519 | mState.blendColor.green = green; |
| 520 | mState.blendColor.blue = blue; |
| 521 | mState.blendColor.alpha = alpha; |
| 522 | mBlendStateDirty = true; |
| 523 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 527 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 528 | if (mState.blendEquationRGB != rgbEquation || |
| 529 | mState.blendEquationAlpha != alphaEquation) |
| 530 | { |
| 531 | mState.blendEquationRGB = rgbEquation; |
| 532 | mState.blendEquationAlpha = alphaEquation; |
| 533 | mBlendStateDirty = true; |
| 534 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void Context::setStencilTest(bool enabled) |
| 538 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 539 | if (mState.stencilTest != enabled) |
| 540 | { |
| 541 | mState.stencilTest = enabled; |
| 542 | mStencilStateDirty = true; |
| 543 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | bool Context::isStencilTestEnabled() const |
| 547 | { |
| 548 | return mState.stencilTest; |
| 549 | } |
| 550 | |
| 551 | void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 552 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 553 | if (mState.stencilFunc != stencilFunc || |
| 554 | mState.stencilRef != stencilRef || |
| 555 | mState.stencilMask != stencilMask) |
| 556 | { |
| 557 | mState.stencilFunc = stencilFunc; |
daniel@transgaming.com | dd7948b | 2010-06-02 16:12:34 +0000 | [diff] [blame] | 558 | mState.stencilRef = (stencilRef > 0) ? stencilRef : 0; |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 559 | mState.stencilMask = stencilMask; |
| 560 | mStencilStateDirty = true; |
| 561 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) |
| 565 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 566 | if (mState.stencilBackFunc != stencilBackFunc || |
| 567 | mState.stencilBackRef != stencilBackRef || |
| 568 | mState.stencilBackMask != stencilBackMask) |
| 569 | { |
| 570 | mState.stencilBackFunc = stencilBackFunc; |
daniel@transgaming.com | dd7948b | 2010-06-02 16:12:34 +0000 | [diff] [blame] | 571 | mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 572 | mState.stencilBackMask = stencilBackMask; |
| 573 | mStencilStateDirty = true; |
| 574 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | void Context::setStencilWritemask(GLuint stencilWritemask) |
| 578 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 579 | if (mState.stencilWritemask != stencilWritemask) |
| 580 | { |
| 581 | mState.stencilWritemask = stencilWritemask; |
| 582 | mStencilStateDirty = true; |
| 583 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void Context::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 587 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 588 | if (mState.stencilBackWritemask != stencilBackWritemask) |
| 589 | { |
| 590 | mState.stencilBackWritemask = stencilBackWritemask; |
| 591 | mStencilStateDirty = true; |
| 592 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) |
| 596 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 597 | if (mState.stencilFail != stencilFail || |
| 598 | mState.stencilPassDepthFail != stencilPassDepthFail || |
| 599 | mState.stencilPassDepthPass != stencilPassDepthPass) |
| 600 | { |
| 601 | mState.stencilFail = stencilFail; |
| 602 | mState.stencilPassDepthFail = stencilPassDepthFail; |
| 603 | mState.stencilPassDepthPass = stencilPassDepthPass; |
| 604 | mStencilStateDirty = true; |
| 605 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) |
| 609 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 610 | if (mState.stencilBackFail != stencilBackFail || |
| 611 | mState.stencilBackPassDepthFail != stencilBackPassDepthFail || |
| 612 | mState.stencilBackPassDepthPass != stencilBackPassDepthPass) |
| 613 | { |
| 614 | mState.stencilBackFail = stencilBackFail; |
| 615 | mState.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 616 | mState.stencilBackPassDepthPass = stencilBackPassDepthPass; |
| 617 | mStencilStateDirty = true; |
| 618 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | void Context::setPolygonOffsetFill(bool enabled) |
| 622 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 623 | if (mState.polygonOffsetFill != enabled) |
| 624 | { |
| 625 | mState.polygonOffsetFill = enabled; |
| 626 | mPolygonOffsetStateDirty = true; |
| 627 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | bool Context::isPolygonOffsetFillEnabled() const |
| 631 | { |
| 632 | return mState.polygonOffsetFill; |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 633 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units) |
| 637 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 638 | if (mState.polygonOffsetFactor != factor || |
| 639 | mState.polygonOffsetUnits != units) |
| 640 | { |
| 641 | mState.polygonOffsetFactor = factor; |
| 642 | mState.polygonOffsetUnits = units; |
| 643 | mPolygonOffsetStateDirty = true; |
| 644 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void Context::setSampleAlphaToCoverage(bool enabled) |
| 648 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 649 | if (mState.sampleAlphaToCoverage != enabled) |
| 650 | { |
| 651 | mState.sampleAlphaToCoverage = enabled; |
| 652 | mSampleStateDirty = true; |
| 653 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | bool Context::isSampleAlphaToCoverageEnabled() const |
| 657 | { |
| 658 | return mState.sampleAlphaToCoverage; |
| 659 | } |
| 660 | |
| 661 | void Context::setSampleCoverage(bool enabled) |
| 662 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 663 | if (mState.sampleCoverage != enabled) |
| 664 | { |
| 665 | mState.sampleCoverage = enabled; |
| 666 | mSampleStateDirty = true; |
| 667 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | bool Context::isSampleCoverageEnabled() const |
| 671 | { |
| 672 | return mState.sampleCoverage; |
| 673 | } |
| 674 | |
daniel@transgaming.com | a36f98e | 2010-05-18 18:51:09 +0000 | [diff] [blame] | 675 | void Context::setSampleCoverageParams(GLclampf value, bool invert) |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 676 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 677 | if (mState.sampleCoverageValue != value || |
| 678 | mState.sampleCoverageInvert != invert) |
| 679 | { |
| 680 | mState.sampleCoverageValue = value; |
| 681 | mState.sampleCoverageInvert = invert; |
| 682 | mSampleStateDirty = true; |
| 683 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | void Context::setScissorTest(bool enabled) |
| 687 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 688 | if (mState.scissorTest != enabled) |
| 689 | { |
| 690 | mState.scissorTest = enabled; |
| 691 | mScissorStateDirty = true; |
| 692 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | bool Context::isScissorTestEnabled() const |
| 696 | { |
| 697 | return mState.scissorTest; |
| 698 | } |
| 699 | |
| 700 | void Context::setDither(bool enabled) |
| 701 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 702 | if (mState.dither != enabled) |
| 703 | { |
| 704 | mState.dither = enabled; |
| 705 | mDitherStateDirty = true; |
| 706 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | bool Context::isDitherEnabled() const |
| 710 | { |
| 711 | return mState.dither; |
| 712 | } |
| 713 | |
| 714 | void Context::setLineWidth(GLfloat width) |
| 715 | { |
| 716 | mState.lineWidth = width; |
| 717 | } |
| 718 | |
| 719 | void Context::setGenerateMipmapHint(GLenum hint) |
| 720 | { |
| 721 | mState.generateMipmapHint = hint; |
| 722 | } |
| 723 | |
alokp@chromium.org | d303ef9 | 2010-09-09 17:30:15 +0000 | [diff] [blame] | 724 | void Context::setFragmentShaderDerivativeHint(GLenum hint) |
| 725 | { |
| 726 | mState.fragmentShaderDerivativeHint = hint; |
| 727 | // TODO: Propagate the hint to shader translator so we can write |
| 728 | // ddx, ddx_coarse, or ddx_fine depending on the hint. |
| 729 | // Ignore for now. It is valid for implementations to ignore hint. |
| 730 | } |
| 731 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 732 | void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 733 | { |
| 734 | mState.viewportX = x; |
| 735 | mState.viewportY = y; |
| 736 | mState.viewportWidth = width; |
| 737 | mState.viewportHeight = height; |
| 738 | } |
| 739 | |
| 740 | void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 741 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 742 | if (mState.scissorX != x || mState.scissorY != y || |
| 743 | mState.scissorWidth != width || mState.scissorHeight != height) |
| 744 | { |
| 745 | mState.scissorX = x; |
| 746 | mState.scissorY = y; |
| 747 | mState.scissorWidth = width; |
| 748 | mState.scissorHeight = height; |
| 749 | mScissorStateDirty = true; |
| 750 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void Context::setColorMask(bool red, bool green, bool blue, bool alpha) |
| 754 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 755 | if (mState.colorMaskRed != red || mState.colorMaskGreen != green || |
| 756 | mState.colorMaskBlue != blue || mState.colorMaskAlpha != alpha) |
| 757 | { |
| 758 | mState.colorMaskRed = red; |
| 759 | mState.colorMaskGreen = green; |
| 760 | mState.colorMaskBlue = blue; |
| 761 | mState.colorMaskAlpha = alpha; |
| 762 | mMaskStateDirty = true; |
| 763 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | void Context::setDepthMask(bool mask) |
| 767 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 768 | if (mState.depthMask != mask) |
| 769 | { |
| 770 | mState.depthMask = mask; |
| 771 | mMaskStateDirty = true; |
| 772 | } |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 773 | } |
| 774 | |
daniel@transgaming.com | dfd5702 | 2011-05-11 15:37:25 +0000 | [diff] [blame] | 775 | void Context::setActiveSampler(unsigned int active) |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 776 | { |
| 777 | mState.activeSampler = active; |
| 778 | } |
| 779 | |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 780 | GLuint Context::getReadFramebufferHandle() const |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 781 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 782 | return mState.readFramebuffer; |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | GLuint Context::getDrawFramebufferHandle() const |
| 786 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 787 | return mState.drawFramebuffer; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | GLuint Context::getRenderbufferHandle() const |
| 791 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 792 | return mState.renderbuffer.id(); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | GLuint Context::getArrayBufferHandle() const |
| 796 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 797 | return mState.arrayBuffer.id(); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 798 | } |
| 799 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 800 | void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 801 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 802 | mState.vertexAttribute[attribNum].mArrayEnabled = enabled; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 803 | } |
| 804 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 805 | const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 806 | { |
| 807 | return mState.vertexAttribute[attribNum]; |
| 808 | } |
| 809 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 810 | void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, bool normalized, |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 811 | GLsizei stride, const void *pointer) |
| 812 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 813 | mState.vertexAttribute[attribNum].mBoundBuffer.set(boundBuffer); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 814 | mState.vertexAttribute[attribNum].mSize = size; |
| 815 | mState.vertexAttribute[attribNum].mType = type; |
| 816 | mState.vertexAttribute[attribNum].mNormalized = normalized; |
| 817 | mState.vertexAttribute[attribNum].mStride = stride; |
| 818 | mState.vertexAttribute[attribNum].mPointer = pointer; |
| 819 | } |
| 820 | |
| 821 | const void *Context::getVertexAttribPointer(unsigned int attribNum) const |
| 822 | { |
| 823 | return mState.vertexAttribute[attribNum].mPointer; |
| 824 | } |
| 825 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 826 | const VertexAttributeArray &Context::getVertexAttributes() |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 827 | { |
| 828 | return mState.vertexAttribute; |
| 829 | } |
| 830 | |
| 831 | void Context::setPackAlignment(GLint alignment) |
| 832 | { |
| 833 | mState.packAlignment = alignment; |
| 834 | } |
| 835 | |
| 836 | GLint Context::getPackAlignment() const |
| 837 | { |
| 838 | return mState.packAlignment; |
| 839 | } |
| 840 | |
| 841 | void Context::setUnpackAlignment(GLint alignment) |
| 842 | { |
| 843 | mState.unpackAlignment = alignment; |
| 844 | } |
| 845 | |
| 846 | GLint Context::getUnpackAlignment() const |
| 847 | { |
| 848 | return mState.unpackAlignment; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 849 | } |
| 850 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 851 | GLuint Context::createBuffer() |
| 852 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 853 | return mResourceManager->createBuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 854 | } |
| 855 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 856 | GLuint Context::createProgram() |
| 857 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 858 | return mResourceManager->createProgram(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 859 | } |
| 860 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 861 | GLuint Context::createShader(GLenum type) |
| 862 | { |
| 863 | return mResourceManager->createShader(type); |
| 864 | } |
| 865 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 866 | GLuint Context::createTexture() |
| 867 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 868 | return mResourceManager->createTexture(); |
| 869 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 870 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 871 | GLuint Context::createRenderbuffer() |
| 872 | { |
| 873 | return mResourceManager->createRenderbuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 874 | } |
| 875 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 876 | // Returns an unused framebuffer name |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 877 | GLuint Context::createFramebuffer() |
| 878 | { |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 879 | GLuint handle = mFramebufferHandleAllocator.allocate(); |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 880 | |
| 881 | mFramebufferMap[handle] = NULL; |
| 882 | |
| 883 | return handle; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 884 | } |
| 885 | |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 886 | GLuint Context::createFence() |
| 887 | { |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 888 | GLuint handle = mFenceHandleAllocator.allocate(); |
daniel@transgaming.com | fe20888 | 2010-09-01 15:47:57 +0000 | [diff] [blame] | 889 | |
| 890 | mFenceMap[handle] = new Fence; |
| 891 | |
| 892 | return handle; |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 893 | } |
| 894 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 895 | void Context::deleteBuffer(GLuint buffer) |
| 896 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 897 | if (mResourceManager->getBuffer(buffer)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 898 | { |
| 899 | detachBuffer(buffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 900 | } |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 901 | |
| 902 | mResourceManager->deleteBuffer(buffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void Context::deleteShader(GLuint shader) |
| 906 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 907 | mResourceManager->deleteShader(shader); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | void Context::deleteProgram(GLuint program) |
| 911 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 912 | mResourceManager->deleteProgram(program); |
jbauman@chromium.org | c620985 | 2011-10-07 15:19:26 +0000 | [diff] [blame] | 913 | mCachedCurrentProgram = NULL; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | void Context::deleteTexture(GLuint texture) |
| 917 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 918 | if (mResourceManager->getTexture(texture)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 919 | { |
| 920 | detachTexture(texture); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 921 | } |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 922 | |
| 923 | mResourceManager->deleteTexture(texture); |
| 924 | } |
| 925 | |
| 926 | void Context::deleteRenderbuffer(GLuint renderbuffer) |
| 927 | { |
| 928 | if (mResourceManager->getRenderbuffer(renderbuffer)) |
| 929 | { |
| 930 | detachRenderbuffer(renderbuffer); |
| 931 | } |
| 932 | |
| 933 | mResourceManager->deleteRenderbuffer(renderbuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | void Context::deleteFramebuffer(GLuint framebuffer) |
| 937 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 938 | FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); |
| 939 | |
| 940 | if (framebufferObject != mFramebufferMap.end()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 941 | { |
| 942 | detachFramebuffer(framebuffer); |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 943 | |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 944 | mFramebufferHandleAllocator.release(framebufferObject->first); |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 945 | delete framebufferObject->second; |
| 946 | mFramebufferMap.erase(framebufferObject); |
| 947 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 948 | } |
daniel@transgaming.com | fe20888 | 2010-09-01 15:47:57 +0000 | [diff] [blame] | 949 | |
| 950 | void Context::deleteFence(GLuint fence) |
| 951 | { |
| 952 | FenceMap::iterator fenceObject = mFenceMap.find(fence); |
| 953 | |
| 954 | if (fenceObject != mFenceMap.end()) |
| 955 | { |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 956 | mFenceHandleAllocator.release(fenceObject->first); |
daniel@transgaming.com | fe20888 | 2010-09-01 15:47:57 +0000 | [diff] [blame] | 957 | delete fenceObject->second; |
| 958 | mFenceMap.erase(fenceObject); |
| 959 | } |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 960 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 961 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 962 | Buffer *Context::getBuffer(GLuint handle) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 963 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 964 | return mResourceManager->getBuffer(handle); |
| 965 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 966 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 967 | Shader *Context::getShader(GLuint handle) |
| 968 | { |
| 969 | return mResourceManager->getShader(handle); |
| 970 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 971 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 972 | Program *Context::getProgram(GLuint handle) |
| 973 | { |
| 974 | return mResourceManager->getProgram(handle); |
| 975 | } |
| 976 | |
| 977 | Texture *Context::getTexture(GLuint handle) |
| 978 | { |
| 979 | return mResourceManager->getTexture(handle); |
| 980 | } |
| 981 | |
| 982 | Renderbuffer *Context::getRenderbuffer(GLuint handle) |
| 983 | { |
| 984 | return mResourceManager->getRenderbuffer(handle); |
| 985 | } |
| 986 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 987 | Framebuffer *Context::getReadFramebuffer() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 988 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 989 | return getFramebuffer(mState.readFramebuffer); |
| 990 | } |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 991 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 992 | Framebuffer *Context::getDrawFramebuffer() |
| 993 | { |
jbauman@chromium.org | 040c4db | 2011-10-13 21:35:52 +0000 | [diff] [blame] | 994 | return mBoundDrawFramebuffer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | void Context::bindArrayBuffer(unsigned int buffer) |
| 998 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 999 | mResourceManager->checkBufferAllocation(buffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1000 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1001 | mState.arrayBuffer.set(getBuffer(buffer)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | void Context::bindElementArrayBuffer(unsigned int buffer) |
| 1005 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1006 | mResourceManager->checkBufferAllocation(buffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1007 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1008 | mState.elementArrayBuffer.set(getBuffer(buffer)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | void Context::bindTexture2D(GLuint texture) |
| 1012 | { |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1013 | mResourceManager->checkTextureAllocation(texture, TEXTURE_2D); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1014 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1015 | mState.samplerTexture[TEXTURE_2D][mState.activeSampler].set(getTexture(texture)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | void Context::bindTextureCubeMap(GLuint texture) |
| 1019 | { |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1020 | mResourceManager->checkTextureAllocation(texture, TEXTURE_CUBE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1021 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1022 | mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].set(getTexture(texture)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1025 | void Context::bindReadFramebuffer(GLuint framebuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1026 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 1027 | if (!getFramebuffer(framebuffer)) |
| 1028 | { |
| 1029 | mFramebufferMap[framebuffer] = new Framebuffer(); |
| 1030 | } |
| 1031 | |
| 1032 | mState.readFramebuffer = framebuffer; |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | void Context::bindDrawFramebuffer(GLuint framebuffer) |
| 1036 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 1037 | if (!getFramebuffer(framebuffer)) |
| 1038 | { |
| 1039 | mFramebufferMap[framebuffer] = new Framebuffer(); |
| 1040 | } |
| 1041 | |
| 1042 | mState.drawFramebuffer = framebuffer; |
jbauman@chromium.org | 040c4db | 2011-10-13 21:35:52 +0000 | [diff] [blame] | 1043 | |
| 1044 | mBoundDrawFramebuffer = getFramebuffer(framebuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | void Context::bindRenderbuffer(GLuint renderbuffer) |
| 1048 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1049 | mResourceManager->checkRenderbufferAllocation(renderbuffer); |
| 1050 | |
| 1051 | mState.renderbuffer.set(getRenderbuffer(renderbuffer)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | void Context::useProgram(GLuint program) |
| 1055 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1056 | GLuint priorProgram = mState.currentProgram; |
| 1057 | 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] | 1058 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1059 | if (priorProgram != program) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1060 | { |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1061 | Program *newProgram = mResourceManager->getProgram(program); |
| 1062 | Program *oldProgram = mResourceManager->getProgram(priorProgram); |
jbauman@chromium.org | c620985 | 2011-10-07 15:19:26 +0000 | [diff] [blame] | 1063 | mCachedCurrentProgram = NULL; |
jbauman@chromium.org | 54f59ef | 2011-10-12 17:03:34 +0000 | [diff] [blame] | 1064 | mDxUniformsDirty = true; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1065 | |
| 1066 | if (newProgram) |
| 1067 | { |
| 1068 | newProgram->addRef(); |
| 1069 | } |
| 1070 | |
| 1071 | if (oldProgram) |
| 1072 | { |
| 1073 | oldProgram->release(); |
| 1074 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1075 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | void Context::setFramebufferZero(Framebuffer *buffer) |
| 1079 | { |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 1080 | delete mFramebufferMap[0]; |
| 1081 | mFramebufferMap[0] = buffer; |
jbauman@chromium.org | 040c4db | 2011-10-13 21:35:52 +0000 | [diff] [blame] | 1082 | if (mState.drawFramebuffer == 0) |
| 1083 | { |
| 1084 | mBoundDrawFramebuffer = buffer; |
| 1085 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1088 | void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1089 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1090 | Renderbuffer *renderbufferObject = mState.renderbuffer.get(); |
| 1091 | renderbufferObject->setStorage(renderbuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 1094 | Framebuffer *Context::getFramebuffer(unsigned int handle) |
| 1095 | { |
| 1096 | FramebufferMap::iterator framebuffer = mFramebufferMap.find(handle); |
| 1097 | |
| 1098 | if (framebuffer == mFramebufferMap.end()) |
| 1099 | { |
| 1100 | return NULL; |
| 1101 | } |
| 1102 | else |
| 1103 | { |
| 1104 | return framebuffer->second; |
| 1105 | } |
| 1106 | } |
| 1107 | |
daniel@transgaming.com | fe20888 | 2010-09-01 15:47:57 +0000 | [diff] [blame] | 1108 | Fence *Context::getFence(unsigned int handle) |
| 1109 | { |
| 1110 | FenceMap::iterator fence = mFenceMap.find(handle); |
| 1111 | |
| 1112 | if (fence == mFenceMap.end()) |
| 1113 | { |
| 1114 | return NULL; |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | return fence->second; |
| 1119 | } |
| 1120 | } |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 1121 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1122 | Buffer *Context::getArrayBuffer() |
| 1123 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1124 | return mState.arrayBuffer.get(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | Buffer *Context::getElementArrayBuffer() |
| 1128 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1129 | return mState.elementArrayBuffer.get(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | Program *Context::getCurrentProgram() |
| 1133 | { |
jbauman@chromium.org | c620985 | 2011-10-07 15:19:26 +0000 | [diff] [blame] | 1134 | if (!mCachedCurrentProgram) |
| 1135 | { |
| 1136 | mCachedCurrentProgram = mResourceManager->getProgram(mState.currentProgram); |
| 1137 | } |
| 1138 | return mCachedCurrentProgram; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | Texture2D *Context::getTexture2D() |
| 1142 | { |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1143 | return static_cast<Texture2D*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | TextureCubeMap *Context::getTextureCubeMap() |
| 1147 | { |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1148 | return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1151 | Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1152 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1153 | GLuint texid = mState.samplerTexture[type][sampler].id(); |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 1154 | |
daniel@transgaming.com | a5a8a0a | 2010-11-19 14:55:32 +0000 | [diff] [blame] | 1155 | if (texid == 0) // Special case: 0 refers to different initial textures based on the target |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 1156 | { |
| 1157 | switch (type) |
| 1158 | { |
| 1159 | default: UNREACHABLE(); |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1160 | case TEXTURE_2D: return mTexture2DZero.get(); |
| 1161 | case TEXTURE_CUBE: return mTextureCubeMapZero.get(); |
daniel@transgaming.com | 4195fc4 | 2010-04-08 03:51:09 +0000 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1165 | return mState.samplerTexture[type][sampler].get(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1168 | bool Context::getBooleanv(GLenum pname, GLboolean *params) |
| 1169 | { |
| 1170 | switch (pname) |
| 1171 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1172 | case GL_SHADER_COMPILER: *params = GL_TRUE; break; |
| 1173 | case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break; |
| 1174 | case GL_DEPTH_WRITEMASK: *params = mState.depthMask; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1175 | case GL_COLOR_WRITEMASK: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1176 | params[0] = mState.colorMaskRed; |
| 1177 | params[1] = mState.colorMaskGreen; |
| 1178 | params[2] = mState.colorMaskBlue; |
| 1179 | params[3] = mState.colorMaskAlpha; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1180 | break; |
daniel@transgaming.com | 9d7fc1d | 2010-10-27 15:49:42 +0000 | [diff] [blame] | 1181 | case GL_CULL_FACE: *params = mState.cullFace; break; |
| 1182 | case GL_POLYGON_OFFSET_FILL: *params = mState.polygonOffsetFill; break; |
| 1183 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.sampleAlphaToCoverage; break; |
| 1184 | case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; break; |
| 1185 | case GL_SCISSOR_TEST: *params = mState.scissorTest; break; |
| 1186 | case GL_STENCIL_TEST: *params = mState.stencilTest; break; |
| 1187 | case GL_DEPTH_TEST: *params = mState.depthTest; break; |
| 1188 | case GL_BLEND: *params = mState.blend; break; |
| 1189 | case GL_DITHER: *params = mState.dither; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1190 | default: |
| 1191 | return false; |
| 1192 | } |
| 1193 | |
| 1194 | return true; |
| 1195 | } |
| 1196 | |
| 1197 | bool Context::getFloatv(GLenum pname, GLfloat *params) |
| 1198 | { |
| 1199 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1200 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1201 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1202 | // case, this should make no difference to the calling application. |
| 1203 | switch (pname) |
| 1204 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1205 | case GL_LINE_WIDTH: *params = mState.lineWidth; break; |
| 1206 | case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break; |
| 1207 | case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break; |
| 1208 | case GL_POLYGON_OFFSET_FACTOR: *params = mState.polygonOffsetFactor; break; |
| 1209 | case GL_POLYGON_OFFSET_UNITS: *params = mState.polygonOffsetUnits; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1210 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1211 | params[0] = gl::ALIASED_LINE_WIDTH_RANGE_MIN; |
| 1212 | params[1] = gl::ALIASED_LINE_WIDTH_RANGE_MAX; |
| 1213 | break; |
| 1214 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1215 | params[0] = gl::ALIASED_POINT_SIZE_RANGE_MIN; |
daniel@transgaming.com | be5a086 | 2010-07-28 19:20:37 +0000 | [diff] [blame] | 1216 | params[1] = supportsShaderModel3() ? gl::ALIASED_POINT_SIZE_RANGE_MAX_SM3 : gl::ALIASED_POINT_SIZE_RANGE_MAX_SM2; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1217 | break; |
| 1218 | case GL_DEPTH_RANGE: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1219 | params[0] = mState.zNear; |
| 1220 | params[1] = mState.zFar; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1221 | break; |
| 1222 | case GL_COLOR_CLEAR_VALUE: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1223 | params[0] = mState.colorClearValue.red; |
| 1224 | params[1] = mState.colorClearValue.green; |
| 1225 | params[2] = mState.colorClearValue.blue; |
| 1226 | params[3] = mState.colorClearValue.alpha; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1227 | break; |
daniel@transgaming.com | c164135 | 2010-04-26 15:33:36 +0000 | [diff] [blame] | 1228 | case GL_BLEND_COLOR: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1229 | params[0] = mState.blendColor.red; |
| 1230 | params[1] = mState.blendColor.green; |
| 1231 | params[2] = mState.blendColor.blue; |
| 1232 | params[3] = mState.blendColor.alpha; |
daniel@transgaming.com | c164135 | 2010-04-26 15:33:36 +0000 | [diff] [blame] | 1233 | break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1234 | default: |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | return true; |
| 1239 | } |
| 1240 | |
| 1241 | bool Context::getIntegerv(GLenum pname, GLint *params) |
| 1242 | { |
| 1243 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1244 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1245 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1246 | // case, this should make no difference to the calling application. You may find it in |
| 1247 | // Context::getFloatv. |
| 1248 | switch (pname) |
| 1249 | { |
| 1250 | case GL_MAX_VERTEX_ATTRIBS: *params = gl::MAX_VERTEX_ATTRIBS; break; |
| 1251 | case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = gl::MAX_VERTEX_UNIFORM_VECTORS; break; |
daniel@transgaming.com | 396c643 | 2010-11-26 16:26:12 +0000 | [diff] [blame] | 1252 | case GL_MAX_VARYING_VECTORS: *params = getMaximumVaryingVectors(); break; |
daniel@transgaming.com | af29cac | 2011-05-11 15:36:31 +0000 | [diff] [blame] | 1253 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = getMaximumCombinedTextureImageUnits(); break; |
| 1254 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = getMaximumVertexTextureImageUnits(); break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1255 | case GL_MAX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_TEXTURE_IMAGE_UNITS; break; |
daniel@transgaming.com | 458da14 | 2010-11-28 02:03:02 +0000 | [diff] [blame] | 1256 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = getMaximumFragmentUniformVectors(); break; |
daniel@transgaming.com | 5d752f2 | 2010-10-07 13:37:20 +0000 | [diff] [blame] | 1257 | case GL_MAX_RENDERBUFFER_SIZE: *params = getMaximumRenderbufferDimension(); break; |
daniel@transgaming.com | b28a23b | 2010-05-20 19:18:06 +0000 | [diff] [blame] | 1258 | case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break; |
daniel@transgaming.com | b28a23b | 2010-05-20 19:18:06 +0000 | [diff] [blame] | 1259 | case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ break; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1260 | case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break; |
| 1261 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = mState.elementArrayBuffer.id(); break; |
daniel@transgaming.com | 9d7fc1d | 2010-10-27 15:49:42 +0000 | [diff] [blame] | 1262 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1263 | case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; break; |
| 1264 | case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; break; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1265 | case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.id(); break; |
daniel@transgaming.com | b28a23b | 2010-05-20 19:18:06 +0000 | [diff] [blame] | 1266 | case GL_CURRENT_PROGRAM: *params = mState.currentProgram; break; |
| 1267 | case GL_PACK_ALIGNMENT: *params = mState.packAlignment; break; |
| 1268 | case GL_UNPACK_ALIGNMENT: *params = mState.unpackAlignment; break; |
| 1269 | case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; break; |
alokp@chromium.org | d303ef9 | 2010-09-09 17:30:15 +0000 | [diff] [blame] | 1270 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; break; |
daniel@transgaming.com | b28a23b | 2010-05-20 19:18:06 +0000 | [diff] [blame] | 1271 | case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); break; |
| 1272 | case GL_STENCIL_FUNC: *params = mState.stencilFunc; break; |
| 1273 | case GL_STENCIL_REF: *params = mState.stencilRef; break; |
| 1274 | case GL_STENCIL_VALUE_MASK: *params = mState.stencilMask; break; |
| 1275 | case GL_STENCIL_BACK_FUNC: *params = mState.stencilBackFunc; break; |
| 1276 | case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; break; |
| 1277 | case GL_STENCIL_BACK_VALUE_MASK: *params = mState.stencilBackMask; break; |
| 1278 | case GL_STENCIL_FAIL: *params = mState.stencilFail; break; |
| 1279 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.stencilPassDepthFail; break; |
| 1280 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.stencilPassDepthPass; break; |
| 1281 | case GL_STENCIL_BACK_FAIL: *params = mState.stencilBackFail; break; |
| 1282 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.stencilBackPassDepthFail; break; |
| 1283 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.stencilBackPassDepthPass; break; |
| 1284 | case GL_DEPTH_FUNC: *params = mState.depthFunc; break; |
| 1285 | case GL_BLEND_SRC_RGB: *params = mState.sourceBlendRGB; break; |
| 1286 | case GL_BLEND_SRC_ALPHA: *params = mState.sourceBlendAlpha; break; |
| 1287 | case GL_BLEND_DST_RGB: *params = mState.destBlendRGB; break; |
| 1288 | case GL_BLEND_DST_ALPHA: *params = mState.destBlendAlpha; break; |
| 1289 | case GL_BLEND_EQUATION_RGB: *params = mState.blendEquationRGB; break; |
| 1290 | case GL_BLEND_EQUATION_ALPHA: *params = mState.blendEquationAlpha; break; |
| 1291 | case GL_STENCIL_WRITEMASK: *params = mState.stencilWritemask; break; |
| 1292 | case GL_STENCIL_BACK_WRITEMASK: *params = mState.stencilBackWritemask; break; |
| 1293 | case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; break; |
| 1294 | case GL_SUBPIXEL_BITS: *params = 4; break; |
daniel@transgaming.com | 5d752f2 | 2010-10-07 13:37:20 +0000 | [diff] [blame] | 1295 | case GL_MAX_TEXTURE_SIZE: *params = getMaximumTextureDimension(); break; |
| 1296 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = getMaximumCubeTextureDimension(); break; |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1297 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 1298 | params[0] = mNumCompressedTextureFormats; |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1299 | break; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1300 | case GL_MAX_SAMPLES_ANGLE: |
| 1301 | { |
| 1302 | GLsizei maxSamples = getMaxSupportedSamples(); |
| 1303 | if (maxSamples != 0) |
| 1304 | { |
| 1305 | *params = maxSamples; |
| 1306 | } |
| 1307 | else |
| 1308 | { |
| 1309 | return false; |
| 1310 | } |
| 1311 | |
| 1312 | break; |
| 1313 | } |
| 1314 | case GL_SAMPLE_BUFFERS: |
| 1315 | case GL_SAMPLES: |
| 1316 | { |
| 1317 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1318 | if (framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE) |
| 1319 | { |
| 1320 | switch (pname) |
| 1321 | { |
| 1322 | case GL_SAMPLE_BUFFERS: |
| 1323 | if (framebuffer->getSamples() != 0) |
| 1324 | { |
| 1325 | *params = 1; |
| 1326 | } |
| 1327 | else |
| 1328 | { |
| 1329 | *params = 0; |
| 1330 | } |
| 1331 | break; |
| 1332 | case GL_SAMPLES: |
| 1333 | *params = framebuffer->getSamples(); |
| 1334 | break; |
| 1335 | } |
| 1336 | } |
| 1337 | else |
| 1338 | { |
| 1339 | *params = 0; |
| 1340 | } |
| 1341 | } |
| 1342 | break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1343 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: *params = gl::IMPLEMENTATION_COLOR_READ_TYPE; break; |
| 1344 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: *params = gl::IMPLEMENTATION_COLOR_READ_FORMAT; break; |
| 1345 | case GL_MAX_VIEWPORT_DIMS: |
| 1346 | { |
daniel@transgaming.com | 5d752f2 | 2010-10-07 13:37:20 +0000 | [diff] [blame] | 1347 | int maxDimension = std::max(getMaximumRenderbufferDimension(), getMaximumTextureDimension()); |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1348 | params[0] = maxDimension; |
| 1349 | params[1] = maxDimension; |
| 1350 | } |
| 1351 | break; |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1352 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 1353 | { |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 1354 | if (supportsDXT1Textures()) |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1355 | { |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 1356 | *params++ = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
| 1357 | *params++ = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; |
| 1358 | } |
| 1359 | if (supportsDXT3Textures()) |
| 1360 | { |
| 1361 | *params++ = GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE; |
| 1362 | } |
| 1363 | if (supportsDXT5Textures()) |
| 1364 | { |
| 1365 | *params++ = GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE; |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1369 | case GL_VIEWPORT: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1370 | params[0] = mState.viewportX; |
| 1371 | params[1] = mState.viewportY; |
| 1372 | params[2] = mState.viewportWidth; |
| 1373 | params[3] = mState.viewportHeight; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1374 | break; |
| 1375 | case GL_SCISSOR_BOX: |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1376 | params[0] = mState.scissorX; |
| 1377 | params[1] = mState.scissorY; |
| 1378 | params[2] = mState.scissorWidth; |
| 1379 | params[3] = mState.scissorHeight; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1380 | break; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1381 | case GL_CULL_FACE_MODE: *params = mState.cullMode; break; |
| 1382 | case GL_FRONT_FACE: *params = mState.frontFace; break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1383 | case GL_RED_BITS: |
| 1384 | case GL_GREEN_BITS: |
| 1385 | case GL_BLUE_BITS: |
| 1386 | case GL_ALPHA_BITS: |
| 1387 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1388 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 1389 | gl::Renderbuffer *colorbuffer = framebuffer->getColorbuffer(); |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1390 | |
| 1391 | if (colorbuffer) |
| 1392 | { |
| 1393 | switch (pname) |
| 1394 | { |
| 1395 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1396 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1397 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1398 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1399 | } |
| 1400 | } |
| 1401 | else |
| 1402 | { |
| 1403 | *params = 0; |
| 1404 | } |
| 1405 | } |
| 1406 | break; |
| 1407 | case GL_DEPTH_BITS: |
| 1408 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1409 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 1410 | gl::Renderbuffer *depthbuffer = framebuffer->getDepthbuffer(); |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1411 | |
| 1412 | if (depthbuffer) |
| 1413 | { |
| 1414 | *params = depthbuffer->getDepthSize(); |
| 1415 | } |
| 1416 | else |
| 1417 | { |
| 1418 | *params = 0; |
| 1419 | } |
| 1420 | } |
| 1421 | break; |
| 1422 | case GL_STENCIL_BITS: |
| 1423 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1424 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 1425 | gl::Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer(); |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1426 | |
| 1427 | if (stencilbuffer) |
| 1428 | { |
| 1429 | *params = stencilbuffer->getStencilSize(); |
| 1430 | } |
| 1431 | else |
| 1432 | { |
| 1433 | *params = 0; |
| 1434 | } |
| 1435 | } |
| 1436 | break; |
| 1437 | case GL_TEXTURE_BINDING_2D: |
| 1438 | { |
daniel@transgaming.com | 3f74c7a | 2011-05-11 15:36:51 +0000 | [diff] [blame] | 1439 | if (mState.activeSampler < 0 || mState.activeSampler > getMaximumCombinedTextureImageUnits() - 1) |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1440 | { |
| 1441 | error(GL_INVALID_OPERATION); |
| 1442 | return false; |
| 1443 | } |
| 1444 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1445 | *params = mState.samplerTexture[TEXTURE_2D][mState.activeSampler].id(); |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1446 | } |
| 1447 | break; |
| 1448 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1449 | { |
daniel@transgaming.com | 3f74c7a | 2011-05-11 15:36:51 +0000 | [diff] [blame] | 1450 | if (mState.activeSampler < 0 || mState.activeSampler > getMaximumCombinedTextureImageUnits() - 1) |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1451 | { |
| 1452 | error(GL_INVALID_OPERATION); |
| 1453 | return false; |
| 1454 | } |
| 1455 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 1456 | *params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].id(); |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1457 | } |
| 1458 | break; |
| 1459 | default: |
| 1460 | return false; |
| 1461 | } |
| 1462 | |
| 1463 | return true; |
| 1464 | } |
| 1465 | |
| 1466 | bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) |
| 1467 | { |
| 1468 | // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation |
| 1469 | // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due |
| 1470 | // to the fact that it is stored internally as a float, and so would require conversion |
| 1471 | // if returned from Context::getIntegerv. Since this conversion is already implemented |
| 1472 | // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we |
| 1473 | // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling |
| 1474 | // application. |
| 1475 | switch (pname) |
| 1476 | { |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 1477 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 1478 | { |
| 1479 | *type = GL_INT; |
| 1480 | *numParams = mNumCompressedTextureFormats; |
| 1481 | } |
| 1482 | break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 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: |
alokp@chromium.org | d303ef9 | 2010-09-09 17:30:15 +0000 | [diff] [blame] | 1506 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1507 | case GL_RED_BITS: |
| 1508 | case GL_GREEN_BITS: |
| 1509 | case GL_BLUE_BITS: |
| 1510 | case GL_ALPHA_BITS: |
| 1511 | case GL_DEPTH_BITS: |
| 1512 | case GL_STENCIL_BITS: |
| 1513 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 1514 | case GL_CULL_FACE_MODE: |
| 1515 | case GL_FRONT_FACE: |
| 1516 | case GL_ACTIVE_TEXTURE: |
| 1517 | case GL_STENCIL_FUNC: |
| 1518 | case GL_STENCIL_VALUE_MASK: |
| 1519 | case GL_STENCIL_REF: |
| 1520 | case GL_STENCIL_FAIL: |
| 1521 | case GL_STENCIL_PASS_DEPTH_FAIL: |
| 1522 | case GL_STENCIL_PASS_DEPTH_PASS: |
| 1523 | case GL_STENCIL_BACK_FUNC: |
| 1524 | case GL_STENCIL_BACK_VALUE_MASK: |
| 1525 | case GL_STENCIL_BACK_REF: |
| 1526 | case GL_STENCIL_BACK_FAIL: |
| 1527 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: |
| 1528 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: |
| 1529 | case GL_DEPTH_FUNC: |
| 1530 | case GL_BLEND_SRC_RGB: |
| 1531 | case GL_BLEND_SRC_ALPHA: |
| 1532 | case GL_BLEND_DST_RGB: |
| 1533 | case GL_BLEND_DST_ALPHA: |
| 1534 | case GL_BLEND_EQUATION_RGB: |
| 1535 | case GL_BLEND_EQUATION_ALPHA: |
| 1536 | case GL_STENCIL_WRITEMASK: |
| 1537 | case GL_STENCIL_BACK_WRITEMASK: |
| 1538 | case GL_STENCIL_CLEAR_VALUE: |
| 1539 | case GL_SUBPIXEL_BITS: |
| 1540 | case GL_MAX_TEXTURE_SIZE: |
| 1541 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 1542 | case GL_SAMPLE_BUFFERS: |
| 1543 | case GL_SAMPLES: |
| 1544 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1545 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1546 | case GL_TEXTURE_BINDING_2D: |
| 1547 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1548 | { |
| 1549 | *type = GL_INT; |
| 1550 | *numParams = 1; |
| 1551 | } |
| 1552 | break; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1553 | case GL_MAX_SAMPLES_ANGLE: |
| 1554 | { |
| 1555 | if (getMaxSupportedSamples() != 0) |
| 1556 | { |
| 1557 | *type = GL_INT; |
| 1558 | *numParams = 1; |
| 1559 | } |
| 1560 | else |
| 1561 | { |
| 1562 | return false; |
| 1563 | } |
| 1564 | } |
| 1565 | break; |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1566 | case GL_MAX_VIEWPORT_DIMS: |
| 1567 | { |
| 1568 | *type = GL_INT; |
| 1569 | *numParams = 2; |
| 1570 | } |
| 1571 | break; |
| 1572 | case GL_VIEWPORT: |
| 1573 | case GL_SCISSOR_BOX: |
| 1574 | { |
| 1575 | *type = GL_INT; |
| 1576 | *numParams = 4; |
| 1577 | } |
| 1578 | break; |
| 1579 | case GL_SHADER_COMPILER: |
| 1580 | case GL_SAMPLE_COVERAGE_INVERT: |
| 1581 | case GL_DEPTH_WRITEMASK: |
daniel@transgaming.com | 79f6677 | 2010-04-13 03:26:09 +0000 | [diff] [blame] | 1582 | case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled, |
| 1583 | case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries. |
| 1584 | case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as bool-natural |
| 1585 | case GL_SAMPLE_COVERAGE: |
| 1586 | case GL_SCISSOR_TEST: |
| 1587 | case GL_STENCIL_TEST: |
| 1588 | case GL_DEPTH_TEST: |
| 1589 | case GL_BLEND: |
| 1590 | case GL_DITHER: |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1591 | { |
| 1592 | *type = GL_BOOL; |
| 1593 | *numParams = 1; |
| 1594 | } |
| 1595 | break; |
| 1596 | case GL_COLOR_WRITEMASK: |
| 1597 | { |
| 1598 | *type = GL_BOOL; |
| 1599 | *numParams = 4; |
| 1600 | } |
| 1601 | break; |
| 1602 | case GL_POLYGON_OFFSET_FACTOR: |
| 1603 | case GL_POLYGON_OFFSET_UNITS: |
| 1604 | case GL_SAMPLE_COVERAGE_VALUE: |
| 1605 | case GL_DEPTH_CLEAR_VALUE: |
| 1606 | case GL_LINE_WIDTH: |
| 1607 | { |
| 1608 | *type = GL_FLOAT; |
| 1609 | *numParams = 1; |
| 1610 | } |
| 1611 | break; |
| 1612 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1613 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1614 | case GL_DEPTH_RANGE: |
| 1615 | { |
| 1616 | *type = GL_FLOAT; |
| 1617 | *numParams = 2; |
| 1618 | } |
| 1619 | break; |
| 1620 | case GL_COLOR_CLEAR_VALUE: |
daniel@transgaming.com | c164135 | 2010-04-26 15:33:36 +0000 | [diff] [blame] | 1621 | case GL_BLEND_COLOR: |
daniel@transgaming.com | 777f267 | 2010-04-07 03:25:16 +0000 | [diff] [blame] | 1622 | { |
| 1623 | *type = GL_FLOAT; |
| 1624 | *numParams = 4; |
| 1625 | } |
| 1626 | break; |
| 1627 | default: |
| 1628 | return false; |
| 1629 | } |
| 1630 | |
| 1631 | return true; |
| 1632 | } |
| 1633 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1634 | // Applies the render target surface, depth stencil surface, viewport rectangle and |
| 1635 | // scissor rectangle to the Direct3D 9 device |
| 1636 | bool Context::applyRenderTarget(bool ignoreViewport) |
| 1637 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1638 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1639 | |
| 1640 | if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1641 | { |
daniel@transgaming.com | b5a3a6b | 2011-03-21 16:38:46 +0000 | [diff] [blame] | 1642 | return error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
jbauman@chromium.org | 8b3c1af | 2011-10-12 01:21:41 +0000 | [diff] [blame] | 1645 | IDirect3DSurface9 *renderTarget = NULL; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1646 | IDirect3DSurface9 *depthStencil = NULL; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1647 | |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1648 | bool renderTargetChanged = false; |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 1649 | unsigned int renderTargetSerial = framebufferObject->getRenderTargetSerial(); |
| 1650 | if (renderTargetSerial != mAppliedRenderTargetSerial) |
| 1651 | { |
jbauman@chromium.org | 8b3c1af | 2011-10-12 01:21:41 +0000 | [diff] [blame] | 1652 | renderTarget = framebufferObject->getRenderTarget(); |
| 1653 | |
| 1654 | if (!renderTarget) |
| 1655 | { |
| 1656 | return false; // Context must be lost |
| 1657 | } |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1658 | mDevice->SetRenderTarget(0, renderTarget); |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 1659 | mAppliedRenderTargetSerial = renderTargetSerial; |
daniel@transgaming.com | bc3699d | 2010-08-05 14:48:49 +0000 | [diff] [blame] | 1660 | mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets. |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1661 | renderTargetChanged = true; |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1664 | unsigned int depthbufferSerial = 0; |
| 1665 | unsigned int stencilbufferSerial = 0; |
| 1666 | if (framebufferObject->getDepthbufferType() != GL_NONE) |
| 1667 | { |
| 1668 | depthStencil = framebufferObject->getDepthbuffer()->getDepthStencil(); |
apatrick@chromium.org | b2bdd06 | 2010-10-05 02:24:30 +0000 | [diff] [blame] | 1669 | if (!depthStencil) |
| 1670 | { |
| 1671 | ERR("Depth stencil pointer unexpectedly null."); |
| 1672 | return false; |
| 1673 | } |
| 1674 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1675 | depthbufferSerial = framebufferObject->getDepthbuffer()->getSerial(); |
| 1676 | } |
| 1677 | else if (framebufferObject->getStencilbufferType() != GL_NONE) |
| 1678 | { |
| 1679 | depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil(); |
apatrick@chromium.org | b2bdd06 | 2010-10-05 02:24:30 +0000 | [diff] [blame] | 1680 | if (!depthStencil) |
| 1681 | { |
| 1682 | ERR("Depth stencil pointer unexpectedly null."); |
| 1683 | return false; |
| 1684 | } |
| 1685 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1686 | stencilbufferSerial = framebufferObject->getStencilbuffer()->getSerial(); |
| 1687 | } |
| 1688 | |
| 1689 | if (depthbufferSerial != mAppliedDepthbufferSerial || |
apatrick@chromium.org | 85dc42b | 2010-09-14 03:10:08 +0000 | [diff] [blame] | 1690 | stencilbufferSerial != mAppliedStencilbufferSerial || |
vangelis@chromium.org | cf66ebb | 2010-09-14 22:15:43 +0000 | [diff] [blame] | 1691 | !mDepthStencilInitialized) |
daniel@transgaming.com | 339ae70 | 2010-05-12 03:40:20 +0000 | [diff] [blame] | 1692 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1693 | mDevice->SetDepthStencilSurface(depthStencil); |
daniel@transgaming.com | 339ae70 | 2010-05-12 03:40:20 +0000 | [diff] [blame] | 1694 | mAppliedDepthbufferSerial = depthbufferSerial; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1695 | mAppliedStencilbufferSerial = stencilbufferSerial; |
vangelis@chromium.org | cf66ebb | 2010-09-14 22:15:43 +0000 | [diff] [blame] | 1696 | mDepthStencilInitialized = true; |
daniel@transgaming.com | 339ae70 | 2010-05-12 03:40:20 +0000 | [diff] [blame] | 1697 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1698 | |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1699 | if (!mRenderTargetDescInitialized || renderTargetChanged) |
| 1700 | { |
jbauman@chromium.org | 8b3c1af | 2011-10-12 01:21:41 +0000 | [diff] [blame] | 1701 | if (!renderTarget) |
| 1702 | { |
| 1703 | renderTarget = framebufferObject->getRenderTarget(); |
| 1704 | |
| 1705 | if (!renderTarget) |
| 1706 | { |
| 1707 | return false; // Context must be lost |
| 1708 | } |
| 1709 | } |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1710 | renderTarget->GetDesc(&mRenderTargetDesc); |
| 1711 | mRenderTargetDescInitialized = true; |
| 1712 | } |
| 1713 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1714 | D3DVIEWPORT9 viewport; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1715 | |
daniel@transgaming.com | 996675c | 2010-11-17 13:06:29 +0000 | [diff] [blame] | 1716 | float zNear = clamp01(mState.zNear); |
| 1717 | float zFar = clamp01(mState.zFar); |
| 1718 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1719 | if (ignoreViewport) |
| 1720 | { |
| 1721 | viewport.X = 0; |
| 1722 | viewport.Y = 0; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1723 | viewport.Width = mRenderTargetDesc.Width; |
| 1724 | viewport.Height = mRenderTargetDesc.Height; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1725 | viewport.MinZ = 0.0f; |
| 1726 | viewport.MaxZ = 1.0f; |
| 1727 | } |
| 1728 | else |
| 1729 | { |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1730 | RECT rect = transformPixelRect(mState.viewportX, mState.viewportY, mState.viewportWidth, mState.viewportHeight, mRenderTargetDesc.Height); |
| 1731 | viewport.X = clamp(rect.left, 0L, static_cast<LONG>(mRenderTargetDesc.Width)); |
| 1732 | viewport.Y = clamp(rect.top, 0L, static_cast<LONG>(mRenderTargetDesc.Height)); |
| 1733 | viewport.Width = clamp(rect.right - rect.left, 0L, static_cast<LONG>(mRenderTargetDesc.Width) - static_cast<LONG>(viewport.X)); |
| 1734 | viewport.Height = clamp(rect.bottom - rect.top, 0L, static_cast<LONG>(mRenderTargetDesc.Height) - static_cast<LONG>(viewport.Y)); |
daniel@transgaming.com | 996675c | 2010-11-17 13:06:29 +0000 | [diff] [blame] | 1735 | viewport.MinZ = zNear; |
| 1736 | viewport.MaxZ = zFar; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
daniel@transgaming.com | baeb8c5 | 2010-05-05 18:50:39 +0000 | [diff] [blame] | 1739 | if (viewport.Width <= 0 || viewport.Height <= 0) |
| 1740 | { |
| 1741 | return false; // Nothing to render |
| 1742 | } |
| 1743 | |
jbauman@chromium.org | 241e70d | 2011-11-03 23:07:05 +0000 | [diff] [blame] | 1744 | if (renderTargetChanged || !mViewportInitialized || memcmp(&viewport, &mSetViewport, sizeof mSetViewport) != 0) |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1745 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1746 | mDevice->SetViewport(&viewport); |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1747 | mSetViewport = viewport; |
| 1748 | mViewportInitialized = true; |
jbauman@chromium.org | 54f59ef | 2011-10-12 17:03:34 +0000 | [diff] [blame] | 1749 | mDxUniformsDirty = true; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1750 | } |
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 | if (mScissorStateDirty) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1753 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1754 | if (mState.scissorTest) |
| 1755 | { |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 1756 | RECT rect = transformPixelRect(mState.scissorX, mState.scissorY, mState.scissorWidth, mState.scissorHeight, mRenderTargetDesc.Height); |
| 1757 | rect.left = clamp(rect.left, 0L, static_cast<LONG>(mRenderTargetDesc.Width)); |
| 1758 | rect.top = clamp(rect.top, 0L, static_cast<LONG>(mRenderTargetDesc.Height)); |
| 1759 | rect.right = clamp(rect.right, 0L, static_cast<LONG>(mRenderTargetDesc.Width)); |
| 1760 | rect.bottom = clamp(rect.bottom, 0L, static_cast<LONG>(mRenderTargetDesc.Height)); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1761 | mDevice->SetScissorRect(&rect); |
| 1762 | mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1763 | } |
| 1764 | else |
| 1765 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1766 | mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1767 | } |
daniel@transgaming.com | bc3699d | 2010-08-05 14:48:49 +0000 | [diff] [blame] | 1768 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1769 | mScissorStateDirty = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
jbauman@chromium.org | 54f59ef | 2011-10-12 17:03:34 +0000 | [diff] [blame] | 1772 | if (mState.currentProgram && mDxUniformsDirty) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1773 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1774 | Program *programObject = getCurrentProgram(); |
| 1775 | |
daniel@transgaming.com | 91fd1de | 2010-05-18 18:51:40 +0000 | [diff] [blame] | 1776 | GLint halfPixelSize = programObject->getDxHalfPixelSizeLocation(); |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 1777 | GLfloat xy[2] = {1.0f / viewport.Width, -1.0f / viewport.Height}; |
daniel@transgaming.com | 3175496 | 2010-11-28 02:02:52 +0000 | [diff] [blame] | 1778 | programObject->setUniform2fv(halfPixelSize, 1, xy); |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 1779 | |
daniel@transgaming.com | 3175496 | 2010-11-28 02:02:52 +0000 | [diff] [blame] | 1780 | GLint viewport = programObject->getDxViewportLocation(); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 1781 | GLfloat whxy[4] = {mState.viewportWidth / 2.0f, mState.viewportHeight / 2.0f, |
| 1782 | (float)mState.viewportX + mState.viewportWidth / 2.0f, |
| 1783 | (float)mState.viewportY + mState.viewportHeight / 2.0f}; |
daniel@transgaming.com | 3175496 | 2010-11-28 02:02:52 +0000 | [diff] [blame] | 1784 | programObject->setUniform4fv(viewport, 1, whxy); |
daniel@transgaming.com | 9b5f544 | 2010-03-16 05:43:55 +0000 | [diff] [blame] | 1785 | |
daniel@transgaming.com | 91fd1de | 2010-05-18 18:51:40 +0000 | [diff] [blame] | 1786 | GLint depth = programObject->getDxDepthLocation(); |
daniel@transgaming.com | 996675c | 2010-11-17 13:06:29 +0000 | [diff] [blame] | 1787 | GLfloat dz[2] = {(zFar - zNear) / 2.0f, (zNear + zFar) / 2.0f}; |
daniel@transgaming.com | 3175496 | 2010-11-28 02:02:52 +0000 | [diff] [blame] | 1788 | programObject->setUniform2fv(depth, 1, dz); |
daniel@transgaming.com | 9b5f544 | 2010-03-16 05:43:55 +0000 | [diff] [blame] | 1789 | |
daniel@transgaming.com | 3175496 | 2010-11-28 02:02:52 +0000 | [diff] [blame] | 1790 | GLint depthRange = programObject->getDxDepthRangeLocation(); |
| 1791 | GLfloat nearFarDiff[3] = {zNear, zFar, zFar - zNear}; |
| 1792 | programObject->setUniform3fv(depthRange, 1, nearFarDiff); |
jbauman@chromium.org | 54f59ef | 2011-10-12 17:03:34 +0000 | [diff] [blame] | 1793 | mDxUniformsDirty = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | return true; |
| 1797 | } |
| 1798 | |
| 1799 | // 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] | 1800 | void Context::applyState(GLenum drawMode) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1801 | { |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1802 | Program *programObject = getCurrentProgram(); |
| 1803 | |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 1804 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
| 1805 | |
| 1806 | GLenum adjustedFrontFace = adjustWinding(mState.frontFace); |
| 1807 | |
daniel@transgaming.com | 91fd1de | 2010-05-18 18:51:40 +0000 | [diff] [blame] | 1808 | GLint frontCCW = programObject->getDxFrontCCWLocation(); |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 1809 | GLint ccw = (adjustedFrontFace == GL_CCW); |
daniel@transgaming.com | 79b820b | 2010-03-16 05:48:57 +0000 | [diff] [blame] | 1810 | programObject->setUniform1iv(frontCCW, 1, &ccw); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1811 | |
daniel@transgaming.com | 91fd1de | 2010-05-18 18:51:40 +0000 | [diff] [blame] | 1812 | GLint pointsOrLines = programObject->getDxPointsOrLinesLocation(); |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 1813 | GLint alwaysFront = !isTriangleMode(drawMode); |
| 1814 | programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront); |
| 1815 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1816 | D3DADAPTER_IDENTIFIER9 *identifier = mDisplay->getAdapterIdentifier(); |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 1817 | bool zeroColorMaskAllowed = identifier->VendorId != 0x1002; |
| 1818 | // Apparently some ATI cards have a bug where a draw with a zero color |
| 1819 | // write mask can cause later draws to have incorrect results. Instead, |
| 1820 | // set a nonzero color write mask but modify the blend state so that no |
| 1821 | // drawing is done. |
| 1822 | // http://code.google.com/p/angleproject/issues/detail?id=169 |
| 1823 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1824 | if (mCullStateDirty || mFrontFaceDirty) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1825 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1826 | if (mState.cullFace) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1827 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1828 | mDevice->SetRenderState(D3DRS_CULLMODE, es2dx::ConvertCullMode(mState.cullMode, adjustedFrontFace)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1829 | } |
| 1830 | else |
| 1831 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1832 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1835 | mCullStateDirty = false; |
| 1836 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1837 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1838 | if (mDepthStateDirty) |
| 1839 | { |
daniel@transgaming.com | 317887f | 2011-05-11 15:26:12 +0000 | [diff] [blame] | 1840 | if (mState.depthTest) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1841 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1842 | mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); |
| 1843 | mDevice->SetRenderState(D3DRS_ZFUNC, es2dx::ConvertComparison(mState.depthFunc)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1844 | } |
| 1845 | else |
| 1846 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1847 | mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1848 | } |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1849 | |
| 1850 | mDepthStateDirty = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 1853 | if (!zeroColorMaskAllowed && (mMaskStateDirty || mBlendStateDirty)) |
| 1854 | { |
| 1855 | mBlendStateDirty = true; |
| 1856 | mMaskStateDirty = true; |
| 1857 | } |
| 1858 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1859 | if (mBlendStateDirty) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1860 | { |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1861 | if (mState.blend) |
daniel@transgaming.com | 1436e26 | 2010-03-17 03:58:56 +0000 | [diff] [blame] | 1862 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1863 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1864 | |
| 1865 | if (mState.sourceBlendRGB != GL_CONSTANT_ALPHA && mState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && |
| 1866 | mState.destBlendRGB != GL_CONSTANT_ALPHA && mState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) |
| 1867 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1868 | mDevice->SetRenderState(D3DRS_BLENDFACTOR, es2dx::ConvertColor(mState.blendColor)); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1869 | } |
| 1870 | else |
| 1871 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1872 | mDevice->SetRenderState(D3DRS_BLENDFACTOR, D3DCOLOR_RGBA(unorm<8>(mState.blendColor.alpha), |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1873 | unorm<8>(mState.blendColor.alpha), |
| 1874 | unorm<8>(mState.blendColor.alpha), |
| 1875 | unorm<8>(mState.blendColor.alpha))); |
| 1876 | } |
| 1877 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1878 | mDevice->SetRenderState(D3DRS_SRCBLEND, es2dx::ConvertBlendFunc(mState.sourceBlendRGB)); |
| 1879 | mDevice->SetRenderState(D3DRS_DESTBLEND, es2dx::ConvertBlendFunc(mState.destBlendRGB)); |
| 1880 | mDevice->SetRenderState(D3DRS_BLENDOP, es2dx::ConvertBlendOp(mState.blendEquationRGB)); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1881 | |
| 1882 | if (mState.sourceBlendRGB != mState.sourceBlendAlpha || |
| 1883 | mState.destBlendRGB != mState.destBlendAlpha || |
| 1884 | mState.blendEquationRGB != mState.blendEquationAlpha) |
| 1885 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1886 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1887 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1888 | mDevice->SetRenderState(D3DRS_SRCBLENDALPHA, es2dx::ConvertBlendFunc(mState.sourceBlendAlpha)); |
| 1889 | mDevice->SetRenderState(D3DRS_DESTBLENDALPHA, es2dx::ConvertBlendFunc(mState.destBlendAlpha)); |
| 1890 | mDevice->SetRenderState(D3DRS_BLENDOPALPHA, es2dx::ConvertBlendOp(mState.blendEquationAlpha)); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1891 | } |
| 1892 | else |
| 1893 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1894 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1895 | } |
daniel@transgaming.com | 1436e26 | 2010-03-17 03:58:56 +0000 | [diff] [blame] | 1896 | } |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1897 | else |
daniel@transgaming.com | aede630 | 2010-04-29 03:35:48 +0000 | [diff] [blame] | 1898 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1899 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
daniel@transgaming.com | aede630 | 2010-04-29 03:35:48 +0000 | [diff] [blame] | 1900 | } |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1901 | |
| 1902 | mBlendStateDirty = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1905 | if (mStencilStateDirty || mFrontFaceDirty) |
| 1906 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 1907 | if (mState.stencilTest && framebufferObject->hasStencil()) |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1908 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1909 | mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 1910 | mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1911 | |
| 1912 | // FIXME: Unsupported by D3D9 |
| 1913 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF; |
| 1914 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK; |
| 1915 | const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK; |
| 1916 | if (mState.stencilWritemask != mState.stencilBackWritemask || |
| 1917 | mState.stencilRef != mState.stencilBackRef || |
| 1918 | mState.stencilMask != mState.stencilBackMask) |
| 1919 | { |
| 1920 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL."); |
| 1921 | return error(GL_INVALID_OPERATION); |
| 1922 | } |
| 1923 | |
daniel@transgaming.com | dd7948b | 2010-06-02 16:12:34 +0000 | [diff] [blame] | 1924 | // get the maximum size of the stencil ref |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 1925 | gl::Renderbuffer *stencilbuffer = framebufferObject->getStencilbuffer(); |
daniel@transgaming.com | dd7948b | 2010-06-02 16:12:34 +0000 | [diff] [blame] | 1926 | GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1; |
| 1927 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1928 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask); |
| 1929 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1930 | es2dx::ConvertComparison(mState.stencilFunc)); |
| 1931 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1932 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil); |
| 1933 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilMask); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1934 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1935 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1936 | es2dx::ConvertStencilOp(mState.stencilFail)); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1937 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1938 | es2dx::ConvertStencilOp(mState.stencilPassDepthFail)); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1939 | mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1940 | es2dx::ConvertStencilOp(mState.stencilPassDepthPass)); |
| 1941 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1942 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilBackWritemask); |
| 1943 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1944 | es2dx::ConvertComparison(mState.stencilBackFunc)); |
| 1945 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1946 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil); |
| 1947 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilBackMask); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1948 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1949 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1950 | es2dx::ConvertStencilOp(mState.stencilBackFail)); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1951 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1952 | es2dx::ConvertStencilOp(mState.stencilBackPassDepthFail)); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1953 | mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1954 | es2dx::ConvertStencilOp(mState.stencilBackPassDepthPass)); |
| 1955 | } |
| 1956 | else |
| 1957 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1958 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | mStencilStateDirty = false; |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 1962 | mFrontFaceDirty = false; |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | if (mMaskStateDirty) |
| 1966 | { |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 1967 | int colorMask = es2dx::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, |
| 1968 | mState.colorMaskBlue, mState.colorMaskAlpha); |
| 1969 | if (colorMask == 0 && !zeroColorMaskAllowed) |
| 1970 | { |
| 1971 | // Enable green channel, but set blending so nothing will be drawn. |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1972 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_GREEN); |
| 1973 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 1974 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1975 | mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO); |
| 1976 | mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); |
| 1977 | mDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 1978 | } |
| 1979 | else |
| 1980 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1981 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, colorMask); |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 1982 | } |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1983 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, mState.depthMask ? TRUE : FALSE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1984 | |
| 1985 | mMaskStateDirty = false; |
| 1986 | } |
| 1987 | |
| 1988 | if (mPolygonOffsetStateDirty) |
| 1989 | { |
| 1990 | if (mState.polygonOffsetFill) |
| 1991 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 1992 | gl::Renderbuffer *depthbuffer = framebufferObject->getDepthbuffer(); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1993 | if (depthbuffer) |
| 1994 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1995 | mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor)); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1996 | float depthBias = ldexp(mState.polygonOffsetUnits, -(int)(depthbuffer->getDepthSize())); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 1997 | mDevice->SetRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&depthBias)); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 1998 | } |
| 1999 | } |
| 2000 | else |
| 2001 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2002 | mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, 0); |
| 2003 | mDevice->SetRenderState(D3DRS_DEPTHBIAS, 0); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | mPolygonOffsetStateDirty = false; |
| 2007 | } |
| 2008 | |
enne@chromium.org | c5f8dea | 2010-09-21 16:40:30 +0000 | [diff] [blame] | 2009 | if (mSampleStateDirty) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2010 | { |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2011 | if (mState.sampleAlphaToCoverage) |
daniel@transgaming.com | a87bdf5 | 2010-04-29 03:38:55 +0000 | [diff] [blame] | 2012 | { |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2013 | FIXME("Sample alpha to coverage is unimplemented."); |
| 2014 | } |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 2015 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2016 | mDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2017 | if (mState.sampleCoverage) |
| 2018 | { |
| 2019 | unsigned int mask = 0; |
| 2020 | if (mState.sampleCoverageValue != 0) |
enne@chromium.org | c5f8dea | 2010-09-21 16:40:30 +0000 | [diff] [blame] | 2021 | { |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2022 | float threshold = 0.5f; |
| 2023 | |
| 2024 | for (int i = 0; i < framebufferObject->getSamples(); ++i) |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 2025 | { |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2026 | mask <<= 1; |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 2027 | |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2028 | if ((i + 1) * mState.sampleCoverageValue >= threshold) |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 2029 | { |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2030 | threshold += 1.0f; |
| 2031 | mask |= 1; |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
enne@chromium.org | c5f8dea | 2010-09-21 16:40:30 +0000 | [diff] [blame] | 2034 | } |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2035 | |
| 2036 | if (mState.sampleCoverageInvert) |
enne@chromium.org | c5f8dea | 2010-09-21 16:40:30 +0000 | [diff] [blame] | 2037 | { |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2038 | mask = ~mask; |
enne@chromium.org | c5f8dea | 2010-09-21 16:40:30 +0000 | [diff] [blame] | 2039 | } |
daniel@transgaming.com | 3203c10 | 2011-06-08 12:41:32 +0000 | [diff] [blame] | 2040 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2041 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, mask); |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 2042 | } |
| 2043 | else |
| 2044 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2045 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
daniel@transgaming.com | a87bdf5 | 2010-04-29 03:38:55 +0000 | [diff] [blame] | 2046 | } |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 2047 | |
| 2048 | mSampleStateDirty = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 2051 | if (mDitherStateDirty) |
| 2052 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2053 | mDevice->SetRenderState(D3DRS_DITHERENABLE, mState.dither ? TRUE : FALSE); |
daniel@transgaming.com | a79f9d1 | 2010-05-12 03:40:01 +0000 | [diff] [blame] | 2054 | |
| 2055 | mDitherStateDirty = false; |
| 2056 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 2059 | GLenum Context::applyVertexBuffer(GLint first, GLsizei count) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2060 | { |
daniel@transgaming.com | baa7451 | 2011-04-13 14:56:47 +0000 | [diff] [blame] | 2061 | TranslatedAttribute attributes[MAX_VERTEX_ATTRIBS]; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2062 | |
daniel@transgaming.com | baa7451 | 2011-04-13 14:56:47 +0000 | [diff] [blame] | 2063 | GLenum err = mVertexDataManager->prepareVertexData(first, count, attributes); |
daniel@transgaming.com | 81655a7 | 2010-05-20 19:18:17 +0000 | [diff] [blame] | 2064 | if (err != GL_NO_ERROR) |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 2065 | { |
daniel@transgaming.com | 81655a7 | 2010-05-20 19:18:17 +0000 | [diff] [blame] | 2066 | return err; |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2069 | return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, getCurrentProgram()); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2072 | // 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] | 2073 | 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] | 2074 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 2075 | GLenum err = mIndexDataManager->prepareIndexData(type, count, mState.elementArrayBuffer.get(), indices, indexInfo); |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 2076 | |
daniel@transgaming.com | 81655a7 | 2010-05-20 19:18:17 +0000 | [diff] [blame] | 2077 | if (err == GL_NO_ERROR) |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 2078 | { |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 2079 | if (indexInfo->serial != mAppliedIBSerial) |
| 2080 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2081 | mDevice->SetIndices(indexInfo->indexBuffer); |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 2082 | mAppliedIBSerial = indexInfo->serial; |
| 2083 | } |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
daniel@transgaming.com | 81655a7 | 2010-05-20 19:18:17 +0000 | [diff] [blame] | 2086 | return err; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | // Applies the shaders and shader constants to the Direct3D 9 device |
| 2090 | void Context::applyShaders() |
| 2091 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2092 | Program *programObject = getCurrentProgram(); |
daniel@transgaming.com | a9eb5da | 2011-03-21 16:39:16 +0000 | [diff] [blame] | 2093 | if (programObject->getSerial() != mAppliedProgramSerial) |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 2094 | { |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 2095 | IDirect3DVertexShader9 *vertexShader = programObject->getVertexShader(); |
| 2096 | IDirect3DPixelShader9 *pixelShader = programObject->getPixelShader(); |
| 2097 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2098 | mDevice->SetPixelShader(pixelShader); |
| 2099 | mDevice->SetVertexShader(vertexShader); |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 2100 | programObject->dirtyAllUniforms(); |
daniel@transgaming.com | a9eb5da | 2011-03-21 16:39:16 +0000 | [diff] [blame] | 2101 | mAppliedProgramSerial = programObject->getSerial(); |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2104 | programObject->applyUniforms(); |
| 2105 | } |
| 2106 | |
| 2107 | // Applies the textures and sampler states to the Direct3D 9 device |
| 2108 | void Context::applyTextures() |
| 2109 | { |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2110 | applyTextures(SAMPLER_PIXEL); |
| 2111 | |
| 2112 | if (mSupportsVertexTexture) |
| 2113 | { |
| 2114 | applyTextures(SAMPLER_VERTEX); |
| 2115 | } |
| 2116 | } |
| 2117 | |
daniel@transgaming.com | 9ba680a | 2011-05-11 15:37:11 +0000 | [diff] [blame] | 2118 | // For each Direct3D 9 sampler of either the pixel or vertex stage, |
| 2119 | // looks up the corresponding OpenGL texture image unit and texture type, |
| 2120 | // and sets the texture and its addressing/filtering state (or NULL when inactive). |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2121 | void Context::applyTextures(SamplerType type) |
| 2122 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2123 | Program *programObject = getCurrentProgram(); |
| 2124 | |
daniel@transgaming.com | 9ba680a | 2011-05-11 15:37:11 +0000 | [diff] [blame] | 2125 | int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type |
jbauman@chromium.org | 8b3c1af | 2011-10-12 01:21:41 +0000 | [diff] [blame] | 2126 | unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS; |
| 2127 | int d3dSamplerOffset = (type == SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; |
jbauman@chromium.org | b6e7222 | 2011-10-18 23:01:46 +0000 | [diff] [blame] | 2128 | int samplerRange = programObject->getUsedSamplerRange(type); |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2129 | |
jbauman@chromium.org | b6e7222 | 2011-10-18 23:01:46 +0000 | [diff] [blame] | 2130 | for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2131 | { |
daniel@transgaming.com | 9ba680a | 2011-05-11 15:37:11 +0000 | [diff] [blame] | 2132 | int textureUnit = programObject->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index |
jbauman@chromium.org | 8b3c1af | 2011-10-12 01:21:41 +0000 | [diff] [blame] | 2133 | int d3dSampler = samplerIndex + d3dSamplerOffset; |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2134 | |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2135 | if (textureUnit != -1) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2136 | { |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2137 | TextureType textureType = programObject->getSamplerTextureType(type, samplerIndex); |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2138 | |
| 2139 | Texture *texture = getSamplerTexture(textureUnit, textureType); |
| 2140 | |
daniel@transgaming.com | 0da803b | 2011-11-09 17:44:58 +0000 | [diff] [blame] | 2141 | if (appliedTextureSerial[samplerIndex] != texture->getSerial() || texture->hasDirtyParameters() || texture->hasDirtyImages()) |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 2142 | { |
daniel@transgaming.com | 38e76e5 | 2011-03-21 16:39:10 +0000 | [diff] [blame] | 2143 | IDirect3DBaseTexture9 *d3dTexture = texture->getTexture(); |
| 2144 | |
| 2145 | if (d3dTexture) |
daniel@transgaming.com | 5a0b0a8 | 2010-05-12 03:45:07 +0000 | [diff] [blame] | 2146 | { |
daniel@transgaming.com | 0da803b | 2011-11-09 17:44:58 +0000 | [diff] [blame] | 2147 | if (appliedTextureSerial[samplerIndex] != texture->getSerial() || texture->hasDirtyParameters()) |
daniel@transgaming.com | a06aa87 | 2011-03-21 17:22:21 +0000 | [diff] [blame] | 2148 | { |
| 2149 | GLenum wrapS = texture->getWrapS(); |
| 2150 | GLenum wrapT = texture->getWrapT(); |
| 2151 | GLenum minFilter = texture->getMinFilter(); |
| 2152 | GLenum magFilter = texture->getMagFilter(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2153 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2154 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(wrapS)); |
| 2155 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(wrapT)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2156 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2157 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, es2dx::ConvertMagFilter(magFilter)); |
daniel@transgaming.com | a06aa87 | 2011-03-21 17:22:21 +0000 | [diff] [blame] | 2158 | D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter; |
| 2159 | es2dx::ConvertMinFilter(minFilter, &d3dMinFilter, &d3dMipFilter); |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2160 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter); |
| 2161 | mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter); |
daniel@transgaming.com | a06aa87 | 2011-03-21 17:22:21 +0000 | [diff] [blame] | 2162 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2163 | |
daniel@transgaming.com | 0da803b | 2011-11-09 17:44:58 +0000 | [diff] [blame] | 2164 | if (appliedTextureSerial[samplerIndex] != texture->getSerial() || texture->hasDirtyImages()) |
daniel@transgaming.com | a06aa87 | 2011-03-21 17:22:21 +0000 | [diff] [blame] | 2165 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2166 | mDevice->SetTexture(d3dSampler, d3dTexture); |
daniel@transgaming.com | a06aa87 | 2011-03-21 17:22:21 +0000 | [diff] [blame] | 2167 | } |
daniel@transgaming.com | 5a0b0a8 | 2010-05-12 03:45:07 +0000 | [diff] [blame] | 2168 | } |
| 2169 | else |
| 2170 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2171 | mDevice->SetTexture(d3dSampler, getIncompleteTexture(textureType)->getTexture()); |
daniel@transgaming.com | 5a0b0a8 | 2010-05-12 03:45:07 +0000 | [diff] [blame] | 2172 | } |
daniel@transgaming.com | 5a0b0a8 | 2010-05-12 03:45:07 +0000 | [diff] [blame] | 2173 | |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2174 | appliedTextureSerial[samplerIndex] = texture->getSerial(); |
daniel@transgaming.com | 38e76e5 | 2011-03-21 16:39:10 +0000 | [diff] [blame] | 2175 | texture->resetDirty(); |
| 2176 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2177 | } |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 2178 | else |
| 2179 | { |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2180 | if (appliedTextureSerial[samplerIndex] != 0) |
daniel@transgaming.com | 5a0b0a8 | 2010-05-12 03:45:07 +0000 | [diff] [blame] | 2181 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2182 | mDevice->SetTexture(d3dSampler, NULL); |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2183 | appliedTextureSerial[samplerIndex] = 0; |
daniel@transgaming.com | 5a0b0a8 | 2010-05-12 03:45:07 +0000 | [diff] [blame] | 2184 | } |
daniel@transgaming.com | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 2185 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2186 | } |
jbauman@chromium.org | b6e7222 | 2011-10-18 23:01:46 +0000 | [diff] [blame] | 2187 | |
| 2188 | for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) |
| 2189 | { |
| 2190 | if (appliedTextureSerial[samplerIndex] != 0) |
| 2191 | { |
daniel@transgaming.com | c5a7b69 | 2011-10-26 02:45:44 +0000 | [diff] [blame] | 2192 | mDevice->SetTexture(samplerIndex + d3dSamplerOffset, NULL); |
jbauman@chromium.org | b6e7222 | 2011-10-18 23:01:46 +0000 | [diff] [blame] | 2193 | appliedTextureSerial[samplerIndex] = 0; |
| 2194 | } |
| 2195 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) |
| 2199 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 2200 | Framebuffer *framebuffer = getReadFramebuffer(); |
daniel@transgaming.com | bbc5779 | 2010-07-28 19:21:05 +0000 | [diff] [blame] | 2201 | |
| 2202 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 2203 | { |
| 2204 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 2205 | } |
| 2206 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 2207 | if (getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 2208 | { |
| 2209 | return error(GL_INVALID_OPERATION); |
| 2210 | } |
| 2211 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2212 | IDirect3DSurface9 *renderTarget = framebuffer->getRenderTarget(); |
daniel@transgaming.com | d36c6a0 | 2010-08-31 12:15:09 +0000 | [diff] [blame] | 2213 | |
| 2214 | if (!renderTarget) |
| 2215 | { |
| 2216 | return; // Context must be lost, return silently |
| 2217 | } |
| 2218 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2219 | D3DSURFACE_DESC desc; |
| 2220 | renderTarget->GetDesc(&desc); |
| 2221 | |
| 2222 | IDirect3DSurface9 *systemSurface; |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2223 | HRESULT result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &systemSurface, NULL); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2224 | |
daniel@transgaming.com | 97b1241 | 2011-08-09 13:40:28 +0000 | [diff] [blame] | 2225 | if (FAILED(result)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2226 | { |
daniel@transgaming.com | 97b1241 | 2011-08-09 13:40:28 +0000 | [diff] [blame] | 2227 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2228 | return error(GL_OUT_OF_MEMORY); |
| 2229 | } |
| 2230 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2231 | if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) |
| 2232 | { |
| 2233 | UNIMPLEMENTED(); // FIXME: Requires resolve using StretchRect into non-multisampled render target |
daniel@transgaming.com | 97b1241 | 2011-08-09 13:40:28 +0000 | [diff] [blame] | 2234 | return error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2237 | result = mDevice->GetRenderTargetData(renderTarget, systemSurface); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2238 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2239 | if (FAILED(result)) |
| 2240 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2241 | systemSurface->Release(); |
| 2242 | |
daniel@transgaming.com | 6f5c5fc | 2011-11-09 17:46:39 +0000 | [diff] [blame] | 2243 | // It turns out that D3D will sometimes produce more error |
| 2244 | // codes than those documented. |
| 2245 | if (checkDeviceLost(result)) |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2246 | return error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 6f5c5fc | 2011-11-09 17:46:39 +0000 | [diff] [blame] | 2247 | else |
| 2248 | { |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2249 | UNREACHABLE(); |
daniel@transgaming.com | 6f5c5fc | 2011-11-09 17:46:39 +0000 | [diff] [blame] | 2250 | return; |
apatrick@chromium.org | 6db8cab | 2010-07-22 20:39:50 +0000 | [diff] [blame] | 2251 | } |
daniel@transgaming.com | 6f5c5fc | 2011-11-09 17:46:39 +0000 | [diff] [blame] | 2252 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | D3DLOCKED_RECT lock; |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2256 | RECT rect = transformPixelRect(x, y, width, height, desc.Height); |
| 2257 | rect.left = clamp(rect.left, 0L, static_cast<LONG>(desc.Width)); |
| 2258 | rect.top = clamp(rect.top, 0L, static_cast<LONG>(desc.Height)); |
| 2259 | rect.right = clamp(rect.right, 0L, static_cast<LONG>(desc.Width)); |
| 2260 | rect.bottom = clamp(rect.bottom, 0L, static_cast<LONG>(desc.Height)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2261 | |
| 2262 | result = systemSurface->LockRect(&lock, &rect, D3DLOCK_READONLY); |
| 2263 | |
| 2264 | if (FAILED(result)) |
| 2265 | { |
| 2266 | UNREACHABLE(); |
| 2267 | systemSurface->Release(); |
| 2268 | |
| 2269 | return; // No sensible error to generate |
| 2270 | } |
| 2271 | |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2272 | unsigned char *source = ((unsigned char*)lock.pBits) + lock.Pitch * (rect.bottom - rect.top - 1); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2273 | unsigned char *dest = (unsigned char*)pixels; |
daniel@transgaming.com | afb2395 | 2010-04-13 03:25:54 +0000 | [diff] [blame] | 2274 | unsigned short *dest16 = (unsigned short*)pixels; |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2275 | int inputPitch = -lock.Pitch; |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2276 | GLsizei outputPitch = ComputePitch(width, format, type, mState.packAlignment); |
daniel@transgaming.com | 713914b | 2010-05-04 03:35:17 +0000 | [diff] [blame] | 2277 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2278 | for (int j = 0; j < rect.bottom - rect.top; j++) |
| 2279 | { |
daniel@transgaming.com | a9198d9 | 2010-08-08 04:49:56 +0000 | [diff] [blame] | 2280 | if (desc.Format == D3DFMT_A8R8G8B8 && |
| 2281 | format == GL_BGRA_EXT && |
| 2282 | type == GL_UNSIGNED_BYTE) |
| 2283 | { |
| 2284 | // Fast path for EXT_read_format_bgra, given |
| 2285 | // an RGBA source buffer. Note that buffers with no |
| 2286 | // alpha go through the slow path below. |
| 2287 | memcpy(dest + j * outputPitch, |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2288 | source + j * inputPitch, |
daniel@transgaming.com | a9198d9 | 2010-08-08 04:49:56 +0000 | [diff] [blame] | 2289 | (rect.right - rect.left) * 4); |
| 2290 | continue; |
| 2291 | } |
| 2292 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2293 | for (int i = 0; i < rect.right - rect.left; i++) |
| 2294 | { |
| 2295 | float r; |
| 2296 | float g; |
| 2297 | float b; |
| 2298 | float a; |
| 2299 | |
| 2300 | switch (desc.Format) |
| 2301 | { |
| 2302 | case D3DFMT_R5G6B5: |
| 2303 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2304 | unsigned short rgb = *(unsigned short*)(source + 2 * i + j * inputPitch); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2305 | |
| 2306 | a = 1.0f; |
| 2307 | b = (rgb & 0x001F) * (1.0f / 0x001F); |
| 2308 | g = (rgb & 0x07E0) * (1.0f / 0x07E0); |
| 2309 | r = (rgb & 0xF800) * (1.0f / 0xF800); |
| 2310 | } |
| 2311 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2312 | case D3DFMT_A1R5G5B5: |
| 2313 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2314 | unsigned short argb = *(unsigned short*)(source + 2 * i + j * inputPitch); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2315 | |
| 2316 | a = (argb & 0x8000) ? 1.0f : 0.0f; |
| 2317 | b = (argb & 0x001F) * (1.0f / 0x001F); |
| 2318 | g = (argb & 0x03E0) * (1.0f / 0x03E0); |
| 2319 | r = (argb & 0x7C00) * (1.0f / 0x7C00); |
| 2320 | } |
| 2321 | break; |
| 2322 | case D3DFMT_A8R8G8B8: |
| 2323 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2324 | unsigned int argb = *(unsigned int*)(source + 4 * i + j * inputPitch); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2325 | |
| 2326 | a = (argb & 0xFF000000) * (1.0f / 0xFF000000); |
| 2327 | b = (argb & 0x000000FF) * (1.0f / 0x000000FF); |
| 2328 | g = (argb & 0x0000FF00) * (1.0f / 0x0000FF00); |
| 2329 | r = (argb & 0x00FF0000) * (1.0f / 0x00FF0000); |
| 2330 | } |
| 2331 | break; |
| 2332 | case D3DFMT_X8R8G8B8: |
| 2333 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2334 | unsigned int xrgb = *(unsigned int*)(source + 4 * i + j * inputPitch); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2335 | |
| 2336 | a = 1.0f; |
| 2337 | b = (xrgb & 0x000000FF) * (1.0f / 0x000000FF); |
| 2338 | g = (xrgb & 0x0000FF00) * (1.0f / 0x0000FF00); |
| 2339 | r = (xrgb & 0x00FF0000) * (1.0f / 0x00FF0000); |
| 2340 | } |
| 2341 | break; |
| 2342 | case D3DFMT_A2R10G10B10: |
| 2343 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2344 | unsigned int argb = *(unsigned int*)(source + 4 * i + j * inputPitch); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2345 | |
| 2346 | a = (argb & 0xC0000000) * (1.0f / 0xC0000000); |
| 2347 | b = (argb & 0x000003FF) * (1.0f / 0x000003FF); |
| 2348 | g = (argb & 0x000FFC00) * (1.0f / 0x000FFC00); |
| 2349 | r = (argb & 0x3FF00000) * (1.0f / 0x3FF00000); |
| 2350 | } |
| 2351 | break; |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 2352 | case D3DFMT_A32B32G32R32F: |
| 2353 | { |
| 2354 | // float formats in D3D are stored rgba, rather than the other way round |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2355 | r = *((float*)(source + 16 * i + j * inputPitch) + 0); |
| 2356 | g = *((float*)(source + 16 * i + j * inputPitch) + 1); |
| 2357 | b = *((float*)(source + 16 * i + j * inputPitch) + 2); |
| 2358 | a = *((float*)(source + 16 * i + j * inputPitch) + 3); |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 2359 | } |
| 2360 | break; |
| 2361 | case D3DFMT_A16B16G16R16F: |
| 2362 | { |
| 2363 | // float formats in D3D are stored rgba, rather than the other way round |
| 2364 | float abgr[4]; |
| 2365 | |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 2366 | D3DXFloat16To32Array(abgr, (D3DXFLOAT16*)(source + 8 * i + j * inputPitch), 4); |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 2367 | |
| 2368 | a = abgr[3]; |
| 2369 | b = abgr[2]; |
| 2370 | g = abgr[1]; |
| 2371 | r = abgr[0]; |
| 2372 | } |
| 2373 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2374 | default: |
| 2375 | UNIMPLEMENTED(); // FIXME |
| 2376 | UNREACHABLE(); |
| 2377 | } |
| 2378 | |
| 2379 | switch (format) |
| 2380 | { |
| 2381 | case GL_RGBA: |
| 2382 | switch (type) |
| 2383 | { |
| 2384 | case GL_UNSIGNED_BYTE: |
daniel@transgaming.com | 713914b | 2010-05-04 03:35:17 +0000 | [diff] [blame] | 2385 | dest[4 * i + j * outputPitch + 0] = (unsigned char)(255 * r + 0.5f); |
| 2386 | dest[4 * i + j * outputPitch + 1] = (unsigned char)(255 * g + 0.5f); |
| 2387 | dest[4 * i + j * outputPitch + 2] = (unsigned char)(255 * b + 0.5f); |
| 2388 | 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] | 2389 | break; |
| 2390 | default: UNREACHABLE(); |
| 2391 | } |
| 2392 | break; |
daniel@transgaming.com | a9198d9 | 2010-08-08 04:49:56 +0000 | [diff] [blame] | 2393 | case GL_BGRA_EXT: |
| 2394 | switch (type) |
| 2395 | { |
| 2396 | case GL_UNSIGNED_BYTE: |
| 2397 | dest[4 * i + j * outputPitch + 0] = (unsigned char)(255 * b + 0.5f); |
| 2398 | dest[4 * i + j * outputPitch + 1] = (unsigned char)(255 * g + 0.5f); |
| 2399 | dest[4 * i + j * outputPitch + 2] = (unsigned char)(255 * r + 0.5f); |
| 2400 | dest[4 * i + j * outputPitch + 3] = (unsigned char)(255 * a + 0.5f); |
| 2401 | break; |
| 2402 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 2403 | // According to the desktop GL spec in the "Transfer of Pixel Rectangles" section |
| 2404 | // this type is packed as follows: |
| 2405 | // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
| 2406 | // -------------------------------------------------------------------------------- |
| 2407 | // | 4th | 3rd | 2nd | 1st component | |
| 2408 | // -------------------------------------------------------------------------------- |
| 2409 | // in the case of BGRA_EXT, B is the first component, G the second, and so forth. |
| 2410 | dest16[i + j * outputPitch / sizeof(unsigned short)] = |
| 2411 | ((unsigned short)(15 * a + 0.5f) << 12)| |
| 2412 | ((unsigned short)(15 * r + 0.5f) << 8) | |
| 2413 | ((unsigned short)(15 * g + 0.5f) << 4) | |
| 2414 | ((unsigned short)(15 * b + 0.5f) << 0); |
| 2415 | break; |
| 2416 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 2417 | // According to the desktop GL spec in the "Transfer of Pixel Rectangles" section |
| 2418 | // this type is packed as follows: |
| 2419 | // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
| 2420 | // -------------------------------------------------------------------------------- |
| 2421 | // | 4th | 3rd | 2nd | 1st component | |
| 2422 | // -------------------------------------------------------------------------------- |
| 2423 | // in the case of BGRA_EXT, B is the first component, G the second, and so forth. |
| 2424 | dest16[i + j * outputPitch / sizeof(unsigned short)] = |
| 2425 | ((unsigned short)( a + 0.5f) << 15) | |
| 2426 | ((unsigned short)(31 * r + 0.5f) << 10) | |
| 2427 | ((unsigned short)(31 * g + 0.5f) << 5) | |
| 2428 | ((unsigned short)(31 * b + 0.5f) << 0); |
| 2429 | break; |
| 2430 | default: UNREACHABLE(); |
| 2431 | } |
| 2432 | break; |
daniel@transgaming.com | afb2395 | 2010-04-13 03:25:54 +0000 | [diff] [blame] | 2433 | case GL_RGB: // IMPLEMENTATION_COLOR_READ_FORMAT |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2434 | switch (type) |
| 2435 | { |
daniel@transgaming.com | afb2395 | 2010-04-13 03:25:54 +0000 | [diff] [blame] | 2436 | case GL_UNSIGNED_SHORT_5_6_5: // IMPLEMENTATION_COLOR_READ_TYPE |
daniel@transgaming.com | 713914b | 2010-05-04 03:35:17 +0000 | [diff] [blame] | 2437 | dest16[i + j * outputPitch / sizeof(unsigned short)] = |
| 2438 | ((unsigned short)(31 * b + 0.5f) << 0) | |
| 2439 | ((unsigned short)(63 * g + 0.5f) << 5) | |
| 2440 | ((unsigned short)(31 * r + 0.5f) << 11); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2441 | break; |
| 2442 | default: UNREACHABLE(); |
| 2443 | } |
| 2444 | break; |
| 2445 | default: UNREACHABLE(); |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | systemSurface->UnlockRect(); |
| 2451 | |
| 2452 | systemSurface->Release(); |
| 2453 | } |
| 2454 | |
| 2455 | void Context::clear(GLbitfield mask) |
| 2456 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 2457 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
daniel@transgaming.com | baeb8c5 | 2010-05-05 18:50:39 +0000 | [diff] [blame] | 2458 | |
| 2459 | if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 2460 | { |
daniel@transgaming.com | b5a3a6b | 2011-03-21 16:38:46 +0000 | [diff] [blame] | 2461 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
daniel@transgaming.com | baeb8c5 | 2010-05-05 18:50:39 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2464 | DWORD flags = 0; |
| 2465 | |
| 2466 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2467 | { |
| 2468 | mask &= ~GL_COLOR_BUFFER_BIT; |
daniel@transgaming.com | c6f5340 | 2010-06-24 13:02:19 +0000 | [diff] [blame] | 2469 | |
| 2470 | if (framebufferObject->getColorbufferType() != GL_NONE) |
| 2471 | { |
| 2472 | flags |= D3DCLEAR_TARGET; |
| 2473 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 2477 | { |
| 2478 | mask &= ~GL_DEPTH_BUFFER_BIT; |
daniel@transgaming.com | c6f5340 | 2010-06-24 13:02:19 +0000 | [diff] [blame] | 2479 | if (mState.depthMask && framebufferObject->getDepthbufferType() != GL_NONE) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2480 | { |
| 2481 | flags |= D3DCLEAR_ZBUFFER; |
| 2482 | } |
| 2483 | } |
| 2484 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2485 | GLuint stencilUnmasked = 0x0; |
| 2486 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 2487 | if (mask & GL_STENCIL_BUFFER_BIT) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2488 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2489 | mask &= ~GL_STENCIL_BUFFER_BIT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 2490 | if (framebufferObject->getStencilbufferType() != GL_NONE) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2491 | { |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 2492 | IDirect3DSurface9 *depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil(); |
apatrick@chromium.org | b2bdd06 | 2010-10-05 02:24:30 +0000 | [diff] [blame] | 2493 | if (!depthStencil) |
| 2494 | { |
| 2495 | ERR("Depth stencil pointer unexpectedly null."); |
| 2496 | return; |
| 2497 | } |
| 2498 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 2499 | D3DSURFACE_DESC desc; |
| 2500 | depthStencil->GetDesc(&desc); |
| 2501 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 2502 | unsigned int stencilSize = dx2es::GetStencilSize(desc.Format); |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 2503 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 2504 | |
| 2505 | if (stencilUnmasked != 0x0) |
| 2506 | { |
| 2507 | flags |= D3DCLEAR_STENCIL; |
| 2508 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | if (mask != 0) |
| 2513 | { |
| 2514 | return error(GL_INVALID_VALUE); |
| 2515 | } |
| 2516 | |
daniel@transgaming.com | baeb8c5 | 2010-05-05 18:50:39 +0000 | [diff] [blame] | 2517 | if (!applyRenderTarget(true)) // Clips the clear to the scissor rectangle but not the viewport |
| 2518 | { |
| 2519 | return; |
| 2520 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2521 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2522 | D3DCOLOR color = D3DCOLOR_ARGB(unorm<8>(mState.colorClearValue.alpha), |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2523 | unorm<8>(mState.colorClearValue.red), |
| 2524 | unorm<8>(mState.colorClearValue.green), |
| 2525 | unorm<8>(mState.colorClearValue.blue)); |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2526 | float depth = clamp01(mState.depthClearValue); |
| 2527 | int stencil = mState.stencilClearValue & 0x000000FF; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2528 | |
| 2529 | IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); |
| 2530 | |
daniel@transgaming.com | d36c6a0 | 2010-08-31 12:15:09 +0000 | [diff] [blame] | 2531 | if (!renderTarget) |
| 2532 | { |
| 2533 | return; // Context must be lost, return silently |
| 2534 | } |
| 2535 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2536 | D3DSURFACE_DESC desc; |
| 2537 | renderTarget->GetDesc(&desc); |
| 2538 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 2539 | bool alphaUnmasked = (dx2es::GetAlphaSize(desc.Format) == 0) || mState.colorMaskAlpha; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2540 | |
| 2541 | const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) && |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2542 | (mState.stencilWritemask & stencilUnmasked) != stencilUnmasked; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2543 | const bool needMaskedColorClear = (flags & D3DCLEAR_TARGET) && |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2544 | !(mState.colorMaskRed && mState.colorMaskGreen && |
| 2545 | mState.colorMaskBlue && alphaUnmasked); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2546 | |
| 2547 | if (needMaskedColorClear || needMaskedStencilClear) |
| 2548 | { |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 2549 | // State which is altered in all paths from this point to the clear call is saved. |
| 2550 | // State which is altered in only some paths will be flagged dirty in the case that |
| 2551 | // that path is taken. |
| 2552 | HRESULT hr; |
| 2553 | if (mMaskedClearSavedState == NULL) |
| 2554 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2555 | hr = mDevice->BeginStateBlock(); |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 2556 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 2557 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2558 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 2559 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 2560 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 2561 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 2562 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 2563 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 2564 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 2565 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 2566 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 2567 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 2568 | mDevice->SetPixelShader(NULL); |
| 2569 | mDevice->SetVertexShader(NULL); |
| 2570 | mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); |
| 2571 | mDevice->SetStreamSource(0, NULL, 0, 0); |
| 2572 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 2573 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 2574 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 2575 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 2576 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 2577 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 2578 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 2579 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2580 | hr = mDevice->EndStateBlock(&mMaskedClearSavedState); |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 2581 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 2582 | } |
| 2583 | |
| 2584 | ASSERT(mMaskedClearSavedState != NULL); |
| 2585 | |
| 2586 | if (mMaskedClearSavedState != NULL) |
| 2587 | { |
| 2588 | hr = mMaskedClearSavedState->Capture(); |
| 2589 | ASSERT(SUCCEEDED(hr)); |
| 2590 | } |
| 2591 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2592 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 2593 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 2594 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 2595 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 2596 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 2597 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 2598 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 2599 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2600 | |
| 2601 | if (flags & D3DCLEAR_TARGET) |
| 2602 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2603 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, es2dx::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, mState.colorMaskBlue, mState.colorMaskAlpha)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2604 | } |
| 2605 | else |
| 2606 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2607 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | if (stencilUnmasked != 0x0 && (flags & D3DCLEAR_STENCIL)) |
| 2611 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2612 | mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 2613 | mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); |
| 2614 | mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); |
| 2615 | mDevice->SetRenderState(D3DRS_STENCILREF, stencil); |
| 2616 | mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, mState.stencilWritemask); |
| 2617 | mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); |
| 2618 | mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); |
| 2619 | mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 2620 | mStencilStateDirty = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2621 | } |
| 2622 | else |
| 2623 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2624 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2627 | mDevice->SetPixelShader(NULL); |
| 2628 | mDevice->SetVertexShader(NULL); |
| 2629 | mDevice->SetFVF(D3DFVF_XYZRHW); |
| 2630 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 2631 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 2632 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 2633 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 2634 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 2635 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 2636 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2637 | |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2638 | float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges |
| 2639 | quad[0][0] = -0.5f; |
| 2640 | quad[0][1] = desc.Height - 0.5f; |
| 2641 | quad[0][2] = 0.0f; |
| 2642 | quad[0][3] = 1.0f; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2643 | |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2644 | quad[1][0] = desc.Width - 0.5f; |
| 2645 | quad[1][1] = desc.Height - 0.5f; |
| 2646 | quad[1][2] = 0.0f; |
| 2647 | quad[1][3] = 1.0f; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2648 | |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2649 | quad[2][0] = -0.5f; |
| 2650 | quad[2][1] = -0.5f; |
| 2651 | quad[2][2] = 0.0f; |
| 2652 | quad[2][3] = 1.0f; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2653 | |
daniel@transgaming.com | 1615be2 | 2011-02-09 16:30:06 +0000 | [diff] [blame] | 2654 | quad[3][0] = desc.Width - 0.5f; |
| 2655 | quad[3][1] = -0.5f; |
| 2656 | quad[3][2] = 0.0f; |
| 2657 | quad[3][3] = 1.0f; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2658 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2659 | mDisplay->startScene(); |
| 2660 | mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float[4])); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2661 | |
| 2662 | if (flags & D3DCLEAR_ZBUFFER) |
| 2663 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2664 | mDevice->SetRenderState(D3DRS_ZENABLE, TRUE); |
| 2665 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); |
| 2666 | mDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2667 | } |
daniel@transgaming.com | 8f05d1a | 2010-06-07 02:06:03 +0000 | [diff] [blame] | 2668 | |
| 2669 | if (mMaskedClearSavedState != NULL) |
| 2670 | { |
| 2671 | mMaskedClearSavedState->Apply(); |
| 2672 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2673 | } |
daniel@transgaming.com | 8ede24f | 2010-05-05 18:47:58 +0000 | [diff] [blame] | 2674 | else if (flags) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2675 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2676 | mDevice->Clear(0, NULL, flags, color, depth, stencil); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count) |
| 2681 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2682 | if (!mState.currentProgram) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2683 | { |
| 2684 | return error(GL_INVALID_OPERATION); |
| 2685 | } |
| 2686 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2687 | D3DPRIMITIVETYPE primitiveType; |
| 2688 | int primitiveCount; |
| 2689 | |
| 2690 | if(!es2dx::ConvertPrimitiveType(mode, count, &primitiveType, &primitiveCount)) |
| 2691 | return error(GL_INVALID_ENUM); |
| 2692 | |
| 2693 | if (primitiveCount <= 0) |
| 2694 | { |
| 2695 | return; |
| 2696 | } |
| 2697 | |
| 2698 | if (!applyRenderTarget(false)) |
| 2699 | { |
daniel@transgaming.com | baeb8c5 | 2010-05-05 18:50:39 +0000 | [diff] [blame] | 2700 | return; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 2703 | applyState(mode); |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 2704 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 2705 | GLenum err = applyVertexBuffer(first, count); |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 2706 | if (err != GL_NO_ERROR) |
| 2707 | { |
| 2708 | return error(err); |
| 2709 | } |
| 2710 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2711 | applyShaders(); |
| 2712 | applyTextures(); |
| 2713 | |
daniel@transgaming.com | f494c9c | 2011-05-11 15:37:05 +0000 | [diff] [blame] | 2714 | if (!getCurrentProgram()->validateSamplers(false)) |
daniel@transgaming.com | c3a0e94 | 2010-04-29 03:35:45 +0000 | [diff] [blame] | 2715 | { |
| 2716 | return error(GL_INVALID_OPERATION); |
| 2717 | } |
| 2718 | |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2719 | if (!cullSkipsDraw(mode)) |
| 2720 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2721 | mDisplay->startScene(); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 2722 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2723 | mDevice->DrawPrimitive(primitiveType, 0, primitiveCount); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2724 | |
| 2725 | if (mode == GL_LINE_LOOP) // Draw the last segment separately |
| 2726 | { |
| 2727 | drawClosingLine(first, first + count - 1); |
| 2728 | } |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2729 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2732 | void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2733 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2734 | if (!mState.currentProgram) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2735 | { |
| 2736 | return error(GL_INVALID_OPERATION); |
| 2737 | } |
| 2738 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 2739 | if (!indices && !mState.elementArrayBuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2740 | { |
| 2741 | return error(GL_INVALID_OPERATION); |
| 2742 | } |
| 2743 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2744 | D3DPRIMITIVETYPE primitiveType; |
| 2745 | int primitiveCount; |
| 2746 | |
| 2747 | if(!es2dx::ConvertPrimitiveType(mode, count, &primitiveType, &primitiveCount)) |
| 2748 | return error(GL_INVALID_ENUM); |
| 2749 | |
| 2750 | if (primitiveCount <= 0) |
| 2751 | { |
| 2752 | return; |
| 2753 | } |
| 2754 | |
| 2755 | if (!applyRenderTarget(false)) |
| 2756 | { |
daniel@transgaming.com | baeb8c5 | 2010-05-05 18:50:39 +0000 | [diff] [blame] | 2757 | return; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 2760 | applyState(mode); |
daniel@transgaming.com | 41d8dd8 | 2010-05-12 03:45:03 +0000 | [diff] [blame] | 2761 | |
| 2762 | TranslatedIndexData indexInfo; |
| 2763 | GLenum err = applyIndexBuffer(indices, count, mode, type, &indexInfo); |
| 2764 | if (err != GL_NO_ERROR) |
| 2765 | { |
| 2766 | return error(err); |
| 2767 | } |
| 2768 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 2769 | GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; |
| 2770 | err = applyVertexBuffer(indexInfo.minIndex, vertexCount); |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 2771 | if (err != GL_NO_ERROR) |
| 2772 | { |
| 2773 | return error(err); |
| 2774 | } |
| 2775 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2776 | applyShaders(); |
| 2777 | applyTextures(); |
| 2778 | |
daniel@transgaming.com | f494c9c | 2011-05-11 15:37:05 +0000 | [diff] [blame] | 2779 | if (!getCurrentProgram()->validateSamplers(false)) |
daniel@transgaming.com | c3a0e94 | 2010-04-29 03:35:45 +0000 | [diff] [blame] | 2780 | { |
| 2781 | return error(GL_INVALID_OPERATION); |
| 2782 | } |
| 2783 | |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2784 | if (!cullSkipsDraw(mode)) |
| 2785 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2786 | mDisplay->startScene(); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2787 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2788 | mDevice->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, primitiveCount); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2789 | |
| 2790 | if (mode == GL_LINE_LOOP) // Draw the last segment separately |
| 2791 | { |
| 2792 | drawClosingLine(count, type, indices); |
| 2793 | } |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 2794 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
daniel@transgaming.com | 0d86aa7 | 2011-10-26 02:35:10 +0000 | [diff] [blame] | 2797 | // Implements glFlush when block is false, glFinish when block is true |
| 2798 | void Context::sync(bool block) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2799 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2800 | IDirect3DQuery9 *eventQuery = NULL; |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2801 | HRESULT result; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2802 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2803 | result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2804 | if (FAILED(result)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2805 | { |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2806 | ERR("CreateQuery failed hr=%x\n", result); |
| 2807 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 2808 | { |
| 2809 | return error(GL_OUT_OF_MEMORY); |
| 2810 | } |
| 2811 | ASSERT(false); |
| 2812 | return; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2815 | result = eventQuery->Issue(D3DISSUE_END); |
| 2816 | if (FAILED(result)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2817 | { |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2818 | ERR("eventQuery->Issue(END) failed hr=%x\n", result); |
| 2819 | ASSERT(false); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2820 | eventQuery->Release(); |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2821 | return; |
| 2822 | } |
apatrick@chromium.org | 575e791 | 2010-08-25 18:07:12 +0000 | [diff] [blame] | 2823 | |
daniel@transgaming.com | 0d86aa7 | 2011-10-26 02:35:10 +0000 | [diff] [blame] | 2824 | do |
| 2825 | { |
| 2826 | result = eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); |
| 2827 | |
| 2828 | if(block && result == S_FALSE) |
| 2829 | { |
| 2830 | // Keep polling, but allow other threads to do something useful first |
| 2831 | Sleep(0); |
| 2832 | } |
| 2833 | } |
| 2834 | while(block && result == S_FALSE); |
| 2835 | |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2836 | eventQuery->Release(); |
| 2837 | |
daniel@transgaming.com | 6f5c5fc | 2011-11-09 17:46:39 +0000 | [diff] [blame] | 2838 | if (checkDeviceLost(result)) |
daniel@transgaming.com | 18b7b5b | 2011-05-17 18:34:18 +0000 | [diff] [blame] | 2839 | { |
| 2840 | error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2844 | void Context::drawClosingLine(unsigned int first, unsigned int last) |
| 2845 | { |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2846 | IDirect3DIndexBuffer9 *indexBuffer = NULL; |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2847 | bool succeeded = false; |
| 2848 | UINT offset; |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2849 | |
| 2850 | if (supports32bitIndices()) |
| 2851 | { |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2852 | const int spaceNeeded = 2 * sizeof(unsigned int); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2853 | |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2854 | if (!mClosingIB) |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2855 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2856 | mClosingIB = new StreamingIndexBuffer(mDevice, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX32); |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2857 | } |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2858 | |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2859 | mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_INT); |
| 2860 | |
| 2861 | unsigned int *data = static_cast<unsigned int*>(mClosingIB->map(spaceNeeded, &offset)); |
| 2862 | if (data) |
| 2863 | { |
| 2864 | data[0] = last; |
| 2865 | data[1] = first; |
| 2866 | mClosingIB->unmap(); |
| 2867 | offset /= 4; |
| 2868 | succeeded = true; |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | else |
| 2872 | { |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2873 | const int spaceNeeded = 2 * sizeof(unsigned short); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2874 | |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2875 | if (!mClosingIB) |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2876 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2877 | mClosingIB = new StreamingIndexBuffer(mDevice, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX16); |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2878 | } |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2879 | |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2880 | mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_SHORT); |
| 2881 | |
| 2882 | unsigned short *data = static_cast<unsigned short*>(mClosingIB->map(spaceNeeded, &offset)); |
| 2883 | if (data) |
| 2884 | { |
| 2885 | data[0] = last; |
| 2886 | data[1] = first; |
| 2887 | mClosingIB->unmap(); |
| 2888 | offset /= 2; |
| 2889 | succeeded = true; |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2890 | } |
| 2891 | } |
| 2892 | |
jbauman@chromium.org | 399c35f | 2011-04-28 23:19:51 +0000 | [diff] [blame] | 2893 | if (succeeded) |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2894 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2895 | mDevice->SetIndices(mClosingIB->getBuffer()); |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 2896 | mAppliedIBSerial = mClosingIB->getSerial(); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2897 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 2898 | mDevice->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, last, offset, 1); |
daniel@transgaming.com | ddcd737 | 2011-01-08 05:46:33 +0000 | [diff] [blame] | 2899 | } |
| 2900 | else |
| 2901 | { |
| 2902 | ERR("Could not create an index buffer for closing a line loop."); |
| 2903 | error(GL_OUT_OF_MEMORY); |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | void Context::drawClosingLine(GLsizei count, GLenum type, const void *indices) |
| 2908 | { |
| 2909 | unsigned int first = 0; |
| 2910 | unsigned int last = 0; |
| 2911 | |
| 2912 | if (mState.elementArrayBuffer.get()) |
| 2913 | { |
| 2914 | Buffer *indexBuffer = mState.elementArrayBuffer.get(); |
| 2915 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
| 2916 | indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; |
| 2917 | } |
| 2918 | |
| 2919 | switch (type) |
| 2920 | { |
| 2921 | case GL_UNSIGNED_BYTE: |
| 2922 | first = static_cast<const GLubyte*>(indices)[0]; |
| 2923 | last = static_cast<const GLubyte*>(indices)[count - 1]; |
| 2924 | break; |
| 2925 | case GL_UNSIGNED_SHORT: |
| 2926 | first = static_cast<const GLushort*>(indices)[0]; |
| 2927 | last = static_cast<const GLushort*>(indices)[count - 1]; |
| 2928 | break; |
| 2929 | case GL_UNSIGNED_INT: |
| 2930 | first = static_cast<const GLuint*>(indices)[0]; |
| 2931 | last = static_cast<const GLuint*>(indices)[count - 1]; |
| 2932 | break; |
| 2933 | default: UNREACHABLE(); |
| 2934 | } |
| 2935 | |
| 2936 | drawClosingLine(first, last); |
| 2937 | } |
| 2938 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2939 | void Context::recordInvalidEnum() |
| 2940 | { |
| 2941 | mInvalidEnum = true; |
| 2942 | } |
| 2943 | |
| 2944 | void Context::recordInvalidValue() |
| 2945 | { |
| 2946 | mInvalidValue = true; |
| 2947 | } |
| 2948 | |
| 2949 | void Context::recordInvalidOperation() |
| 2950 | { |
| 2951 | mInvalidOperation = true; |
| 2952 | } |
| 2953 | |
| 2954 | void Context::recordOutOfMemory() |
| 2955 | { |
| 2956 | mOutOfMemory = true; |
| 2957 | } |
| 2958 | |
| 2959 | void Context::recordInvalidFramebufferOperation() |
| 2960 | { |
| 2961 | mInvalidFramebufferOperation = true; |
| 2962 | } |
| 2963 | |
| 2964 | // Get one of the recorded errors and clear its flag, if any. |
| 2965 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 2966 | GLenum Context::getError() |
| 2967 | { |
| 2968 | if (mInvalidEnum) |
| 2969 | { |
| 2970 | mInvalidEnum = false; |
| 2971 | |
| 2972 | return GL_INVALID_ENUM; |
| 2973 | } |
| 2974 | |
| 2975 | if (mInvalidValue) |
| 2976 | { |
| 2977 | mInvalidValue = false; |
| 2978 | |
| 2979 | return GL_INVALID_VALUE; |
| 2980 | } |
| 2981 | |
| 2982 | if (mInvalidOperation) |
| 2983 | { |
| 2984 | mInvalidOperation = false; |
| 2985 | |
| 2986 | return GL_INVALID_OPERATION; |
| 2987 | } |
| 2988 | |
| 2989 | if (mOutOfMemory) |
| 2990 | { |
| 2991 | mOutOfMemory = false; |
| 2992 | |
| 2993 | return GL_OUT_OF_MEMORY; |
| 2994 | } |
| 2995 | |
| 2996 | if (mInvalidFramebufferOperation) |
| 2997 | { |
| 2998 | mInvalidFramebufferOperation = false; |
| 2999 | |
| 3000 | return GL_INVALID_FRAMEBUFFER_OPERATION; |
| 3001 | } |
| 3002 | |
| 3003 | return GL_NO_ERROR; |
| 3004 | } |
| 3005 | |
daniel@transgaming.com | be5a086 | 2010-07-28 19:20:37 +0000 | [diff] [blame] | 3006 | bool Context::supportsShaderModel3() const |
daniel@transgaming.com | 296ca9c | 2010-04-03 20:56:07 +0000 | [diff] [blame] | 3007 | { |
daniel@transgaming.com | be5a086 | 2010-07-28 19:20:37 +0000 | [diff] [blame] | 3008 | return mSupportsShaderModel3; |
daniel@transgaming.com | 296ca9c | 2010-04-03 20:56:07 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
daniel@transgaming.com | 396c643 | 2010-11-26 16:26:12 +0000 | [diff] [blame] | 3011 | int Context::getMaximumVaryingVectors() const |
| 3012 | { |
| 3013 | return mSupportsShaderModel3 ? MAX_VARYING_VECTORS_SM3 : MAX_VARYING_VECTORS_SM2; |
| 3014 | } |
| 3015 | |
daniel@transgaming.com | dfd5702 | 2011-05-11 15:37:25 +0000 | [diff] [blame] | 3016 | unsigned int Context::getMaximumVertexTextureImageUnits() const |
daniel@transgaming.com | af29cac | 2011-05-11 15:36:31 +0000 | [diff] [blame] | 3017 | { |
| 3018 | return mSupportsVertexTexture ? MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF : 0; |
| 3019 | } |
| 3020 | |
daniel@transgaming.com | dfd5702 | 2011-05-11 15:37:25 +0000 | [diff] [blame] | 3021 | unsigned int Context::getMaximumCombinedTextureImageUnits() const |
daniel@transgaming.com | af29cac | 2011-05-11 15:36:31 +0000 | [diff] [blame] | 3022 | { |
| 3023 | return MAX_TEXTURE_IMAGE_UNITS + getMaximumVertexTextureImageUnits(); |
| 3024 | } |
| 3025 | |
daniel@transgaming.com | 458da14 | 2010-11-28 02:03:02 +0000 | [diff] [blame] | 3026 | int Context::getMaximumFragmentUniformVectors() const |
| 3027 | { |
| 3028 | return mSupportsShaderModel3 ? MAX_FRAGMENT_UNIFORM_VECTORS_SM3 : MAX_FRAGMENT_UNIFORM_VECTORS_SM2; |
| 3029 | } |
| 3030 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3031 | int Context::getMaxSupportedSamples() const |
| 3032 | { |
| 3033 | return mMaxSupportedSamples; |
| 3034 | } |
| 3035 | |
| 3036 | int Context::getNearestSupportedSamples(D3DFORMAT format, int requested) const |
| 3037 | { |
| 3038 | if (requested == 0) |
| 3039 | { |
| 3040 | return requested; |
| 3041 | } |
| 3042 | |
| 3043 | std::map<D3DFORMAT, bool *>::const_iterator itr = mMultiSampleSupport.find(format); |
| 3044 | if (itr == mMultiSampleSupport.end()) |
| 3045 | { |
| 3046 | return -1; |
| 3047 | } |
| 3048 | |
| 3049 | for (int i = requested; i <= D3DMULTISAMPLE_16_SAMPLES; ++i) |
| 3050 | { |
| 3051 | if (itr->second[i] && i != D3DMULTISAMPLE_NONMASKABLE) |
| 3052 | { |
| 3053 | return i; |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | return -1; |
| 3058 | } |
| 3059 | |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 3060 | bool Context::supportsEventQueries() const |
| 3061 | { |
| 3062 | return mSupportsEventQueries; |
| 3063 | } |
| 3064 | |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 3065 | bool Context::supportsDXT1Textures() const |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 3066 | { |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 3067 | return mSupportsDXT1Textures; |
| 3068 | } |
| 3069 | |
| 3070 | bool Context::supportsDXT3Textures() const |
| 3071 | { |
| 3072 | return mSupportsDXT3Textures; |
| 3073 | } |
| 3074 | |
| 3075 | bool Context::supportsDXT5Textures() const |
| 3076 | { |
| 3077 | return mSupportsDXT5Textures; |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3080 | bool Context::supportsFloat32Textures() const |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3081 | { |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3082 | return mSupportsFloat32Textures; |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3083 | } |
| 3084 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3085 | bool Context::supportsFloat32LinearFilter() const |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3086 | { |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3087 | return mSupportsFloat32LinearFilter; |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3088 | } |
| 3089 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3090 | bool Context::supportsFloat32RenderableTextures() const |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 3091 | { |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3092 | return mSupportsFloat32RenderableTextures; |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3095 | bool Context::supportsFloat16Textures() const |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3096 | { |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3097 | return mSupportsFloat16Textures; |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3098 | } |
| 3099 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3100 | bool Context::supportsFloat16LinearFilter() const |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3101 | { |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3102 | return mSupportsFloat16LinearFilter; |
daniel@transgaming.com | 0a337e9 | 2010-08-28 17:38:27 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3105 | bool Context::supportsFloat16RenderableTextures() const |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 3106 | { |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3107 | return mSupportsFloat16RenderableTextures; |
daniel@transgaming.com | 1297d92 | 2010-09-01 15:47:47 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
daniel@transgaming.com | 5d752f2 | 2010-10-07 13:37:20 +0000 | [diff] [blame] | 3110 | int Context::getMaximumRenderbufferDimension() const |
| 3111 | { |
| 3112 | return mMaxRenderbufferDimension; |
| 3113 | } |
| 3114 | |
| 3115 | int Context::getMaximumTextureDimension() const |
| 3116 | { |
| 3117 | return mMaxTextureDimension; |
| 3118 | } |
| 3119 | |
| 3120 | int Context::getMaximumCubeTextureDimension() const |
| 3121 | { |
| 3122 | return mMaxCubeTextureDimension; |
| 3123 | } |
| 3124 | |
| 3125 | int Context::getMaximumTextureLevel() const |
| 3126 | { |
| 3127 | return mMaxTextureLevel; |
| 3128 | } |
| 3129 | |
daniel@transgaming.com | ed828e5 | 2010-10-15 17:57:30 +0000 | [diff] [blame] | 3130 | bool Context::supportsLuminanceTextures() const |
| 3131 | { |
| 3132 | return mSupportsLuminanceTextures; |
| 3133 | } |
| 3134 | |
| 3135 | bool Context::supportsLuminanceAlphaTextures() const |
| 3136 | { |
| 3137 | return mSupportsLuminanceAlphaTextures; |
| 3138 | } |
| 3139 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 3140 | bool Context::supports32bitIndices() const |
| 3141 | { |
| 3142 | return mSupports32bitIndices; |
| 3143 | } |
| 3144 | |
daniel@transgaming.com | 4f9ef0d | 2011-05-30 23:51:19 +0000 | [diff] [blame] | 3145 | bool Context::supportsNonPower2Texture() const |
| 3146 | { |
| 3147 | return mSupportsNonPower2Texture; |
| 3148 | } |
| 3149 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3150 | void Context::detachBuffer(GLuint buffer) |
| 3151 | { |
| 3152 | // [OpenGL ES 2.0.24] section 2.9 page 22: |
| 3153 | // If a buffer object is deleted while it is bound, all bindings to that object in the current context |
| 3154 | // (i.e. in the thread that called Delete-Buffers) are reset to zero. |
| 3155 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3156 | if (mState.arrayBuffer.id() == buffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3157 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3158 | mState.arrayBuffer.set(NULL); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3159 | } |
| 3160 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3161 | if (mState.elementArrayBuffer.id() == buffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3162 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3163 | mState.elementArrayBuffer.set(NULL); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++) |
| 3167 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3168 | if (mState.vertexAttribute[attribute].mBoundBuffer.id() == buffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3169 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3170 | mState.vertexAttribute[attribute].mBoundBuffer.set(NULL); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3171 | } |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | void Context::detachTexture(GLuint texture) |
| 3176 | { |
| 3177 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 3178 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 3179 | // rebound to texture object zero |
| 3180 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 3181 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3182 | { |
daniel@transgaming.com | 3f74c7a | 2011-05-11 15:36:51 +0000 | [diff] [blame] | 3183 | for (int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; sampler++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3184 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3185 | if (mState.samplerTexture[type][sampler].id() == texture) |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 3186 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3187 | mState.samplerTexture[type][sampler].set(NULL); |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 3188 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 3193 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 3194 | // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this |
| 3195 | // image was attached in the currently bound framebuffer. |
| 3196 | |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3197 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 3198 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3199 | |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3200 | if (readFramebuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3201 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3202 | readFramebuffer->detachTexture(texture); |
| 3203 | } |
| 3204 | |
| 3205 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 3206 | { |
| 3207 | drawFramebuffer->detachTexture(texture); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | void Context::detachFramebuffer(GLuint framebuffer) |
| 3212 | { |
| 3213 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
| 3214 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though |
| 3215 | // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. |
| 3216 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 3217 | if (mState.readFramebuffer == framebuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3218 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3219 | bindReadFramebuffer(0); |
| 3220 | } |
| 3221 | |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 3222 | if (mState.drawFramebuffer == framebuffer) |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3223 | { |
| 3224 | bindDrawFramebuffer(0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 3229 | { |
| 3230 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 3231 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 3232 | // had been executed with the target RENDERBUFFER and name of zero. |
| 3233 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3234 | if (mState.renderbuffer.id() == renderbuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3235 | { |
| 3236 | bindRenderbuffer(0); |
| 3237 | } |
| 3238 | |
| 3239 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 3240 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 3241 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 3242 | // point to which this image was attached in the currently bound framebuffer. |
| 3243 | |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3244 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 3245 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3246 | |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3247 | if (readFramebuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3248 | { |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 3249 | readFramebuffer->detachRenderbuffer(renderbuffer); |
| 3250 | } |
| 3251 | |
| 3252 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 3253 | { |
| 3254 | drawFramebuffer->detachRenderbuffer(renderbuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3255 | } |
| 3256 | } |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3257 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 3258 | Texture *Context::getIncompleteTexture(TextureType type) |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3259 | { |
apatrick@chromium.org | 4e3bad4 | 2010-09-15 17:31:48 +0000 | [diff] [blame] | 3260 | Texture *t = mIncompleteTextures[type].get(); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3261 | |
| 3262 | if (t == NULL) |
| 3263 | { |
| 3264 | static const GLubyte color[] = { 0, 0, 0, 255 }; |
| 3265 | |
| 3266 | switch (type) |
| 3267 | { |
| 3268 | default: |
| 3269 | UNREACHABLE(); |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 3270 | // default falls through to TEXTURE_2D |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3271 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 3272 | case TEXTURE_2D: |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3273 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3274 | Texture2D *incomplete2d = new Texture2D(Texture::INCOMPLETE_TEXTURE_ID); |
daniel@transgaming.com | 8a0a2db | 2011-03-21 16:38:20 +0000 | [diff] [blame] | 3275 | incomplete2d->setImage(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3276 | t = incomplete2d; |
| 3277 | } |
| 3278 | break; |
| 3279 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 3280 | case TEXTURE_CUBE: |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3281 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 3282 | TextureCubeMap *incompleteCube = new TextureCubeMap(Texture::INCOMPLETE_TEXTURE_ID); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3283 | |
daniel@transgaming.com | 8a0a2db | 2011-03-21 16:38:20 +0000 | [diff] [blame] | 3284 | incompleteCube->setImagePosX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 3285 | incompleteCube->setImageNegX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 3286 | incompleteCube->setImagePosY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 3287 | incompleteCube->setImageNegY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 3288 | incompleteCube->setImagePosZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 3289 | incompleteCube->setImageNegZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3290 | |
| 3291 | t = incompleteCube; |
| 3292 | } |
| 3293 | break; |
| 3294 | } |
| 3295 | |
apatrick@chromium.org | 4e3bad4 | 2010-09-15 17:31:48 +0000 | [diff] [blame] | 3296 | mIncompleteTextures[type].set(t); |
daniel@transgaming.com | 12d5407 | 2010-03-16 06:23:26 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | return t; |
| 3300 | } |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 3301 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 3302 | bool Context::cullSkipsDraw(GLenum drawMode) |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 3303 | { |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 3304 | return mState.cullFace && mState.cullMode == GL_FRONT_AND_BACK && isTriangleMode(drawMode); |
daniel@transgaming.com | ace5e66 | 2010-03-21 04:31:20 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
daniel@transgaming.com | 5af6427 | 2010-04-15 20:45:12 +0000 | [diff] [blame] | 3307 | bool Context::isTriangleMode(GLenum drawMode) |
| 3308 | { |
| 3309 | switch (drawMode) |
| 3310 | { |
| 3311 | case GL_TRIANGLES: |
| 3312 | case GL_TRIANGLE_FAN: |
| 3313 | case GL_TRIANGLE_STRIP: |
| 3314 | return true; |
| 3315 | case GL_POINTS: |
| 3316 | case GL_LINES: |
| 3317 | case GL_LINE_LOOP: |
| 3318 | case GL_LINE_STRIP: |
| 3319 | return false; |
| 3320 | default: UNREACHABLE(); |
| 3321 | } |
| 3322 | |
| 3323 | return false; |
| 3324 | } |
daniel@transgaming.com | e4b08c8 | 2010-04-20 18:53:06 +0000 | [diff] [blame] | 3325 | |
| 3326 | void Context::setVertexAttrib(GLuint index, const GLfloat *values) |
| 3327 | { |
| 3328 | ASSERT(index < gl::MAX_VERTEX_ATTRIBS); |
| 3329 | |
daniel@transgaming.com | 428d158 | 2010-05-04 03:35:25 +0000 | [diff] [blame] | 3330 | mState.vertexAttribute[index].mCurrentValue[0] = values[0]; |
| 3331 | mState.vertexAttribute[index].mCurrentValue[1] = values[1]; |
| 3332 | mState.vertexAttribute[index].mCurrentValue[2] = values[2]; |
| 3333 | mState.vertexAttribute[index].mCurrentValue[3] = values[3]; |
daniel@transgaming.com | e4b08c8 | 2010-04-20 18:53:06 +0000 | [diff] [blame] | 3334 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 3335 | mVertexDataManager->dirtyCurrentValue(index); |
daniel@transgaming.com | e4b08c8 | 2010-04-20 18:53:06 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3338 | // keep list sorted in following order |
| 3339 | // OES extensions |
| 3340 | // EXT extensions |
| 3341 | // Vendor extensions |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 3342 | void Context::initExtensionString() |
| 3343 | { |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3344 | mExtensionString = ""; |
| 3345 | |
| 3346 | // OES extensions |
| 3347 | if (supports32bitIndices()) |
| 3348 | { |
| 3349 | mExtensionString += "GL_OES_element_index_uint "; |
| 3350 | } |
| 3351 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 3352 | mExtensionString += "GL_OES_packed_depth_stencil "; |
daniel@transgaming.com | d36c297 | 2010-08-24 19:21:07 +0000 | [diff] [blame] | 3353 | mExtensionString += "GL_OES_rgb8_rgba8 "; |
alokp@chromium.org | d303ef9 | 2010-09-09 17:30:15 +0000 | [diff] [blame] | 3354 | mExtensionString += "GL_OES_standard_derivatives "; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 3355 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3356 | if (supportsFloat16Textures()) |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 3357 | { |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3358 | mExtensionString += "GL_OES_texture_half_float "; |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 3359 | } |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3360 | if (supportsFloat16LinearFilter()) |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3361 | { |
| 3362 | mExtensionString += "GL_OES_texture_half_float_linear "; |
| 3363 | } |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3364 | if (supportsFloat32Textures()) |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3365 | { |
| 3366 | mExtensionString += "GL_OES_texture_float "; |
| 3367 | } |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 3368 | if (supportsFloat32LinearFilter()) |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3369 | { |
| 3370 | mExtensionString += "GL_OES_texture_float_linear "; |
| 3371 | } |
| 3372 | |
| 3373 | if (supportsNonPower2Texture()) |
| 3374 | { |
| 3375 | mExtensionString += "GL_OES_texture_npot "; |
| 3376 | } |
| 3377 | |
| 3378 | // Multi-vendor (EXT) extensions |
| 3379 | mExtensionString += "GL_EXT_read_format_bgra "; |
apatrick@chromium.org | d3bd0ad | 2010-08-30 18:55:36 +0000 | [diff] [blame] | 3380 | |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 3381 | if (supportsDXT1Textures()) |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 3382 | { |
| 3383 | mExtensionString += "GL_EXT_texture_compression_dxt1 "; |
| 3384 | } |
daniel@transgaming.com | d470a1b | 2010-08-24 19:20:48 +0000 | [diff] [blame] | 3385 | |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3386 | mExtensionString += "GL_EXT_texture_format_BGRA8888 "; |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 3387 | |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3388 | // ANGLE-specific extensions |
| 3389 | mExtensionString += "GL_ANGLE_framebuffer_blit "; |
daniel@transgaming.com | 3ea20e7 | 2010-08-24 19:20:58 +0000 | [diff] [blame] | 3390 | if (getMaxSupportedSamples() != 0) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3391 | { |
| 3392 | mExtensionString += "GL_ANGLE_framebuffer_multisample "; |
| 3393 | } |
| 3394 | |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3395 | if (supportsDXT3Textures()) |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 3396 | { |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3397 | mExtensionString += "GL_ANGLE_texture_compression_dxt3 "; |
| 3398 | } |
| 3399 | if (supportsDXT5Textures()) |
| 3400 | { |
| 3401 | mExtensionString += "GL_ANGLE_texture_compression_dxt5 "; |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 3402 | } |
zmo@google.com | a574f78 | 2011-10-03 21:45:23 +0000 | [diff] [blame] | 3403 | mExtensionString += "GL_ANGLE_translated_shader_source "; |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 3404 | |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3405 | // Other vendor-specific extensions |
| 3406 | if (supportsEventQueries()) |
daniel@transgaming.com | 4f9ef0d | 2011-05-30 23:51:19 +0000 | [diff] [blame] | 3407 | { |
daniel@transgaming.com | 8440e3f | 2011-09-26 18:25:12 +0000 | [diff] [blame] | 3408 | mExtensionString += "GL_NV_fence "; |
daniel@transgaming.com | 4f9ef0d | 2011-05-30 23:51:19 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
daniel@transgaming.com | 3e4c600 | 2010-05-05 18:50:13 +0000 | [diff] [blame] | 3411 | std::string::size_type end = mExtensionString.find_last_not_of(' '); |
| 3412 | if (end != std::string::npos) |
| 3413 | { |
| 3414 | mExtensionString.resize(end+1); |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | const char *Context::getExtensionString() const |
| 3419 | { |
| 3420 | return mExtensionString.c_str(); |
| 3421 | } |
| 3422 | |
daniel@transgaming.com | c23ff64 | 2011-08-16 20:28:45 +0000 | [diff] [blame] | 3423 | void Context::initRendererString() |
| 3424 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 3425 | D3DADAPTER_IDENTIFIER9 *identifier = mDisplay->getAdapterIdentifier(); |
daniel@transgaming.com | c23ff64 | 2011-08-16 20:28:45 +0000 | [diff] [blame] | 3426 | |
| 3427 | mRendererString = "ANGLE ("; |
| 3428 | mRendererString += identifier->Description; |
| 3429 | mRendererString += ")"; |
| 3430 | } |
| 3431 | |
| 3432 | const char *Context::getRendererString() const |
| 3433 | { |
| 3434 | return mRendererString.c_str(); |
| 3435 | } |
| 3436 | |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3437 | void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 3438 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 3439 | GLbitfield mask) |
| 3440 | { |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3441 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 3442 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 3443 | |
| 3444 | if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE || |
| 3445 | !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 3446 | { |
| 3447 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 3448 | } |
| 3449 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3450 | if (drawFramebuffer->getSamples() != 0) |
| 3451 | { |
| 3452 | return error(GL_INVALID_OPERATION); |
| 3453 | } |
| 3454 | |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 3455 | int readBufferWidth = readFramebuffer->getColorbuffer()->getWidth(); |
| 3456 | int readBufferHeight = readFramebuffer->getColorbuffer()->getHeight(); |
| 3457 | int drawBufferWidth = drawFramebuffer->getColorbuffer()->getWidth(); |
| 3458 | int drawBufferHeight = drawFramebuffer->getColorbuffer()->getHeight(); |
| 3459 | |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3460 | RECT sourceRect; |
| 3461 | RECT destRect; |
| 3462 | |
| 3463 | if (srcX0 < srcX1) |
| 3464 | { |
| 3465 | sourceRect.left = srcX0; |
| 3466 | sourceRect.right = srcX1; |
| 3467 | destRect.left = dstX0; |
| 3468 | destRect.right = dstX1; |
| 3469 | } |
| 3470 | else |
| 3471 | { |
| 3472 | sourceRect.left = srcX1; |
| 3473 | destRect.left = dstX1; |
| 3474 | sourceRect.right = srcX0; |
| 3475 | destRect.right = dstX0; |
| 3476 | } |
| 3477 | |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3478 | if (srcY0 < srcY1) |
| 3479 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 3480 | sourceRect.top = readBufferHeight - srcY1; |
| 3481 | destRect.top = drawBufferHeight - dstY1; |
| 3482 | sourceRect.bottom = readBufferHeight - srcY0; |
| 3483 | destRect.bottom = drawBufferHeight - dstY0; |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3484 | } |
| 3485 | else |
| 3486 | { |
apatrick@chromium.org | b31f532 | 2011-01-19 19:02:52 +0000 | [diff] [blame] | 3487 | sourceRect.top = readBufferHeight - srcY0; |
| 3488 | destRect.top = drawBufferHeight - dstY0; |
| 3489 | sourceRect.bottom = readBufferHeight - srcY1; |
| 3490 | destRect.bottom = drawBufferHeight - dstY1; |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | RECT sourceScissoredRect = sourceRect; |
| 3494 | RECT destScissoredRect = destRect; |
| 3495 | |
| 3496 | if (mState.scissorTest) |
| 3497 | { |
| 3498 | // Only write to parts of the destination framebuffer which pass the scissor test |
| 3499 | // Please note: the destRect is now in D3D-style coordinates, so the *top* of the |
| 3500 | // rect will be checked against scissorY, rather than the bottom. |
| 3501 | if (destRect.left < mState.scissorX) |
| 3502 | { |
| 3503 | int xDiff = mState.scissorX - destRect.left; |
| 3504 | destScissoredRect.left = mState.scissorX; |
| 3505 | sourceScissoredRect.left += xDiff; |
| 3506 | } |
| 3507 | |
| 3508 | if (destRect.right > mState.scissorX + mState.scissorWidth) |
| 3509 | { |
| 3510 | int xDiff = destRect.right - (mState.scissorX + mState.scissorWidth); |
| 3511 | destScissoredRect.right = mState.scissorX + mState.scissorWidth; |
| 3512 | sourceScissoredRect.right -= xDiff; |
| 3513 | } |
| 3514 | |
| 3515 | if (destRect.top < mState.scissorY) |
| 3516 | { |
| 3517 | int yDiff = mState.scissorY - destRect.top; |
| 3518 | destScissoredRect.top = mState.scissorY; |
| 3519 | sourceScissoredRect.top += yDiff; |
| 3520 | } |
| 3521 | |
| 3522 | if (destRect.bottom > mState.scissorY + mState.scissorHeight) |
| 3523 | { |
| 3524 | int yDiff = destRect.bottom - (mState.scissorY + mState.scissorHeight); |
| 3525 | destScissoredRect.bottom = mState.scissorY + mState.scissorHeight; |
| 3526 | sourceScissoredRect.bottom -= yDiff; |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | bool blitRenderTarget = false; |
| 3531 | bool blitDepthStencil = false; |
| 3532 | |
| 3533 | RECT sourceTrimmedRect = sourceScissoredRect; |
| 3534 | RECT destTrimmedRect = destScissoredRect; |
| 3535 | |
| 3536 | // The source & destination rectangles also may need to be trimmed if they fall out of the bounds of |
| 3537 | // the actual draw and read surfaces. |
| 3538 | if (sourceTrimmedRect.left < 0) |
| 3539 | { |
| 3540 | int xDiff = 0 - sourceTrimmedRect.left; |
| 3541 | sourceTrimmedRect.left = 0; |
| 3542 | destTrimmedRect.left += xDiff; |
| 3543 | } |
| 3544 | |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3545 | if (sourceTrimmedRect.right > readBufferWidth) |
| 3546 | { |
| 3547 | int xDiff = sourceTrimmedRect.right - readBufferWidth; |
| 3548 | sourceTrimmedRect.right = readBufferWidth; |
| 3549 | destTrimmedRect.right -= xDiff; |
| 3550 | } |
| 3551 | |
| 3552 | if (sourceTrimmedRect.top < 0) |
| 3553 | { |
| 3554 | int yDiff = 0 - sourceTrimmedRect.top; |
| 3555 | sourceTrimmedRect.top = 0; |
| 3556 | destTrimmedRect.top += yDiff; |
| 3557 | } |
| 3558 | |
| 3559 | if (sourceTrimmedRect.bottom > readBufferHeight) |
| 3560 | { |
| 3561 | int yDiff = sourceTrimmedRect.bottom - readBufferHeight; |
| 3562 | sourceTrimmedRect.bottom = readBufferHeight; |
| 3563 | destTrimmedRect.bottom -= yDiff; |
| 3564 | } |
| 3565 | |
| 3566 | if (destTrimmedRect.left < 0) |
| 3567 | { |
| 3568 | int xDiff = 0 - destTrimmedRect.left; |
| 3569 | destTrimmedRect.left = 0; |
| 3570 | sourceTrimmedRect.left += xDiff; |
| 3571 | } |
| 3572 | |
| 3573 | if (destTrimmedRect.right > drawBufferWidth) |
| 3574 | { |
| 3575 | int xDiff = destTrimmedRect.right - drawBufferWidth; |
| 3576 | destTrimmedRect.right = drawBufferWidth; |
| 3577 | sourceTrimmedRect.right -= xDiff; |
| 3578 | } |
| 3579 | |
| 3580 | if (destTrimmedRect.top < 0) |
| 3581 | { |
| 3582 | int yDiff = 0 - destTrimmedRect.top; |
| 3583 | destTrimmedRect.top = 0; |
| 3584 | sourceTrimmedRect.top += yDiff; |
| 3585 | } |
| 3586 | |
| 3587 | if (destTrimmedRect.bottom > drawBufferHeight) |
| 3588 | { |
| 3589 | int yDiff = destTrimmedRect.bottom - drawBufferHeight; |
| 3590 | destTrimmedRect.bottom = drawBufferHeight; |
| 3591 | sourceTrimmedRect.bottom -= yDiff; |
| 3592 | } |
| 3593 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3594 | bool partialBufferCopy = false; |
daniel@transgaming.com | 3aba733 | 2011-01-14 15:08:35 +0000 | [diff] [blame] | 3595 | if (sourceTrimmedRect.bottom - sourceTrimmedRect.top < readBufferHeight || |
| 3596 | sourceTrimmedRect.right - sourceTrimmedRect.left < readBufferWidth || |
| 3597 | destTrimmedRect.bottom - destTrimmedRect.top < drawBufferHeight || |
| 3598 | destTrimmedRect.right - destTrimmedRect.left < drawBufferWidth || |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3599 | sourceTrimmedRect.top != 0 || destTrimmedRect.top != 0 || sourceTrimmedRect.left != 0 || destTrimmedRect.left != 0) |
| 3600 | { |
| 3601 | partialBufferCopy = true; |
| 3602 | } |
| 3603 | |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3604 | if (mask & GL_COLOR_BUFFER_BIT) |
| 3605 | { |
enne@chromium.org | 0fa7463 | 2010-09-21 16:18:52 +0000 | [diff] [blame] | 3606 | const bool validReadType = readFramebuffer->getColorbufferType() == GL_TEXTURE_2D || |
| 3607 | readFramebuffer->getColorbufferType() == GL_RENDERBUFFER; |
| 3608 | const bool validDrawType = drawFramebuffer->getColorbufferType() == GL_TEXTURE_2D || |
| 3609 | drawFramebuffer->getColorbufferType() == GL_RENDERBUFFER; |
| 3610 | if (!validReadType || !validDrawType || |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3611 | readFramebuffer->getColorbuffer()->getD3DFormat() != drawFramebuffer->getColorbuffer()->getD3DFormat()) |
| 3612 | { |
| 3613 | ERR("Color buffer format conversion in BlitFramebufferANGLE not supported by this implementation"); |
| 3614 | return error(GL_INVALID_OPERATION); |
| 3615 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3616 | |
| 3617 | if (partialBufferCopy && readFramebuffer->getSamples() != 0) |
| 3618 | { |
| 3619 | return error(GL_INVALID_OPERATION); |
| 3620 | } |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3621 | |
| 3622 | blitRenderTarget = true; |
| 3623 | |
| 3624 | } |
| 3625 | |
| 3626 | if (mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 3627 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 3628 | Renderbuffer *readDSBuffer = NULL; |
| 3629 | Renderbuffer *drawDSBuffer = NULL; |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3630 | |
| 3631 | // We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have |
| 3632 | // both a depth and stencil buffer, it will be the same buffer. |
| 3633 | |
| 3634 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 3635 | { |
| 3636 | if (readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer()) |
| 3637 | { |
| 3638 | if (readFramebuffer->getDepthbufferType() != drawFramebuffer->getDepthbufferType() || |
| 3639 | readFramebuffer->getDepthbuffer()->getD3DFormat() != drawFramebuffer->getDepthbuffer()->getD3DFormat()) |
| 3640 | { |
| 3641 | return error(GL_INVALID_OPERATION); |
| 3642 | } |
| 3643 | |
| 3644 | blitDepthStencil = true; |
| 3645 | readDSBuffer = readFramebuffer->getDepthbuffer(); |
| 3646 | drawDSBuffer = drawFramebuffer->getDepthbuffer(); |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 3651 | { |
| 3652 | if (readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer()) |
| 3653 | { |
| 3654 | if (readFramebuffer->getStencilbufferType() != drawFramebuffer->getStencilbufferType() || |
| 3655 | readFramebuffer->getStencilbuffer()->getD3DFormat() != drawFramebuffer->getStencilbuffer()->getD3DFormat()) |
| 3656 | { |
| 3657 | return error(GL_INVALID_OPERATION); |
| 3658 | } |
| 3659 | |
| 3660 | blitDepthStencil = true; |
| 3661 | readDSBuffer = readFramebuffer->getStencilbuffer(); |
| 3662 | drawDSBuffer = drawFramebuffer->getStencilbuffer(); |
| 3663 | } |
| 3664 | } |
| 3665 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3666 | if (partialBufferCopy) |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3667 | { |
| 3668 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 3669 | return error(GL_INVALID_OPERATION); // only whole-buffer copies are permitted |
| 3670 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3671 | |
daniel@transgaming.com | 97446d2 | 2010-08-24 19:20:54 +0000 | [diff] [blame] | 3672 | if ((drawDSBuffer && drawDSBuffer->getSamples() != 0) || |
| 3673 | (readDSBuffer && readDSBuffer->getSamples() != 0)) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 3674 | { |
| 3675 | return error(GL_INVALID_OPERATION); |
| 3676 | } |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | if (blitRenderTarget || blitDepthStencil) |
| 3680 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 3681 | mDisplay->endScene(); |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3682 | |
| 3683 | if (blitRenderTarget) |
| 3684 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 3685 | HRESULT result = mDevice->StretchRect(readFramebuffer->getRenderTarget(), &sourceTrimmedRect, |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3686 | drawFramebuffer->getRenderTarget(), &destTrimmedRect, D3DTEXF_NONE); |
| 3687 | |
| 3688 | if (FAILED(result)) |
| 3689 | { |
| 3690 | ERR("BlitFramebufferANGLE failed: StretchRect returned %x.", result); |
| 3691 | return; |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | if (blitDepthStencil) |
| 3696 | { |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 3697 | HRESULT result = mDevice->StretchRect(readFramebuffer->getDepthStencil(), NULL, drawFramebuffer->getDepthStencil(), NULL, D3DTEXF_NONE); |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 3698 | |
| 3699 | if (FAILED(result)) |
| 3700 | { |
| 3701 | ERR("BlitFramebufferANGLE failed: StretchRect returned %x.", result); |
| 3702 | return; |
| 3703 | } |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3708 | VertexDeclarationCache::VertexDeclarationCache() : mMaxLru(0) |
| 3709 | { |
| 3710 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3711 | { |
| 3712 | mVertexDeclCache[i].vertexDeclaration = NULL; |
| 3713 | mVertexDeclCache[i].lruCount = 0; |
| 3714 | } |
| 3715 | } |
| 3716 | |
| 3717 | VertexDeclarationCache::~VertexDeclarationCache() |
| 3718 | { |
| 3719 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3720 | { |
| 3721 | if (mVertexDeclCache[i].vertexDeclaration) |
| 3722 | { |
| 3723 | mVertexDeclCache[i].vertexDeclaration->Release(); |
| 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | |
daniel@transgaming.com | c941e25 | 2011-10-26 02:32:31 +0000 | [diff] [blame] | 3728 | GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], Program *program) |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3729 | { |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3730 | D3DVERTEXELEMENT9 elements[MAX_VERTEX_ATTRIBS + 1]; |
| 3731 | D3DVERTEXELEMENT9 *element = &elements[0]; |
| 3732 | |
| 3733 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 3734 | { |
| 3735 | if (attributes[i].active) |
| 3736 | { |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 3737 | if (mAppliedVBs[i].serial != attributes[i].serial || |
| 3738 | mAppliedVBs[i].stride != attributes[i].stride || |
| 3739 | mAppliedVBs[i].offset != attributes[i].offset) |
| 3740 | { |
| 3741 | device->SetStreamSource(i, attributes[i].vertexBuffer, attributes[i].offset, attributes[i].stride); |
| 3742 | mAppliedVBs[i].serial = attributes[i].serial; |
| 3743 | mAppliedVBs[i].stride = attributes[i].stride; |
| 3744 | mAppliedVBs[i].offset = attributes[i].offset; |
| 3745 | } |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3746 | |
| 3747 | element->Stream = i; |
| 3748 | element->Offset = 0; |
| 3749 | element->Type = attributes[i].type; |
| 3750 | element->Method = D3DDECLMETHOD_DEFAULT; |
| 3751 | element->Usage = D3DDECLUSAGE_TEXCOORD; |
| 3752 | element->UsageIndex = program->getSemanticIndex(i); |
| 3753 | element++; |
| 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | static const D3DVERTEXELEMENT9 end = D3DDECL_END(); |
| 3758 | *(element++) = end; |
| 3759 | |
| 3760 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3761 | { |
| 3762 | VertexDeclCacheEntry *entry = &mVertexDeclCache[i]; |
| 3763 | if (memcmp(entry->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)) == 0 && entry->vertexDeclaration) |
| 3764 | { |
| 3765 | entry->lruCount = ++mMaxLru; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 3766 | if(entry->vertexDeclaration != mLastSetVDecl) |
| 3767 | { |
| 3768 | device->SetVertexDeclaration(entry->vertexDeclaration); |
| 3769 | mLastSetVDecl = entry->vertexDeclaration; |
| 3770 | } |
| 3771 | |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3772 | return GL_NO_ERROR; |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | VertexDeclCacheEntry *lastCache = mVertexDeclCache; |
| 3777 | |
| 3778 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3779 | { |
| 3780 | if (mVertexDeclCache[i].lruCount < lastCache->lruCount) |
| 3781 | { |
| 3782 | lastCache = &mVertexDeclCache[i]; |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | if (lastCache->vertexDeclaration != NULL) |
| 3787 | { |
| 3788 | lastCache->vertexDeclaration->Release(); |
| 3789 | lastCache->vertexDeclaration = NULL; |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 3790 | // mLastSetVDecl is set to the replacement, so we don't have to worry |
| 3791 | // about it. |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)); |
| 3795 | device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration); |
| 3796 | device->SetVertexDeclaration(lastCache->vertexDeclaration); |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 3797 | mLastSetVDecl = lastCache->vertexDeclaration; |
daniel@transgaming.com | 09c2c1a | 2011-04-13 14:57:16 +0000 | [diff] [blame] | 3798 | lastCache->lruCount = ++mMaxLru; |
| 3799 | |
| 3800 | return GL_NO_ERROR; |
| 3801 | } |
| 3802 | |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 3803 | void VertexDeclarationCache::markStateDirty() |
| 3804 | { |
| 3805 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 3806 | { |
| 3807 | mAppliedVBs[i].serial = 0; |
| 3808 | } |
| 3809 | |
| 3810 | mLastSetVDecl = NULL; |
| 3811 | } |
| 3812 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | extern "C" |
| 3816 | { |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 3817 | gl::Context *glCreateContext(const egl::Config *config, const gl::Context *shareContext) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3818 | { |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 3819 | return new gl::Context(config, shareContext); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | void glDestroyContext(gl::Context *context) |
| 3823 | { |
| 3824 | delete context; |
| 3825 | |
| 3826 | if (context == gl::getContext()) |
| 3827 | { |
| 3828 | gl::makeCurrent(NULL, NULL, NULL); |
| 3829 | } |
| 3830 | } |
| 3831 | |
| 3832 | void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface) |
| 3833 | { |
| 3834 | gl::makeCurrent(context, display, surface); |
| 3835 | } |
| 3836 | |
| 3837 | gl::Context *glGetCurrentContext() |
| 3838 | { |
| 3839 | return gl::getContext(); |
| 3840 | } |
| 3841 | } |