| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
| 10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, | 1124 bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| 1125 int width, int height) { | 1125 int width, int height) { |
| 1126 | 1126 |
| 1127 // All internally created RTs are also textures. We don't create | 1127 // All internally created RTs are also textures. We don't create |
| 1128 // SBs for a client's standalone RT (that is a RT that isn't also a texture)
. | 1128 // SBs for a client's standalone RT (that is a RT that isn't also a texture)
. |
| 1129 SkASSERT(rt->asTexture()); | 1129 SkASSERT(rt->asTexture()); |
| 1130 SkASSERT(width >= rt->width()); | 1130 SkASSERT(width >= rt->width()); |
| 1131 SkASSERT(height >= rt->height()); | 1131 SkASSERT(height >= rt->height()); |
| 1132 | 1132 |
| 1133 int samples = rt->numSamples(); | 1133 int samples = rt->numSamples(); |
| 1134 GrGLuint sbID; | 1134 GrGLuint sbID = 0; |
| 1135 GL_CALL(GenRenderbuffers(1, &sbID)); | |
| 1136 if (!sbID) { | |
| 1137 return false; | |
| 1138 } | |
| 1139 | 1135 |
| 1140 int stencilFmtCnt = this->glCaps().stencilFormats().count(); | 1136 int stencilFmtCnt = this->glCaps().stencilFormats().count(); |
| 1141 for (int i = 0; i < stencilFmtCnt; ++i) { | 1137 for (int i = 0; i < stencilFmtCnt; ++i) { |
| 1138 if (!sbID) { |
| 1139 GL_CALL(GenRenderbuffers(1, &sbID)); |
| 1140 } |
| 1141 if (!sbID) { |
| 1142 return false; |
| 1143 } |
| 1142 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); | 1144 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); |
| 1143 // we start with the last stencil format that succeeded in hopes | 1145 // we start with the last stencil format that succeeded in hopes |
| 1144 // that we won't go through this loop more than once after the | 1146 // that we won't go through this loop more than once after the |
| 1145 // first (painful) stencil creation. | 1147 // first (painful) stencil creation. |
| 1146 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; | 1148 int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
| 1147 const GrGLCaps::StencilFormat& sFmt = | 1149 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sI
dx]; |
| 1148 this->glCaps().stencilFormats()[sIdx]; | |
| 1149 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1150 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1150 // we do this "if" so that we don't call the multisample | 1151 // we do this "if" so that we don't call the multisample |
| 1151 // version on a GL that doesn't have an MSAA extension. | 1152 // version on a GL that doesn't have an MSAA extension. |
| 1152 bool created; | 1153 bool created; |
| 1153 if (samples > 0) { | 1154 if (samples > 0) { |
| 1154 created = renderbuffer_storage_msaa(fGLContext, | 1155 created = renderbuffer_storage_msaa(fGLContext, |
| 1155 samples, | 1156 samples, |
| 1156 sFmt.fInternalFormat, | 1157 sFmt.fInternalFormat, |
| 1157 width, height); | 1158 width, height); |
| 1158 } else { | 1159 } else { |
| 1159 GL_ALLOC_CALL(this->glInterface(), | 1160 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERB
UFFER, |
| 1160 RenderbufferStorage(GR_GL_RENDERBUFFER, | 1161 sFmt.fInterna
lFormat, |
| 1161 sFmt.fInternalFormat, | 1162 width, height
)); |
| 1162 width, height)); | 1163 created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glI
nterface())); |
| 1163 created = | |
| 1164 (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterfa
ce())); | |
| 1165 } | 1164 } |
| 1166 if (created) { | 1165 if (created) { |
| 1167 // After sized formats we attempt an unsized format and take | 1166 // After sized formats we attempt an unsized format and take |
| 1168 // whatever sizes GL gives us. In that case we query for the size. | 1167 // whatever sizes GL gives us. In that case we query for the size. |
| 1169 GrGLStencilBuffer::Format format = sFmt; | 1168 GrGLStencilBuffer::Format format = sFmt; |
| 1170 get_stencil_rb_sizes(this->glInterface(), &format); | 1169 get_stencil_rb_sizes(this->glInterface(), &format); |
| 1171 static const bool kIsWrapped = false; | 1170 static const bool kIsWrapped = false; |
| 1172 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, | 1171 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
| 1173 (this, kIsWrapped, sbID, width
, height, | 1172 (this, kIsWrapped, sbID, width
, height, |
| 1174 samples, format))); | 1173 samples, format))); |
| 1174 // If we fail we have to create a new render buffer ID since we gave
this one to the |
| 1175 // GrGLStencilBuffer object. |
| 1176 sbID = 0; |
| 1175 if (this->attachStencilBufferToRenderTarget(sb, rt)) { | 1177 if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
| 1176 fLastSuccessfulStencilFmtIdx = sIdx; | 1178 fLastSuccessfulStencilFmtIdx = sIdx; |
| 1177 sb->transferToCache(); | 1179 sb->transferToCache(); |
| 1178 rt->setStencilBuffer(sb); | 1180 rt->setStencilBuffer(sb); |
| 1179 return true; | 1181 return true; |
| 1180 } | 1182 } |
| 1181 sb->abandon(); // otherwise we lose sbID | |
| 1182 } | 1183 } |
| 1183 } | 1184 } |
| 1184 GL_CALL(DeleteRenderbuffers(1, &sbID)); | 1185 GL_CALL(DeleteRenderbuffers(1, &sbID)); |
| 1185 return false; | 1186 return false; |
| 1186 } | 1187 } |
| 1187 | 1188 |
| 1188 bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar
get* rt) { | 1189 bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar
get* rt) { |
| 1189 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); | 1190 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
| 1190 | 1191 |
| 1191 GrGLuint fbo = glrt->renderFBOID(); | 1192 GrGLuint fbo = glrt->renderFBOID(); |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2554 this->setVertexArrayID(gpu, 0); | 2555 this->setVertexArrayID(gpu, 0); |
| 2555 } | 2556 } |
| 2556 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2557 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2557 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2558 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2558 fDefaultVertexArrayAttribState.resize(attrCount); | 2559 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2559 } | 2560 } |
| 2560 attribState = &fDefaultVertexArrayAttribState; | 2561 attribState = &fDefaultVertexArrayAttribState; |
| 2561 } | 2562 } |
| 2562 return attribState; | 2563 return attribState; |
| 2563 } | 2564 } |
| OLD | NEW |