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