aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2015-06-24 06:59:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-24 06:59:57 -0700
commitcba99b88fd5fb39def7a094dc32c0745c7a1cfea (patch)
treec2574908e1a63570bbd0eef0689efd7b783ff6a9 /src/gpu/gl
parent1b8e1b5c499e31a671232c8ccb10e778e0d8b154 (diff)
Move GLSL-specific routines/classes to separate glsl directory
The purpose is to begin separating our GLSL-specific code from our GL-specific code, so it can be used with the GL45 platform Review URL: https://codereview.chromium.org/1202293002
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLCaps.cpp81
-rw-r--r--src/gpu/gl/GrGLCaps.h90
-rw-r--r--src/gpu/gl/GrGLContext.cpp3
-rw-r--r--src/gpu/gl/GrGLContext.h1
-rwxr-xr-x[-rw-r--r--]src/gpu/gl/GrGLGLSL.cpp (renamed from src/gpu/gl/GrGLSL.cpp)34
-rwxr-xr-xsrc/gpu/gl/GrGLGLSL.h36
-rw-r--r--src/gpu/gl/GrGLGpu.cpp8
-rw-r--r--src/gpu/gl/GrGLProgram.cpp1
-rw-r--r--src/gpu/gl/GrGLProgram.h1
-rw-r--r--src/gpu/gl/GrGLProgramDataManager.h1
-rw-r--r--src/gpu/gl/GrGLSL.h347
-rw-r--r--src/gpu/gl/GrGLSL_impl.h175
-rw-r--r--src/gpu/gl/GrGLShaderVar.h1
-rw-r--r--src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp12
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp1
-rw-r--r--src/gpu/gl/builders/GrGLShaderBuilder.cpp1
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp3
17 files changed, 85 insertions, 711 deletions
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 0c53006bd2..22fd053c1d 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -9,6 +9,7 @@
#include "GrGLCaps.h"
#include "GrGLContext.h"
+#include "glsl/GrGLSLCaps.h"
#include "SkTSearch.h"
#include "SkTSort.h"
@@ -51,8 +52,7 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
fReadPixelsSupportedCache.reset();
- fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions,
- ctxInfo, glInterface, *this)));
+ fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions)));
this->init(contextOptions, ctxInfo, glInterface);
}
@@ -450,7 +450,7 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
this->initConfigTexturableTable(ctxInfo, gli);
this->initConfigRenderableTable(ctxInfo);
- glslCaps->initShaderPrecisionTable(ctxInfo, gli);
+ this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
this->applyOptionsOverrides(contextOptions);
glslCaps->applyOptionsOverrides(contextOptions);
@@ -1078,46 +1078,6 @@ SkString GrGLCaps::dump() const {
return r;
}
-////////////////////////////////////////////////////////////////////////////////////////////
-
-GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options,
- const GrGLContextInfo& ctxInfo,
- const GrGLInterface* gli,
- const GrGLCaps& glCaps) {
- fDropsTileOnZeroDivide = false;
- fFBFetchSupport = false;
- fFBFetchNeedsCustomOutput = false;
- fBindlessTextureSupport = false;
- fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
- fFBFetchColorName = NULL;
- fFBFetchExtensionString = NULL;
-}
-
-SkString GrGLSLCaps::dump() const {
- SkString r = INHERITED::dump();
-
- static const char* kAdvBlendEqInteractionStr[] = {
- "Not Supported",
- "Automatic",
- "General Enable",
- "Specific Enables",
- };
- GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
- GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
- GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
- GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
- GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
-
- r.appendf("--- GLSL-Specific ---\n");
-
- r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
- r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
- r.appendf("Bindless texture support: %s\n", (fBindlessTextureSupport ? "YES" : "NO"));
- r.appendf("Advanced blend equation interaction: %s\n",
- kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
- return r;
-}
-
static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
switch (p) {
case kLow_GrSLPrecision:
@@ -1144,16 +1104,17 @@ static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
return -1;
}
-void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
- const GrGLInterface* intf) {
+void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
+ const GrGLInterface* intf,
+ GrGLSLCaps* glslCaps) {
if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
for (int s = 0; s < kGrShaderTypeCount; ++s) {
if (kGeometry_GrShaderType != s) {
GrShaderType shaderType = static_cast<GrShaderType>(s);
GrGLenum glShader = shader_type_to_gl_shader(shaderType);
- PrecisionInfo* first = NULL;
- fShaderPrecisionVaries = false;
+ GrShaderCaps::PrecisionInfo* first = NULL;
+ glslCaps->fShaderPrecisionVaries = false;
for (int p = 0; p < kGrSLPrecisionCount; ++p) {
GrSLPrecision precision = static_cast<GrSLPrecision>(p);
GrGLenum glPrecision = precision_to_gl_float_type(precision);
@@ -1161,14 +1122,15 @@ void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
GrGLint bits;
GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
if (bits) {
- fFloatPrecisions[s][p].fLogRangeLow = range[0];
- fFloatPrecisions[s][p].fLogRangeHigh = range[1];
- fFloatPrecisions[s][p].fBits = bits;
+ glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
+ glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
+ glslCaps->fFloatPrecisions[s][p].fBits = bits;
if (!first) {
- first = &fFloatPrecisions[s][p];
+ first = &glslCaps->fFloatPrecisions[s][p];
}
- else if (!fShaderPrecisionVaries) {
- fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
+ else if (!glslCaps->fShaderPrecisionVaries) {
+ glslCaps->fShaderPrecisionVaries =
+ (*first != glslCaps->fFloatPrecisions[s][p]);
}
}
}
@@ -1177,13 +1139,13 @@ void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
}
else {
// We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
- fShaderPrecisionVaries = false;
+ glslCaps->fShaderPrecisionVaries = false;
for (int s = 0; s < kGrShaderTypeCount; ++s) {
if (kGeometry_GrShaderType != s) {
for (int p = 0; p < kGrSLPrecisionCount; ++p) {
- fFloatPrecisions[s][p].fLogRangeLow = 127;
- fFloatPrecisions[s][p].fLogRangeHigh = 127;
- fFloatPrecisions[s][p].fBits = 23;
+ glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
+ glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
+ glslCaps->fFloatPrecisions[s][p].fBits = 23;
}
}
}
@@ -1192,9 +1154,10 @@ void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
// the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
// highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
// are recommended against.
- if (fGeometryShaderSupport) {
+ if (glslCaps->fGeometryShaderSupport) {
for (int p = 0; p < kGrSLPrecisionCount; ++p) {
- fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
+ glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
+ glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
}
}
}
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 3d3319968f..fd03da5e46 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -10,7 +10,7 @@
#define GrGLCaps_DEFINED
#include "GrCaps.h"
-#include "GrGLSL.h"
+#include "glsl/GrGLSL.h"
#include "GrGLStencilAttachment.h"
#include "SkChecksum.h"
#include "SkTHash.h"
@@ -328,6 +328,10 @@ private:
bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
+ void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
+ const GrGLInterface* intf,
+ GrGLSLCaps* glslCaps);
+
// tracks configs that have been verified to pass the FBO completeness when
// used as a color attachment
VerifiedColorConfigs fVerifiedColorConfigs;
@@ -387,88 +391,4 @@ private:
typedef GrCaps INHERITED;
};
-class GrGLSLCaps : public GrShaderCaps {
-public:
- SK_DECLARE_INST_COUNT(GrGLSLCaps)
-
- /**
- * Indicates how GLSL must interact with advanced blend equations. The KHR extension requires
- * special layout qualifiers in the fragment shader.
- */
- enum AdvBlendEqInteraction {
- kNotSupported_AdvBlendEqInteraction, //<! No _blend_equation_advanced extension
- kAutomatic_AdvBlendEqInteraction, //<! No interaction required
- kGeneralEnable_AdvBlendEqInteraction, //<! layout(blend_support_all_equations) out
- kSpecificEnables_AdvBlendEqInteraction, //<! Specific layout qualifiers per equation
-
- kLast_AdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction
- };
-
- /**
- * Initializes the GrGLSLCaps to the set of features supported in the current
- * OpenGL context accessible via ctxInfo.
- */
- GrGLSLCaps(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
- const GrGLCaps&);
-
- /**
- * Some helper functions for encapsulating various extensions to read FB Buffer on openglES
- *
- * TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect
- */
- bool fbFetchSupport() const { return fFBFetchSupport; }
-
- bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; }
-
- bool bindlessTextureSupport() const { return fBindlessTextureSupport; }
-
- const char* fbFetchColorName() const { return fFBFetchColorName; }
-
- const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
-
- bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
-
- AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; }
-
- bool mustEnableAdvBlendEqs() const {
- return fAdvBlendEqInteraction >= kGeneralEnable_AdvBlendEqInteraction;
- }
-
- bool mustEnableSpecificAdvBlendEqs() const {
- return fAdvBlendEqInteraction == kSpecificEnables_AdvBlendEqInteraction;
- }
-
- bool mustDeclareFragmentShaderOutput() const {
- return fGLSLGeneration > k110_GrGLSLGeneration;
- }
-
- GrGLSLGeneration generation() const { return fGLSLGeneration; }
-
- /**
- * Returns a string containing the caps info.
- */
- SkString dump() const override;
-
-private:
- // Must be called after fGeometryShaderSupport is initialized.
- void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*);
-
- GrGLSLGeneration fGLSLGeneration;
-
- bool fDropsTileOnZeroDivide : 1;
- bool fFBFetchSupport : 1;
- bool fFBFetchNeedsCustomOutput : 1;
- bool fBindlessTextureSupport : 1;
-
- const char* fFBFetchColorName;
- const char* fFBFetchExtensionString;
-
- AdvBlendEqInteraction fAdvBlendEqInteraction;
-
- friend class GrGLCaps; // For initialization.
-
- typedef GrShaderCaps INHERITED;
-};
-
-
#endif
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp
index adbc5d9e86..ee840b3aab 100644
--- a/src/gpu/gl/GrGLContext.cpp
+++ b/src/gpu/gl/GrGLContext.cpp
@@ -6,6 +6,7 @@
*/
#include "GrGLContext.h"
+#include "GrGLGLSL.h"
////////////////////////////////////////////////////////////////////////////////
@@ -34,7 +35,7 @@ GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContext
return NULL;
}
- if (!GrGetGLSLGeneration(interface, &args.fGLSLGeneration)) {
+ if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) {
return NULL;
}
diff --git a/src/gpu/gl/GrGLContext.h b/src/gpu/gl/GrGLContext.h
index 8a4289471c..f86007a217 100644
--- a/src/gpu/gl/GrGLContext.h
+++ b/src/gpu/gl/GrGLContext.h
@@ -12,7 +12,6 @@
#include "gl/GrGLExtensions.h"
#include "gl/GrGLInterface.h"
#include "GrGLCaps.h"
-#include "GrGLSL.h"
#include "GrGLUtil.h"
struct GrContextOptions;
diff --git a/src/gpu/gl/GrGLSL.cpp b/src/gpu/gl/GrGLGLSL.cpp
index 20e6e20938..ea65842c91 100644..100755
--- a/src/gpu/gl/GrGLSL.cpp
+++ b/src/gpu/gl/GrGLGLSL.cpp
@@ -5,11 +5,11 @@
* found in the LICENSE file.
*/
-#include "GrGLSL.h"
+#include "GrGLGLSL.h"
#include "GrGLShaderVar.h"
#include "SkString.h"
-bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) {
+bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) {
SkASSERT(generation);
GrGLSLVersion ver = GrGLGetGLSLVersion(gl);
if (GR_GLSL_INVALID_VER == ver) {
@@ -47,7 +47,7 @@ bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation)
}
}
-const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) {
+const char* GrGLGetGLSLVersionDecl(const GrGLContextInfo& info) {
switch (info.glslGeneration()) {
case k110_GrGLSLGeneration:
if (kGLES_GrGLStandard == info.standard()) {
@@ -89,21 +89,7 @@ const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) {
return "<no version>";
}
-bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) {
- switch (gen) {
- case k110_GrGLSLGeneration:
- return false;
- case k130_GrGLSLGeneration:
- case k140_GrGLSLGeneration:
- case k150_GrGLSLGeneration:
- case k330_GrGLSLGeneration:
- case k310es_GrGLSLGeneration:
- return true;
- }
- return false;
-}
-
-void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard s, SkString* out) {
+void GrGLAppendGLSLDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard s, SkString* out) {
// Desktop GLSL has added precision qualifiers but they don't do anything.
if (kGLES_GrGLStandard == s) {
switch (p) {
@@ -121,15 +107,3 @@ void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard
}
}
}
-
-void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) {
- if (mulFactor.isOnes()) {
- *outAppend = SkString();
- }
-
- if (mulFactor.isZeros()) {
- outAppend->appendf("%s = vec4(0);", vec4VarName);
- } else {
- outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str());
- }
-}
diff --git a/src/gpu/gl/GrGLGLSL.h b/src/gpu/gl/GrGLGLSL.h
new file mode 100755
index 0000000000..724765f1a8
--- /dev/null
+++ b/src/gpu/gl/GrGLGLSL.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLInitGLSL_DEFINED
+#define GrGLInitGLSL_DEFINED
+
+#include "gl/GrGLInterface.h"
+#include "glsl/GrGLSL.h"
+#include "GrColor.h"
+#include "GrTypesPriv.h"
+#include "SkString.h"
+
+class GrGLContextInfo;
+
+/**
+ * Gets the most recent GLSL Generation compatible with the OpenGL context.
+ */
+bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation);
+
+/**
+ * Returns a string to include at the beginning of a shader to declare the GLSL
+ * version.
+ */
+const char* GrGLGetGLSLVersionDecl(const GrGLContextInfo&);
+
+/**
+ * Adds a line of GLSL code to declare the default precision for float types.
+ */
+void GrGLAppendGLSLDefaultFloatPrecisionDeclaration(GrSLPrecision, GrGLStandard, SkString* out);
+
+
+#endif
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index b3bcdbe79c..20669b8e78 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -7,6 +7,7 @@
#include "GrGLGpu.h"
+#include "GrGLGLSL.h"
#include "GrGLStencilAttachment.h"
#include "GrGLTextureRenderTarget.h"
#include "GrGpuResourcePriv.h"
@@ -18,6 +19,7 @@
#include "GrTypes.h"
#include "GrVertices.h"
#include "builders/GrGLShaderStringBuilder.h"
+#include "glsl/GrGLSLCaps.h"
#include "SkStrokeRec.h"
#include "SkTemplates.h"
@@ -2737,7 +2739,7 @@ bool GrGLGpu::copySurface(GrSurface* dst,
void GrGLGpu::createCopyProgram() {
- const char* version = GrGetGLSLVersionDecl(this->ctxInfo());
+ const char* version = GrGLGetGLSLVersionDecl(this->ctxInfo());
GrGLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute_TypeModifier);
GrGLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType,
@@ -2767,8 +2769,8 @@ void GrGLGpu::createCopyProgram() {
);
SkString fshaderTxt(version);
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, this->glStandard(),
- &fshaderTxt);
+ GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, this->glStandard(),
+ &fshaderTxt);
vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier);
vTexCoord.appendDecl(this->ctxInfo(), &fshaderTxt);
fshaderTxt.append(";");
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 679e3ba4ca..7a6c5974d8 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -15,7 +15,6 @@
#include "GrGLPathProcessor.h"
#include "GrGLPathRendering.h"
#include "GrGLShaderVar.h"
-#include "GrGLSL.h"
#include "GrGLXferProcessor.h"
#include "GrPathProcessor.h"
#include "GrPipeline.h"
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 22afefb011..086fb7ac2a 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -12,7 +12,6 @@
#include "builders/GrGLProgramBuilder.h"
#include "GrGLContext.h"
#include "GrGLProgramDesc.h"
-#include "GrGLSL.h"
#include "GrGLTexture.h"
#include "GrGLProgramDataManager.h"
diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h
index 21ee9b5931..644ba951c4 100644
--- a/src/gpu/gl/GrGLProgramDataManager.h
+++ b/src/gpu/gl/GrGLProgramDataManager.h
@@ -9,7 +9,6 @@
#define GrGLProgramDataManager_DEFINED
#include "gl/GrGLShaderVar.h"
-#include "gl/GrGLSL.h"
#include "GrAllocator.h"
#include "SkTArray.h"
diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h
deleted file mode 100644
index b338c991a6..0000000000
--- a/src/gpu/gl/GrGLSL.h
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLSL_DEFINED
-#define GrGLSL_DEFINED
-
-#include "gl/GrGLInterface.h"
-#include "GrColor.h"
-#include "GrTypesPriv.h"
-#include "SkString.h"
-
-class GrGLContextInfo;
-class GrGLShaderVar;
-
-// Limited set of GLSL versions we build shaders for. Caller should round
-// down the GLSL version to one of these enums.
-enum GrGLSLGeneration {
- /**
- * Desktop GLSL 1.10 and ES2 shading language (based on desktop GLSL 1.20)
- */
- k110_GrGLSLGeneration,
- /**
- * Desktop GLSL 1.30
- */
- k130_GrGLSLGeneration,
- /**
- * Desktop GLSL 1.40
- */
- k140_GrGLSLGeneration,
- /**
- * Desktop GLSL 1.50
- */
- k150_GrGLSLGeneration,
- /**
- * Desktop GLSL 3.30, and ES GLSL 3.00
- */
- k330_GrGLSLGeneration,
- /**
- * ES GLSL 3.10 only TODO Make GLSLCap objects to make this more granular
- */
- k310es_GrGLSLGeneration,
-};
-
-/**
- * Gets the most recent GLSL Generation compatible with the OpenGL context.
- */
-bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation);
-
-bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration);
-
-/**
- * Returns a string to include at the beginning of a shader to declare the GLSL
- * version.
- */
-const char* GrGetGLSLVersionDecl(const GrGLContextInfo&);
-
-/**
- * Adds a line of GLSL code to declare the default precision for float types.
- */
-void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, GrGLStandard, SkString* out);
-
-/**
- * Gets the name of the function that should be used to sample a 2D texture. Coord type is used
- * to indicate whether the texture is sampled using projective textured (kVec3f) or not (kVec2f).
- */
-inline const char* GrGLSLTexture2DFunctionName(GrSLType coordType, GrGLSLGeneration glslGen) {
- if (kVec2f_GrSLType == coordType) {
- return glslGen >= k130_GrGLSLGeneration ? "texture" : "texture2D";
- } else {
- SkASSERT(kVec3f_GrSLType == coordType);
- return glslGen >= k130_GrGLSLGeneration ? "textureProj" : "texture2DProj";
- }
-}
-
-/**
- * Converts a GrSLType to a string containing the name of the equivalent GLSL type.
- */
-static inline const char* GrGLSLTypeString(GrSLType t) {
- switch (t) {
- case kVoid_GrSLType:
- return "void";
- case kFloat_GrSLType:
- return "float";
- case kVec2f_GrSLType:
- return "vec2";
- case kVec3f_GrSLType:
- return "vec3";
- case kVec4f_GrSLType:
- return "vec4";
- case kMat33f_GrSLType:
- return "mat3";
- case kMat44f_GrSLType:
- return "mat4";
- case kSampler2D_GrSLType:
- return "sampler2D";
- default:
- SkFAIL("Unknown shader var type.");
- return ""; // suppress warning
- }
-}
-
-/** A generic base-class representing a GLSL expression.
- * The instance can be a variable name, expression or vecN(0) or vecN(1). Does simple constant
- * folding with help of 1 and 0.
- *
- * Clients should not use this class, rather the specific instantiations defined
- * later, for example GrGLSLExpr4.
- */
-template <typename Self>
-class GrGLSLExpr {
-public:
- bool isOnes() const { return kOnes_ExprType == fType; }
- bool isZeros() const { return kZeros_ExprType == fType; }
-
- const char* c_str() const {
- if (kZeros_ExprType == fType) {
- return Self::ZerosStr();
- } else if (kOnes_ExprType == fType) {
- return Self::OnesStr();
- }
- SkASSERT(!fExpr.isEmpty()); // Empty expressions should not be used.
- return fExpr.c_str();
- }
-
- bool isValid() const {
- return kFullExpr_ExprType != fType || !fExpr.isEmpty();
- }
-
-protected:
- /** Constructs an invalid expression.
- * Useful only as a return value from functions that never actually return
- * this and instances that will be assigned to later. */
- GrGLSLExpr()
- : fType(kFullExpr_ExprType) {
- // The only constructor that is allowed to build an empty expression.
- SkASSERT(!this->isValid());
- }
-
- /** Constructs an expression with all components as value v */
- explicit GrGLSLExpr(int v) {
- if (v == 0) {
- fType = kZeros_ExprType;
- } else if (v == 1) {
- fType = kOnes_ExprType;
- } else {
- fType = kFullExpr_ExprType;
- fExpr.appendf(Self::CastIntStr(), v);
- }
- }
-
- /** Constructs an expression from a string.
- * Argument expr is a simple expression or a parenthesized expression. */
- // TODO: make explicit once effects input Exprs.
- GrGLSLExpr(const char expr[]) {
- if (NULL == expr) { // TODO: remove this once effects input Exprs.
- fType = kOnes_ExprType;
- } else {
- fType = kFullExpr_ExprType;
- fExpr = expr;
- }
- SkASSERT(this->isValid());
- }
-
- /** Constructs an expression from a string.
- * Argument expr is a simple expression or a parenthesized expression. */
- // TODO: make explicit once effects input Exprs.
- GrGLSLExpr(const SkString& expr) {
- if (expr.isEmpty()) { // TODO: remove this once effects input Exprs.
- fType = kOnes_ExprType;
- } else {
- fType = kFullExpr_ExprType;
- fExpr = expr;
- }
- SkASSERT(this->isValid());
- }
-
- /** Constructs an expression from a string with one substitution. */
- GrGLSLExpr(const char format[], const char in0[])
- : fType(kFullExpr_ExprType) {
- fExpr.appendf(format, in0);
- }
-
- /** Constructs an expression from a string with two substitutions. */
- GrGLSLExpr(const char format[], const char in0[], const char in1[])
- : fType(kFullExpr_ExprType) {
- fExpr.appendf(format, in0, in1);
- }
-
- /** Returns expression casted to another type.
- * Generic implementation that is called for non-trivial cases of casts. */
- template <typename T>
- static Self VectorCastImpl(const T& other);
-
- /** Returns a GLSL multiplication: component-wise or component-by-scalar.
- * The multiplication will be component-wise or multiply each component by a scalar.
- *
- * The returned expression will compute the value of:
- * vecN(in0.x * in1.x, ...) if dim(T0) == dim(T1) (component-wise)
- * vecN(in0.x * in1, ...) if dim(T1) == 1 (vector by scalar)
- * vecN(in0 * in1.x, ...) if dim(T0) == 1 (scalar by vector)
- */
- template <typename T0, typename T1>
- static Self Mul(T0 in0, T1 in1);
-
- /** Returns a GLSL addition: component-wise or add a scalar to each component.
- * Return value computes:
- * vecN(in0.x + in1.x, ...) or vecN(in0.x + in1, ...) or vecN(in0 + in1.x, ...).
- */
- template <typename T0, typename T1>
- static Self Add(T0 in0, T1 in1);
-
- /** Returns a GLSL subtraction: component-wise or subtract compoments by a scalar.
- * Return value computes
- * vecN(in0.x - in1.x, ...) or vecN(in0.x - in1, ...) or vecN(in0 - in1.x, ...).
- */
- template <typename T0, typename T1>
- static Self Sub(T0 in0, T1 in1);
-
- /** Returns expression that accesses component(s) of the expression.
- * format should be the form "%s.x" where 'x' is the component(s) to access.
- * Caller is responsible for making sure the amount of components in the
- * format string is equal to dim(T).
- */
- template <typename T>
- T extractComponents(const char format[]) const;
-
-private:
- enum ExprType {
- kZeros_ExprType,
- kOnes_ExprType,
- kFullExpr_ExprType,
- };
- ExprType fType;
- SkString fExpr;
-};
-
-class GrGLSLExpr1;
-class GrGLSLExpr4;
-
-/** Class representing a float GLSL expression. */
-class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> {
-public:
- GrGLSLExpr1()
- : INHERITED() {
- }
- explicit GrGLSLExpr1(int v)
- : INHERITED(v) {
- }
- GrGLSLExpr1(const char* expr)
- : INHERITED(expr) {
- }
- GrGLSLExpr1(const SkString& expr)
- : INHERITED(expr) {
- }
-
- static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr);
-
-private:
- GrGLSLExpr1(const char format[], const char in0[])
- : INHERITED(format, in0) {
- }
- GrGLSLExpr1(const char format[], const char in0[], const char in1[])
- : INHERITED(format, in0, in1) {
- }
-
- static const char* ZerosStr();
- static const char* OnesStr();
- static const char* CastStr();
- static const char* CastIntStr();
-
- friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
-
- friend class GrGLSLExpr<GrGLSLExpr1>;
- friend class GrGLSLExpr<GrGLSLExpr4>;
-
- typedef GrGLSLExpr<GrGLSLExpr1> INHERITED;
-};
-
-/** Class representing a float vector (vec4) GLSL expression. */
-class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> {
-public:
- GrGLSLExpr4()
- : INHERITED() {
- }
- explicit GrGLSLExpr4(int v)
- : INHERITED(v) {
- }
- GrGLSLExpr4(const char* expr)
- : INHERITED(expr) {
- }
- GrGLSLExpr4(const SkString& expr)
- : INHERITED(expr) {
- }
-
- typedef GrGLSLExpr1 AExpr;
- AExpr a() const;
-
- /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, floatv, floatv) */
- static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr);
- static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr);
-
-private:
- GrGLSLExpr4(const char format[], const char in0[])
- : INHERITED(format, in0) {
- }
- GrGLSLExpr4(const char format[], const char in0[], const char in1[])
- : INHERITED(format, in0, in1) {
- }
-
- static const char* ZerosStr();
- static const char* OnesStr();
- static const char* CastStr();
- static const char* CastIntStr();
-
- // The vector-by-scalar and scalar-by-vector binary operations.
- friend GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
-
- // The vector-by-vector, i.e. component-wise, binary operations.
- friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
-
- friend class GrGLSLExpr<GrGLSLExpr4>;
-
- typedef GrGLSLExpr<GrGLSLExpr4> INHERITED;
-};
-
-/**
- * Does an inplace mul, *=, of vec4VarName by mulFactor.
- * A semicolon is added after the assignment.
- */
-void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor);
-
-#include "GrGLSL_impl.h"
-
-#endif
diff --git a/src/gpu/gl/GrGLSL_impl.h b/src/gpu/gl/GrGLSL_impl.h
deleted file mode 100644
index bdd69cc76b..0000000000
--- a/src/gpu/gl/GrGLSL_impl.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLSL_impl_DEFINED
-#define GrGLSL_impl_DEFINED
-
-template<typename Self>
-template<typename T>
-inline Self GrGLSLExpr<Self>::VectorCastImpl(const T& expr) {
- if (expr.isZeros()) {
- return Self(0);
- }
- if (expr.isOnes()) {
- return Self(1);
- }
- return Self(Self::CastStr(), expr.c_str());
-}
-
-template<typename Self>
-template<typename T0, typename T1>
-inline Self GrGLSLExpr<Self>::Mul(T0 in0, T1 in1) {
- if (in0.isZeros() || in1.isZeros()) {
- return Self(0);
- }
- if (in0.isOnes()) {
- return Self::VectorCast(in1);
- }
- if (in1.isOnes()) {
- return Self::VectorCast(in0);
- }
- return Self("(%s * %s)", in0.c_str(), in1.c_str());
-}
-
-template<typename Self>
-template<typename T0, typename T1>
-inline Self GrGLSLExpr<Self>::Add(T0 in0, T1 in1) {
- if (in1.isZeros()) {
- return Self::VectorCast(in0);
- }
- if (in0.isZeros()) {
- return Self::VectorCast(in1);
- }
- if (in0.isOnes() && in1.isOnes()) {
- return Self(2);
- }
- return Self("(%s + %s)", in0.c_str(), in1.c_str());
-}
-
-template<typename Self>
-template<typename T0, typename T1>
-inline Self GrGLSLExpr<Self>::Sub(T0 in0, T1 in1) {
- if (in1.isZeros()) {
- return Self::VectorCast(in0);
- }
- if (in1.isOnes()) {
- if (in0.isOnes()) {
- return Self(0);
- }
- }
-
- return Self("(%s - %s)", in0.c_str(), in1.c_str());
-}
-
-template <typename Self>
-template <typename T>
-T GrGLSLExpr<Self>::extractComponents(const char format[]) const {
- if (this->isZeros()) {
- return T(0);
- }
- if (this->isOnes()) {
- return T(1);
- }
- return T(format, this->c_str());
-}
-
-inline GrGLSLExpr1 GrGLSLExpr1::VectorCast(const GrGLSLExpr1& expr) {
- return expr;
-}
-
-inline const char* GrGLSLExpr1::ZerosStr() {
- return "0";
-}
-
-inline const char* GrGLSLExpr1::OnesStr() {
- return "1.0";
-}
-
-// GrGLSLExpr1::CastStr() is unimplemented because using them is likely an
-// error. This is now caught compile-time.
-
-inline const char* GrGLSLExpr1::CastIntStr() {
- return "%d";
-}
-
-inline GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr1::Mul(in0, in1);
-}
-
-inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr1::Add(in0, in1);
-}
-
-inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr1::Sub(in0, in1);
-}
-
-inline const char* GrGLSLExpr4::ZerosStr() {
- return "vec4(0)";
-}
-
-inline const char* GrGLSLExpr4::OnesStr() {
- return "vec4(1)";
-}
-
-inline const char* GrGLSLExpr4::CastStr() {
- return "vec4(%s)";
-}
-
-inline const char* GrGLSLExpr4::CastIntStr() {
- return "vec4(%d)";
-}
-
-inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) {
- return INHERITED::VectorCastImpl(expr);
-}
-
-inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) {
- return expr;
-}
-
-inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const {
- return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a");
-}
-
-inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Mul(in0, in1);
-}
-
-inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Add(in0, in1);
-}
-
-inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Sub(in0, in1);
-}
-
-inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr4::Mul(in0, in1);
-}
-
-inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr4::Add(in0, in1);
-}
-
-inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr4::Sub(in0, in1);
-}
-
-inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Mul(in0, in1);
-}
-
-inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Add(in0, in1);
-}
-
-inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Sub(in0, in1);
-}
-
-#endif
diff --git a/src/gpu/gl/GrGLShaderVar.h b/src/gpu/gl/GrGLShaderVar.h
index e32683ab4f..77d46a507d 100644
--- a/src/gpu/gl/GrGLShaderVar.h
+++ b/src/gpu/gl/GrGLShaderVar.h
@@ -9,7 +9,6 @@
#define GrGLShaderVar_DEFINED
#include "GrGLContext.h"
-#include "GrGLSL.h"
#include "GrShaderVar.h"
#define USE_UNIFORM_FLOAT_ARRAYS true
diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp
index 557cdbfa58..c2eb09d85a 100644
--- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp
@@ -7,7 +7,9 @@
#include "GrGLFragmentShaderBuilder.h"
#include "GrGLProgramBuilder.h"
-#include "../GrGLGpu.h"
+#include "gl/GrGLGpu.h"
+#include "gl/GrGLGLSL.h"
+#include "glsl/GrGLSLCaps.h"
#define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X)
#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X)
@@ -249,10 +251,10 @@ const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const {
bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId,
SkTDArray<GrGLuint>* shaderIds) {
GrGLGpu* gpu = fProgramBuilder->gpu();
- this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo());
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
- gpu->glStandard(),
- &this->precisionQualifier());
+ this->versionDecl() = GrGLGetGLSLVersionDecl(gpu->ctxInfo());
+ GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
+ gpu->glStandard(),
+ &this->precisionQualifier());
this->compileAndAppendLayoutQualifiers();
fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility,
&this->uniforms());
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 25d9716403..e253ab233b 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -14,6 +14,7 @@
#include "gl/GrGLSLPrettyPrint.h"
#include "gl/GrGLUniformHandle.h"
#include "gl/GrGLXferProcessor.h"
+#include "glsl/GrGLSLCaps.h"
#include "GrAutoLocaleSetter.h"
#include "GrCoordTransform.h"
#include "GrGLProgramBuilder.h"
diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.cpp b/src/gpu/gl/builders/GrGLShaderBuilder.cpp
index 984233dd77..f0408afe21 100644
--- a/src/gpu/gl/builders/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderBuilder.cpp
@@ -10,6 +10,7 @@
#include "GrGLShaderStringBuilder.h"
#include "../GrGLGpu.h"
#include "../GrGLShaderVar.h"
+#include "glsl/GrGLSLCaps.h"
namespace {
void append_texture_lookup(SkString* out,
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
index 6d5d344088..983de21021 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
@@ -7,6 +7,7 @@
#include "GrGLVertexShaderBuilder.h"
#include "GrGLProgramBuilder.h"
+#include "../GrGLGLSL.h"
#include "../GrGLGpu.h"
#define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X)
@@ -85,7 +86,7 @@ void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) {
bool
GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) {
- this->versionDecl() = GrGetGLSLVersionDecl(fProgramBuilder->ctxInfo());
+ this->versionDecl() = GrGLGetGLSLVersionDecl(fProgramBuilder->ctxInfo());
this->compileAndAppendLayoutQualifiers();
fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility, &this->uniforms());
this->appendDecls(fInputs, &this->inputs());