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