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

Unified Diff: src/gpu/gl/GrGLSL_impl.h

Issue 13895006: Expand modulate, add, subtract, extract component glsl helpers. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLSL.cpp ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLSL_impl.h
===================================================================
--- src/gpu/gl/GrGLSL_impl.h (revision 0)
+++ src/gpu/gl/GrGLSL_impl.h (revision 0)
@@ -0,0 +1,193 @@
+/*
+ * 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
+
+#include "SkString.h"
+
+namespace {
+template<int N>
+GrSLConstantVec return_const_vecf(GrSLConstantVec constVec, SkString* outAppend, bool omitAppend) {
+ GrAssert(kNone_GrSLConstantVec != constVec);
+ if (!omitAppend) {
+ if (kZeros_GrSLConstantVec == constVec) {
+ outAppend->append(GrGLSLZerosVecf(N));
+ } else {
+ outAppend->append(GrGLSLOnesVecf(N));
+ }
+ }
+ return constVec;
+}
+}
+
+template <int N>
+GrSLConstantVec GrGLSLModulatef(SkString* outAppend,
+ const char* in0,
+ const char* in1,
+ GrSLConstantVec default0,
+ GrSLConstantVec default1,
+ bool omitIfConstVec) {
+ GrAssert(N > 0 && N <= 4);
+ GrAssert(NULL != outAppend);
+
+ bool has0 = NULL != in0 && '\0' != *in0;
+ bool has1 = NULL != in1 && '\0' != *in1;
+
+ GrAssert(has0 || kNone_GrSLConstantVec != default0);
+ GrAssert(has1 || kNone_GrSLConstantVec != default1);
+
+ if (!has0 && !has1) {
+ GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
+ GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
+ if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == default1) {
+ return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitIfConstVec);
+ } else {
+ // both inputs are ones vectors
+ return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIfConstVec);
+ }
+ } else if (!has0) {
+ GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
+ if (kZeros_GrSLConstantVec == default0) {
+ return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitIfConstVec);
+ } else {
+ outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in1);
+ return kNone_GrSLConstantVec;
+ }
+ } else if (!has1) {
+ GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
+ if (kZeros_GrSLConstantVec == default1) {
+ return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitIfConstVec);
+ } else {
+ outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0);
+ return kNone_GrSLConstantVec;
+ }
+ } else {
+ outAppend->appendf("%s((%s) * (%s))", GrGLSLFloatVectorTypeString(N), in0, in1);
+ return kNone_GrSLConstantVec;
+ }
+}
+
+template <int N>
+GrSLConstantVec GrGLSLAddf(SkString* outAppend,
+ const char* in0,
+ const char* in1,
+ GrSLConstantVec default0,
+ GrSLConstantVec default1,
+ bool omitIfConstVec) {
+ GrAssert(N > 0 && N <= 4);
+ GrAssert(NULL != outAppend);
+
+ bool has0 = NULL != in0 && '\0' != *in0;
+ bool has1 = NULL != in1 && '\0' != *in1;
+
+ if (!has0 && !has1) {
+ GrAssert(kNone_GrSLConstantVec != default0);
+ GrAssert(kNone_GrSLConstantVec != default1);
+ int n = (kOnes_GrSLConstantVec == default0) + (kOnes_GrSLConstantVec == default1);
+ if (0 == n) {
+ return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitIfConstVec);
+ } else if (1 == n) {
+ outAppend->append(GrGLSLOnesVecf(N));
+ return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIfConstVec);
+ } else {
+ GrAssert(2 == n);
+ outAppend->appendf("%s(2)", GrGLSLFloatVectorTypeString(N));
+ return kNone_GrSLConstantVec;
+ }
+ } else if (!has0) {
+ GrAssert(kNone_GrSLConstantVec != default0);
+ if (kZeros_GrSLConstantVec == default0) {
+ outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in1);
+ } else {
+ outAppend->appendf("%s(%s) + %s",
+ GrGLSLFloatVectorTypeString(N),
+ in1,
+ GrGLSLOnesVecf(N));
+ }
+ return kNone_GrSLConstantVec;
+ } else if (!has1) {
+ GrAssert(kNone_GrSLConstantVec != default1);
+ if (kZeros_GrSLConstantVec == default1) {
+ outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0);
+ } else {
+ outAppend->appendf("%s(%s) + %s",
+ GrGLSLFloatVectorTypeString(N),
+ in0,
+ GrGLSLOnesVecf(N));
+ }
+ return kNone_GrSLConstantVec;
+ } else {
+ outAppend->appendf("(%s(%s) + %s(%s))",
+ GrGLSLFloatVectorTypeString(N),
+ in0,
+ GrGLSLFloatVectorTypeString(N),
+ in1);
+ return kNone_GrSLConstantVec;
+ }
+}
+
+template <int N>
+GrSLConstantVec GrGLSLSubtractf(SkString* outAppend,
+ const char* in0,
+ const char* in1,
+ GrSLConstantVec default0,
+ GrSLConstantVec default1,
+ bool omitIfConstVec) {
+ GrAssert(N > 0 && N <= 4);
+ GrAssert(NULL != outAppend);
+
+ bool has0 = NULL != in0 && '\0' != *in0;
+ bool has1 = NULL != in1 && '\0' != *in1;
+
+ if (!has0 && !has1) {
+ GrAssert(kNone_GrSLConstantVec != default0);
+ GrAssert(kNone_GrSLConstantVec != default1);
+ int n = (kOnes_GrSLConstantVec == default0) - (kOnes_GrSLConstantVec == default1);
+ if (-1 == n) {
+ outAppend->appendf("%s(-1)", GrGLSLFloatVectorTypeString(N));
+ return kNone_GrSLConstantVec;
+ } else if (0 == n) {
+ return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitIfConstVec);
+ } else {
+ GrAssert(1 == n);
+ return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIfConstVec);
+ }
+ } else if (!has0) {
+ GrAssert(kNone_GrSLConstantVec != default0);
+ if (kZeros_GrSLConstantVec == default0) {
+ outAppend->appendf("-%s(%s)", GrGLSLFloatVectorTypeString(N), in1);
+ } else {
+ outAppend->appendf("%s - %s(%s)",
+ GrGLSLOnesVecf(N),
+ GrGLSLFloatVectorTypeString(N),
+ in1);
+ }
+ return kNone_GrSLConstantVec;
+ } else if (!has1) {
+ GrAssert(kNone_GrSLConstantVec != default1);
+ if (kZeros_GrSLConstantVec == default1) {
+ outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0);
+ } else {
+ outAppend->appendf("%s(%s) - %s",
+ GrGLSLFloatVectorTypeString(N),
+ in0,
+ GrGLSLOnesVecf(N));
+ }
+ return kNone_GrSLConstantVec;
+ } else {
+ outAppend->appendf("(%s(%s) - %s(%s))",
+ GrGLSLFloatVectorTypeString(N),
+ in0,
+ GrGLSLFloatVectorTypeString(N),
+ in1);
+ return kNone_GrSLConstantVec;
+ }
+}
+
+
+#endif
« no previous file with comments | « src/gpu/gl/GrGLSL.cpp ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698