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