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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 years 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/GrGLUniformHandler.h ('k') | src/gpu/gl/GrGLVaryingHandler.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 2015 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 "gl/GrGLUniformHandler.h"
9
10 #include "gl/GrGLCaps.h"
11 #include "gl/GrGLGpu.h"
12 #include "gl/builders/GrGLProgramBuilder.h"
13
14 #define GL_CALL(X) GR_GL_CALL(this->glGpu()->glInterface(), X)
15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->glGpu()->glInterface(), R, X)
16
17 GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray(
18 uint 32_t visibility,
19 GrSL Type type,
20 GrSL Precision precision,
21 cons t char* name,
22 bool mangleName,
23 int arrayCount,
24 cons t char** outName) {
25 SkASSERT(name && strlen(name));
26 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFr agment_Visibility);
27 SkASSERT(0 == (~kVisibilityMask & visibility));
28 SkASSERT(0 != visibility);
29 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
30
31 UniformInfo& uni = fUniforms.push_back();
32 uni.fVariable.setType(type);
33 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier);
34 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
35 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
36 // exactly what name it wants to use for the uniform view matrix. If we pre fix anythings, then
37 // the names will mismatch. I think the correct solution is to have all GPs which need the
38 // uniform view matrix, they should upload the view matrix in their setData along with regular
39 // uniforms.
40 char prefix = 'u';
41 if ('u' == name[0]) {
42 prefix = '\0';
43 }
44 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mang leName);
45 uni.fVariable.setArrayCount(arrayCount);
46 uni.fVisibility = visibility;
47 uni.fVariable.setPrecision(precision);
48
49 if (outName) {
50 *outName = uni.fVariable.c_str();
51 }
52 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
53 }
54
55 void GrGLUniformHandler::appendUniformDecls(ShaderVisibility visibility, SkStrin g* out) const {
56 for (int i = 0; i < fUniforms.count(); ++i) {
57 if (fUniforms[i].fVisibility & visibility) {
58 fUniforms[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out);
59 out->append(";\n");
60 }
61 }
62 }
63
64 void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps & caps) {
65 if (caps.bindUniformLocationSupport()) {
66 int count = fUniforms.count();
67 for (int i = 0; i < count; ++i) {
68 GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_s tr()));
69 fUniforms[i].fLocation = i;
70 }
71 }
72 }
73
74 void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
75 if (!caps.bindUniformLocationSupport()) {
76 int count = fUniforms.count();
77 for (int i = 0; i < count; ++i) {
78 GrGLint location;
79 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa riable.c_str()));
80 fUniforms[i].fLocation = location;
81 }
82 }
83 }
84
85 const GrGLGpu* GrGLUniformHandler::glGpu() const {
86 GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder;
87 return glPB->gpu();
88 }
89
90
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLUniformHandler.h ('k') | src/gpu/gl/GrGLVaryingHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698