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

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

Issue 1202293002: Move GLSL-specific routines/classes to separate glsl directory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rename GrGLGLSL.{cpp,h} Created 5 years, 6 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
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrGLSL.h"
9 #include "GrGLShaderVar.h"
10 #include "SkString.h"
11
12 bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) {
13 SkASSERT(generation);
14 GrGLSLVersion ver = GrGLGetGLSLVersion(gl);
15 if (GR_GLSL_INVALID_VER == ver) {
16 return false;
17 }
18 switch (gl->fStandard) {
19 case kGL_GrGLStandard:
20 SkASSERT(ver >= GR_GLSL_VER(1,10));
21 if (ver >= GR_GLSL_VER(3,30)) {
22 *generation = k330_GrGLSLGeneration;
23 } else if (ver >= GR_GLSL_VER(1,50)) {
24 *generation = k150_GrGLSLGeneration;
25 } else if (ver >= GR_GLSL_VER(1,40)) {
26 *generation = k140_GrGLSLGeneration;
27 } else if (ver >= GR_GLSL_VER(1,30)) {
28 *generation = k130_GrGLSLGeneration;
29 } else {
30 *generation = k110_GrGLSLGeneration;
31 }
32 return true;
33 case kGLES_GrGLStandard:
34 SkASSERT(ver >= GR_GL_VER(1,00));
35 if (ver >= GR_GLSL_VER(3,1)) {
36 *generation = k310es_GrGLSLGeneration;
37 }
38 else if (ver >= GR_GLSL_VER(3,0)) {
39 *generation = k330_GrGLSLGeneration;
40 } else {
41 *generation = k110_GrGLSLGeneration;
42 }
43 return true;
44 default:
45 SkFAIL("Unknown GL Standard");
46 return false;
47 }
48 }
49
50 const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) {
51 switch (info.glslGeneration()) {
52 case k110_GrGLSLGeneration:
53 if (kGLES_GrGLStandard == info.standard()) {
54 // ES2s shader language is based on version 1.20 but is version
55 // 1.00 of the ES language.
56 return "#version 100\n";
57 } else {
58 SkASSERT(kGL_GrGLStandard == info.standard());
59 return "#version 110\n";
60 }
61 case k130_GrGLSLGeneration:
62 SkASSERT(kGL_GrGLStandard == info.standard());
63 return "#version 130\n";
64 case k140_GrGLSLGeneration:
65 SkASSERT(kGL_GrGLStandard == info.standard());
66 return "#version 140\n";
67 case k150_GrGLSLGeneration:
68 SkASSERT(kGL_GrGLStandard == info.standard());
69 if (info.caps()->isCoreProfile()) {
70 return "#version 150\n";
71 } else {
72 return "#version 150 compatibility\n";
73 }
74 case k330_GrGLSLGeneration:
75 if (kGLES_GrGLStandard == info.standard()) {
76 return "#version 300 es\n";
77 } else {
78 SkASSERT(kGL_GrGLStandard == info.standard());
79 if (info.caps()->isCoreProfile()) {
80 return "#version 330\n";
81 } else {
82 return "#version 330 compatibility\n";
83 }
84 }
85 case k310es_GrGLSLGeneration:
86 SkASSERT(kGLES_GrGLStandard == info.standard());
87 return "#version 310 es\n";
88 }
89 return "<no version>";
90 }
91
92 bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) {
93 switch (gen) {
94 case k110_GrGLSLGeneration:
95 return false;
96 case k130_GrGLSLGeneration:
97 case k140_GrGLSLGeneration:
98 case k150_GrGLSLGeneration:
99 case k330_GrGLSLGeneration:
100 case k310es_GrGLSLGeneration:
101 return true;
102 }
103 return false;
104 }
105
106 void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard s, SkString* out) {
107 // Desktop GLSL has added precision qualifiers but they don't do anything.
108 if (kGLES_GrGLStandard == s) {
109 switch (p) {
110 case kHigh_GrSLPrecision:
111 out->append("precision highp float;\n");
112 break;
113 case kMedium_GrSLPrecision:
114 out->append("precision mediump float;\n");
115 break;
116 case kLow_GrSLPrecision:
117 out->append("precision lowp float;\n");
118 break;
119 default:
120 SkFAIL("Unknown precision value.");
121 }
122 }
123 }
124
125 void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSL Expr4& mulFactor) {
126 if (mulFactor.isOnes()) {
127 *outAppend = SkString();
128 }
129
130 if (mulFactor.isZeros()) {
131 outAppend->appendf("%s = vec4(0);", vec4VarName);
132 } else {
133 outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str());
134 }
135 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698