Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: src/gpu/gl/GrGpuGL.cpp

Issue 12875005: Add support for IMG's MSAA extension. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLInterface.cpp ('k') | src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 // Enable supported shader-related caps 279 // Enable supported shader-related caps
280 if (kDesktop_GrGLBinding == this->glBinding()) { 280 if (kDesktop_GrGLBinding == this->glBinding()) {
281 caps->fDualSourceBlendingSupport = this->glVersion() >= GR_GL_VER(3,3) | | 281 caps->fDualSourceBlendingSupport = this->glVersion() >= GR_GL_VER(3,3) | |
282 this->hasExtension("GL_ARB_blend_func _extended"); 282 this->hasExtension("GL_ARB_blend_func _extended");
283 caps->fShaderDerivativeSupport = true; 283 caps->fShaderDerivativeSupport = true;
284 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS 284 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
285 caps->fGeometryShaderSupport = this->glVersion() >= GR_GL_VER(3,2) && 285 caps->fGeometryShaderSupport = this->glVersion() >= GR_GL_VER(3,2) &&
286 this->glslGeneration() >= k150_GrGLSLGene ration; 286 this->glslGeneration() >= k150_GrGLSLGene ration;
287 } else { 287 } else {
288 caps->fShaderDerivativeSupport = 288 caps->fShaderDerivativeSupport = this->hasExtension("GL_OES_standard_der ivatives");
289 this->hasExtension("GL_OES_standard_derivatives");
290 } 289 }
291 290
292 if (GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType()) { 291 if (GrGLCaps::kImaginationES_MSFBOType == this->glCaps().msFBOType()) {
292 GR_GL_GetIntegerv(this->glInterface(), GR_GL_MAX_SAMPLES_IMG, &caps->fMa xSampleCount);
293 } else if (GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType()) {
293 GR_GL_GetIntegerv(this->glInterface(), GR_GL_MAX_SAMPLES, &caps->fMaxSam pleCount); 294 GR_GL_GetIntegerv(this->glInterface(), GR_GL_MAX_SAMPLES, &caps->fMaxSam pleCount);
294 } 295 }
295 } 296 }
296 297
297 void GrGpuGL::fillInConfigRenderableTable() { 298 void GrGpuGL::fillInConfigRenderableTable() {
298 299
299 // OpenGL < 3.0 300 // OpenGL < 3.0
300 // no support for render targets unless the GL_ARB_framebuffer_object 301 // no support for render targets unless the GL_ARB_framebuffer_object
301 // extension is supported (in which case we get ALPHA, RED, RG, RGB, 302 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
302 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we 303 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 GrGLenum status; 873 GrGLenum status;
873 874
874 GrGLenum msColorFormat = 0; // suppress warning 875 GrGLenum msColorFormat = 0; // suppress warning
875 876
876 GL_CALL(GenFramebuffers(1, &desc->fTexFBOID)); 877 GL_CALL(GenFramebuffers(1, &desc->fTexFBOID));
877 if (!desc->fTexFBOID) { 878 if (!desc->fTexFBOID) {
878 goto FAILED; 879 goto FAILED;
879 } 880 }
880 881
881 882
882 // If we are using multisampling we will create two FBOS. We render 883 // If we are using multisampling we will create two FBOS. We render to one a nd then resolve to
883 // to one and then resolve to the texture bound to the other. 884 // the texture bound to the other. The exception is the IMG multisample exte nsion. With this
884 if (desc->fSampleCnt > 0) { 885 // extension the texture is multisampled when rendered to and then auto-reso lves it when it is
886 // rendered from.
887 if (desc->fSampleCnt > 0 && GrGLCaps::kImaginationES_MSFBOType != this->glCa ps().msFBOType()) {
885 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) { 888 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) {
886 goto FAILED; 889 goto FAILED;
887 } 890 }
888 GL_CALL(GenFramebuffers(1, &desc->fRTFBOID)); 891 GL_CALL(GenFramebuffers(1, &desc->fRTFBOID));
889 GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID)); 892 GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
890 if (!desc->fRTFBOID || 893 if (!desc->fRTFBOID ||
891 !desc->fMSColorRenderbufferID || 894 !desc->fMSColorRenderbufferID ||
892 !this->configToGLFormats(desc->fConfig, 895 !this->configToGLFormats(desc->fConfig,
893 // GLES requires sized internal formats 896 // GLES requires sized internal formats
894 kES2_GrGLBinding == this->glBinding(), 897 kES2_GrGLBinding == this->glBinding(),
(...skipping 19 matching lines...) Expand all
914 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); 917 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
915 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 918 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
916 GR_GL_COLOR_ATTACHMENT0, 919 GR_GL_COLOR_ATTACHMENT0,
917 GR_GL_RENDERBUFFER, 920 GR_GL_RENDERBUFFER,
918 desc->fMSColorRenderbufferID)); 921 desc->fMSColorRenderbufferID));
919 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { 922 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) {
920 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 923 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
921 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 924 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
922 goto FAILED; 925 goto FAILED;
923 } 926 }
924 fGLContext.info().caps().markConfigAsValidColorAttachment( 927 fGLContext.info().caps().markConfigAsValidColorAttachment(desc->fCon fig);
925 desc->fConfig);
926 } 928 }
927 } 929 }
928 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); 930 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
929 931
930 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, 932 if (GrGLCaps::kImaginationES_MSFBOType == this->glCaps().msFBOType() && desc ->fSampleCnt > 0) {
931 GR_GL_COLOR_ATTACHMENT0, 933 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER,
932 GR_GL_TEXTURE_2D, 934 GR_GL_COLOR_ATTACHMENT0,
933 texID, 0)); 935 GR_GL_TEXTURE_2D,
936 texID, 0, desc->fSampleCnt));
937 } else {
938 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
939 GR_GL_COLOR_ATTACHMENT0,
940 GR_GL_TEXTURE_2D,
941 texID, 0));
942 }
934 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { 943 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) {
935 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 944 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
936 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 945 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
937 goto FAILED; 946 goto FAILED;
938 } 947 }
939 fGLContext.info().caps().markConfigAsValidColorAttachment(desc->fConfig) ; 948 fGLContext.info().caps().markConfigAsValidColorAttachment(desc->fConfig) ;
940 } 949 }
941 950
942 return true; 951 return true;
943 952
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 rt->setStencilBuffer(sb); 1174 rt->setStencilBuffer(sb);
1166 return true; 1175 return true;
1167 } 1176 }
1168 sb->abandon(); // otherwise we lose sbID 1177 sb->abandon(); // otherwise we lose sbID
1169 } 1178 }
1170 } 1179 }
1171 GL_CALL(DeleteRenderbuffers(1, &sbID)); 1180 GL_CALL(DeleteRenderbuffers(1, &sbID));
1172 return false; 1181 return false;
1173 } 1182 }
1174 1183
1175 bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, 1184 bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar get* rt) {
1176 GrRenderTarget* rt) {
1177 GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt; 1185 GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt;
1178 1186
1179 GrGLuint fbo = glrt->renderFBOID(); 1187 GrGLuint fbo = glrt->renderFBOID();
1180 1188
1181 if (NULL == sb) { 1189 if (NULL == sb) {
1182 if (NULL != rt->getStencilBuffer()) { 1190 if (NULL != rt->getStencilBuffer()) {
1183 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1191 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1184 GR_GL_STENCIL_ATTACHMENT, 1192 GR_GL_STENCIL_ATTACHMENT,
1185 GR_GL_RENDERBUFFER, 0)); 1193 GR_GL_RENDERBUFFER, 0));
1186 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1194 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1187 GR_GL_DEPTH_ATTACHMENT, 1195 GR_GL_DEPTH_ATTACHMENT,
1188 GR_GL_RENDERBUFFER, 0)); 1196 GR_GL_RENDERBUFFER, 0));
1189 #if GR_DEBUG 1197 #if GR_DEBUG
1190 GrGLenum status; 1198 GrGLenum status;
1191 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1199 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1192 GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status); 1200 GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status);
1193 #endif 1201 #endif
1194 } 1202 }
1195 return true; 1203 return true;
1196 } else { 1204 } else {
1197 GrGLStencilBuffer* glsb = (GrGLStencilBuffer*) sb; 1205 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb);
1198 GrGLuint rb = glsb->renderbufferID(); 1206 GrGLuint rb = glsb->renderbufferID();
1199 1207
1200 fHWBoundRenderTarget = NULL; 1208 fHWBoundRenderTarget = NULL;
1201 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); 1209 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
1202 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1210 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1203 GR_GL_STENCIL_ATTACHMENT, 1211 GR_GL_STENCIL_ATTACHMENT,
1204 GR_GL_RENDERBUFFER, rb)); 1212 GR_GL_RENDERBUFFER, rb));
1205 if (glsb->format().fPacked) { 1213 if (glsb->format().fPacked) {
1206 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1214 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1207 GR_GL_DEPTH_ATTACHMENT, 1215 GR_GL_DEPTH_ATTACHMENT,
1208 GR_GL_RENDERBUFFER, rb)); 1216 GR_GL_RENDERBUFFER, rb));
1209 } else { 1217 } else {
1210 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1218 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1211 GR_GL_DEPTH_ATTACHMENT, 1219 GR_GL_DEPTH_ATTACHMENT,
1212 GR_GL_RENDERBUFFER, 0)); 1220 GR_GL_RENDERBUFFER, 0));
1213 } 1221 }
1214 1222
1215 GrGLenum status; 1223 GrGLenum status;
1216 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), 1224 if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) {
1217 glsb->format())) {
1218 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); 1225 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
1219 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { 1226 if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
1220 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1227 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1221 GR_GL_STENCIL_ATTACHMENT, 1228 GR_GL_STENCIL_ATTACHMENT,
1222 GR_GL_RENDERBUFFER, 0)); 1229 GR_GL_RENDERBUFFER, 0));
1223 if (glsb->format().fPacked) { 1230 if (glsb->format().fPacked) {
1224 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 1231 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
1225 GR_GL_DEPTH_ATTACHMENT, 1232 GR_GL_DEPTH_ATTACHMENT,
1226 GR_GL_RENDERBUFFER, 0)); 1233 GR_GL_RENDERBUFFER, 0));
1227 } 1234 }
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 default: 1767 default:
1761 // Only the above two fill rules are allowed. 1768 // Only the above two fill rules are allowed.
1762 GrCrash("Unexpected path fill."); 1769 GrCrash("Unexpected path fill.");
1763 return; // suppress unused var warning. 1770 return; // suppress unused var warning.
1764 } 1771 }
1765 GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Fac e); 1772 GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Fac e);
1766 GL_CALL(StencilFillPath(id, fillMode, writeMask)); 1773 GL_CALL(StencilFillPath(id, fillMode, writeMask));
1767 } 1774 }
1768 1775
1769 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { 1776 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) {
1777 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target);
1778 if (rt->needsResolve()) {
1779 // The IMG extension automatically resolves the texture when it is read.
1780 if (GrGLCaps::kImaginationES_MSFBOType != this->glCaps().msFBOType()) {
1781 GrAssert(GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType());
1782 GrAssert(rt->textureFBOID() != rt->renderFBOID());
1783 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID()));
1784 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())) ;
1785 // make sure we go through flushRenderTarget() since we've modified
1786 // the bound DRAW FBO ID.
1787 fHWBoundRenderTarget = NULL;
1788 const GrGLIRect& vp = rt->getViewport();
1789 const GrIRect dirtyRect = rt->getResolveRect();
1790 GrGLIRect r;
1791 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop,
1792 dirtyRect.width(), dirtyRect.height(), target->origi n());
1770 1793
1771 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); 1794 GrAutoTRestore<ScissorState> asr;
1772 1795 if (GrGLCaps::kAppleES_MSFBOType == this->glCaps().msFBOType()) {
1773 if (rt->needsResolve()) { 1796 // Apple's extension uses the scissor as the blit bounds.
1774 GrAssert(GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType());
1775 GrAssert(rt->textureFBOID() != rt->renderFBOID());
1776 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
1777 rt->renderFBOID()));
1778 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER,
1779 rt->textureFBOID()));
1780 // make sure we go through flushRenderTarget() since we've modified
1781 // the bound DRAW FBO ID.
1782 fHWBoundRenderTarget = NULL;
1783 const GrGLIRect& vp = rt->getViewport();
1784 const GrIRect dirtyRect = rt->getResolveRect();
1785 GrGLIRect r;
1786 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop,
1787 dirtyRect.width(), dirtyRect.height(), target->origin()) ;
1788
1789 GrAutoTRestore<ScissorState> asr;
1790 if (GrGLCaps::kAppleES_MSFBOType == this->glCaps().msFBOType()) {
1791 // Apple's extension uses the scissor as the blit bounds.
1792 asr.reset(&fScissorState);
1793 fScissorState.fEnabled = true;
1794 fScissorState.fRect = dirtyRect;
1795 this->flushScissor();
1796 GL_CALL(ResolveMultisampleFramebuffer());
1797 } else {
1798 if (GrGLCaps::kDesktopARB_MSFBOType != this->glCaps().msFBOType()) {
1799 // this respects the scissor during the blit, so disable it.
1800 GrAssert(GrGLCaps::kDesktopEXT_MSFBOType ==
1801 this->glCaps().msFBOType());
1802 asr.reset(&fScissorState); 1797 asr.reset(&fScissorState);
1803 fScissorState.fEnabled = false; 1798 fScissorState.fEnabled = true;
1799 fScissorState.fRect = dirtyRect;
1804 this->flushScissor(); 1800 this->flushScissor();
1801 GL_CALL(ResolveMultisampleFramebuffer());
1802 } else {
1803 if (GrGLCaps::kDesktopARB_MSFBOType != this->glCaps().msFBOType( )) {
1804 // this respects the scissor during the blit, so disable it.
1805 GrAssert(GrGLCaps::kDesktopEXT_MSFBOType == this->glCaps().m sFBOType());
1806 asr.reset(&fScissorState);
1807 fScissorState.fEnabled = false;
1808 this->flushScissor();
1809 }
1810 int right = r.fLeft + r.fWidth;
1811 int top = r.fBottom + r.fHeight;
1812 GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
1813 r.fLeft, r.fBottom, right, top,
1814 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
1805 } 1815 }
1806 int right = r.fLeft + r.fWidth;
1807 int top = r.fBottom + r.fHeight;
1808 GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
1809 r.fLeft, r.fBottom, right, top,
1810 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
1811 } 1816 }
1812 rt->flagAsResolved(); 1817 rt->flagAsResolved();
1813 } 1818 }
1814 } 1819 }
1815 1820
1816 namespace { 1821 namespace {
1817 1822
1818 GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) { 1823 GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) {
1819 static const GrGLenum gTable[] = { 1824 static const GrGLenum gTable[] = {
1820 GR_GL_ALWAYS, // kAlways_StencilFunc 1825 GR_GL_ALWAYS, // kAlways_StencilFunc
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 this->setVertexArrayID(gpu, 0); 2347 this->setVertexArrayID(gpu, 0);
2343 } 2348 }
2344 int attrCount = gpu->glCaps().maxVertexAttributes(); 2349 int attrCount = gpu->glCaps().maxVertexAttributes();
2345 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2350 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2346 fDefaultVertexArrayAttribState.resize(attrCount); 2351 fDefaultVertexArrayAttribState.resize(attrCount);
2347 } 2352 }
2348 attribState = &fDefaultVertexArrayAttribState; 2353 attribState = &fDefaultVertexArrayAttribState;
2349 } 2354 }
2350 return attribState; 2355 return attribState;
2351 } 2356 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLInterface.cpp ('k') | src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698