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