From 98cad6219b430eddf5528473311279f21dbd2e10 Mon Sep 17 00:00:00 2001 From: cdalton Date: Tue, 3 Nov 2015 09:33:21 -0800 Subject: [PATCH] Fix setColocatedSampleLocations on ES and GL < 4.5 Updates setColocatedSampleLocations to use glFramebufferParameteri when the DSA version glNamedFramebufferParameteri is not present. BUG=skia: Review URL: https://codereview.chromium.org/1415503008 --- include/gpu/gl/GrGLFunctions.h | 1 + include/gpu/gl/GrGLInterface.h | 1 + src/gpu/gl/GrGLAssembleInterface.cpp | 9 +++++++++ src/gpu/gl/GrGLCaps.cpp | 14 +++++++++++--- src/gpu/gl/GrGLGpu.cpp | 14 +++++++++++--- src/gpu/gl/GrGLInterface.cpp | 7 +++++++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/include/gpu/gl/GrGLFunctions.h b/include/gpu/gl/GrGLFunctions.h index 5fbbc2f261..fcc02162dd 100644 --- a/include/gpu/gl/GrGLFunctions.h +++ b/include/gpu/gl/GrGLFunctions.h @@ -75,6 +75,7 @@ typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLEndQueryProc)(GrGLenum target); typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFinishProc)(); typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFlushProc)(); typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFlushMappedBufferRangeProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr length); +typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFramebufferParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param); typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer); typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level); typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFramebufferTexture2DMultisampleProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level, GrGLsizei samples); diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h index 8a7abbfc7e..37c6faacde 100644 --- a/include/gpu/gl/GrGLInterface.h +++ b/include/gpu/gl/GrGLInterface.h @@ -205,6 +205,7 @@ public: GLPtr fFinish; GLPtr fFlush; GLPtr fFlushMappedBufferRange; + GLPtr fFramebufferParameteri; GLPtr fFramebufferRenderbuffer; GLPtr fFramebufferTexture2D; GLPtr fFramebufferTexture2DMultisample; diff --git a/src/gpu/gl/GrGLAssembleInterface.cpp b/src/gpu/gl/GrGLAssembleInterface.cpp index c4d3e13179..ce439ec63f 100644 --- a/src/gpu/gl/GrGLAssembleInterface.cpp +++ b/src/gpu/gl/GrGLAssembleInterface.cpp @@ -269,6 +269,10 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { return nullptr; } + if (glVer >= GR_GL_VER(4,3)) { + GET_PROC(FramebufferParameteri); + } + if (extensions.has("GL_NV_path_rendering")) { GET_PROC_SUFFIX(MatrixLoadf, EXT); GET_PROC_SUFFIX(MatrixLoadIdentity, EXT); @@ -624,6 +628,11 @@ const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) { GET_PROC(CheckFramebufferStatus); GET_PROC(DeleteFramebuffers); GET_PROC(DeleteRenderbuffers); + + if (version >= GR_GL_VER(3,1)) { + GET_PROC(FramebufferParameteri); + } + GET_PROC(FramebufferRenderbuffer); GET_PROC(FramebufferTexture2D); diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 86ff54e830..de7fcd5c57 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -324,9 +324,17 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, fDiscardRenderTargetSupport = false; fInvalidateFBType = kNone_InvalidateFBType; } - glslCaps->fProgrammableSampleLocationsSupport = - ctxInfo.hasExtension("GL_NV_sample_locations") || - ctxInfo.hasExtension("GL_ARB_sample_locations"); + + if (kGL_GrGLStandard == standard) { + glslCaps->fProgrammableSampleLocationsSupport = + ctxInfo.version() >= GR_GL_VER(4, 3) && + (ctxInfo.hasExtension("GL_ARB_sample_locations") || + ctxInfo.hasExtension("GL_NV_sample_locations")); + } else { + glslCaps->fProgrammableSampleLocationsSupport = + ctxInfo.version() >= GR_GL_VER(3, 1) && + ctxInfo.hasExtension("GL_NV_sample_locations"); + } /************************************************************************** * GrCaps fields diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 815fd02b19..0a8f98a8b4 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2035,9 +2035,17 @@ void GrGLGpu::setColocatedSampleLocations(GrRenderTarget* rt, bool useColocatedS return; } - GL_CALL(NamedFramebufferParameteri(target->renderFBOID(), - GR_GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS, - useColocatedSampleLocations)); + if (kGL_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_VER(4,5)) { + GL_CALL(NamedFramebufferParameteri(target->renderFBOID(), + GR_GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS, + useColocatedSampleLocations)); + } else { + GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); + GL_CALL(FramebufferParameteri(GR_GL_FRAMEBUFFER, + GR_GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS, + useColocatedSampleLocations)); + fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; + } target->flagAsUsingColocatedSampleLocations(useColocatedSampleLocations); } diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp index 71de9521c2..fafd17cd0b 100644 --- a/src/gpu/gl/GrGLInterface.cpp +++ b/src/gpu/gl/GrGLInterface.cpp @@ -713,6 +713,13 @@ bool GrGLInterface::validate() const { } } + if ((kGL_GrGLStandard == fStandard && glVer >= GR_GL_VER(4,3)) || + (kGLES_GrGLStandard == fStandard && glVer >= GR_GL_VER(3,1))) { + if (nullptr == fFunctions.fFramebufferParameteri) { + RETURN_FALSE_INTERFACE + } + } + if (kGL_GrGLStandard == fStandard && glVer >= GR_GL_VER(4,5)) { if (nullptr == fFunctions.fNamedFramebufferParameteri) { RETURN_FALSE_INTERFACE