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

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

Issue 1535603006: Move some program building utils from GL to GLSL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebased Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
(...skipping 13 matching lines...) Expand all
24 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) 24 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
25 25
26 //////////////////////////////////////////////////////////////////////////////// /////////////////// 26 //////////////////////////////////////////////////////////////////////////////// ///////////////////
27 27
28 GrGLProgram::GrGLProgram(GrGLGpu* gpu, 28 GrGLProgram::GrGLProgram(GrGLGpu* gpu,
29 const GrProgramDesc& desc, 29 const GrProgramDesc& desc,
30 const BuiltinUniformHandles& builtinUniforms, 30 const BuiltinUniformHandles& builtinUniforms,
31 GrGLuint programID, 31 GrGLuint programID,
32 const UniformInfoArray& uniforms, 32 const UniformInfoArray& uniforms,
33 const VaryingInfoArray& pathProcVaryings, 33 const VaryingInfoArray& pathProcVaryings,
34 GrGLInstalledGeoProc* geometryProcessor, 34 GrGLSLPrimitiveProcessor* geometryProcessor,
35 GrGLInstalledXferProc* xferProcessor, 35 GrGLSLXferProcessor* xferProcessor,
36 GrGLInstalledFragProcs* fragmentProcessors, 36 const GrGLSLFragProcs& fragmentProcessors,
37 SkTArray<UniformHandle>* passSamplerUniforms) 37 SkTArray<UniformHandle>* passSamplerUniforms)
38 : fBuiltinUniformHandles(builtinUniforms) 38 : fBuiltinUniformHandles(builtinUniforms)
39 , fProgramID(programID) 39 , fProgramID(programID)
40 , fGeometryProcessor(geometryProcessor) 40 , fGeometryProcessor(geometryProcessor)
41 , fXferProcessor(xferProcessor) 41 , fXferProcessor(xferProcessor)
42 , fFragmentProcessors(SkRef(fragmentProcessors)) 42 , fFragmentProcessors(fragmentProcessors)
43 , fDesc(desc) 43 , fDesc(desc)
44 , fGpu(gpu) 44 , fGpu(gpu)
45 , fProgramDataManager(gpu, programID, uniforms, pathProcVaryings) { 45 , fProgramDataManager(gpu, programID, uniforms, pathProcVaryings) {
46 fSamplerUniforms.swap(passSamplerUniforms); 46 fSamplerUniforms.swap(passSamplerUniforms);
47 // Assign texture units to sampler uniforms one time up front. 47 // Assign texture units to sampler uniforms one time up front.
48 GL_CALL(UseProgram(fProgramID)); 48 GL_CALL(UseProgram(fProgramID));
49 for (int i = 0; i < fSamplerUniforms.count(); i++) { 49 for (int i = 0; i < fSamplerUniforms.count(); i++) {
50 fProgramDataManager.setSampler(fSamplerUniforms[i], i); 50 fProgramDataManager.setSampler(fSamplerUniforms[i], i);
51 } 51 }
52 } 52 }
53 53
54 GrGLProgram::~GrGLProgram() { 54 GrGLProgram::~GrGLProgram() {
55 if (fProgramID) { 55 if (fProgramID) {
56 GL_CALL(DeleteProgram(fProgramID)); 56 GL_CALL(DeleteProgram(fProgramID));
57 } 57 }
58 } 58 }
59 59
60 void GrGLProgram::abandon() { 60 void GrGLProgram::abandon() {
61 fProgramID = 0; 61 fProgramID = 0;
62 } 62 }
63 63
64 /////////////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////////////
65 65
66 template <class Proc> 66 static void append_texture_bindings(const GrProcessor& processor,
67 static void append_texture_bindings(const Proc* ip,
68 const GrProcessor& processor,
69 SkTArray<const GrTextureAccess*>* textureBin dings) { 67 SkTArray<const GrTextureAccess*>* textureBin dings) {
70 if (int numTextures = processor.numTextures()) { 68 if (int numTextures = processor.numTextures()) {
71 SkASSERT(textureBindings->count() == ip->fSamplersIdx);
egdaniel 2016/01/13 17:01:58 This assert is the one casualty of this move, but
72 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res); 69 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res);
73 int i = 0; 70 int i = 0;
74 do { 71 do {
75 bindings[i] = &processor.textureAccess(i); 72 bindings[i] = &processor.textureAccess(i);
76 } while (++i < numTextures); 73 } while (++i < numTextures);
77 } 74 }
78 } 75 }
79 76
80 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, 77 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc,
81 const GrPipeline& pipeline, 78 const GrPipeline& pipeline,
82 SkTArray<const GrTextureAccess*>* textureBindings) { 79 SkTArray<const GrTextureAccess*>* textureBindings) {
83 this->setRenderTargetState(primProc, pipeline); 80 this->setRenderTargetState(primProc, pipeline);
84 81
85 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses 82 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses
86 // of GLProgram determine how to set coord transforms 83 // of GLProgram determine how to set coord transforms
87 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc); 84 fGeometryProcessor->setData(fProgramDataManager, primProc);
88 append_texture_bindings(fGeometryProcessor.get(), primProc, textureBindings) ; 85 append_texture_bindings(primProc, textureBindings);
89 86
90 this->setFragmentData(primProc, pipeline, textureBindings); 87 this->setFragmentData(primProc, pipeline, textureBindings);
91 88
92 const GrXferProcessor& xp = pipeline.getXferProcessor(); 89 const GrXferProcessor& xp = pipeline.getXferProcessor();
93 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); 90 fXferProcessor->setData(fProgramDataManager, xp);
94 append_texture_bindings(fXferProcessor.get(), xp, textureBindings); 91 append_texture_bindings(xp, textureBindings);
95 } 92 }
96 93
97 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, 94 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc,
98 const GrPipeline& pipeline, 95 const GrPipeline& pipeline,
99 SkTArray<const GrTextureAccess*>* textureBindi ngs) { 96 SkTArray<const GrTextureAccess*>* textureBindi ngs) {
100 int numProcessors = fFragmentProcessors->fProcs.count(); 97 int numProcessors = fFragmentProcessors.count();
101 for (int i = 0; i < numProcessors; ++i) { 98 for (int i = 0; i < numProcessors; ++i) {
102 const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i); 99 const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i);
103 fFragmentProcessors->fProcs[i]->fGLProc->setData(fProgramDataManager, pr ocessor); 100 fFragmentProcessors[i]->setData(fProgramDataManager, processor);
104 this->setTransformData(primProc, 101 this->setTransformData(primProc, processor, i);
105 processor, 102 append_texture_bindings(processor, textureBindings);
106 i,
107 fFragmentProcessors->fProcs[i]);
108 append_texture_bindings(fFragmentProcessors->fProcs[i], processor, textu reBindings);
109 } 103 }
110 } 104 }
111 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, 105 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc,
112 const GrFragmentProcessor& processor, 106 const GrFragmentProcessor& processor,
113 int index, 107 int index) {
114 GrGLInstalledFragProc* ip) { 108 fGeometryProcessor->setTransformData(primProc, fProgramDataManager, index,
115 GrGLSLPrimitiveProcessor* gp = fGeometryProcessor.get()->fGLProc.get(); 109 processor.coordTransforms());
116 gp->setTransformData(primProc, fProgramDataManager, index,
117 processor.coordTransforms());
118 } 110 }
119 111
120 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, 112 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc,
121 const GrPipeline& pipeline) { 113 const GrPipeline& pipeline) {
122 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 114 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
123 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && 115 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
124 fRenderTargetState.fRenderTargetSize.fHeight != pipeline.getRenderTarget ()->height()) { 116 fRenderTargetState.fRenderTargetSize.fHeight != pipeline.getRenderTarget ()->height()) {
125 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, 117 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
126 SkIntToScalar(pipeline.getRenderTarget()->hei ght())); 118 SkIntToScalar(pipeline.getRenderTarget()->hei ght()));
127 } 119 }
(...skipping 12 matching lines...) Expand all
140 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); 132 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec);
141 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); 133 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
142 } 134 }
143 } else { 135 } else {
144 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); 136 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport());
145 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); 137 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
146 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), 138 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(),
147 size, rt->origin()); 139 size, rt->origin());
148 } 140 }
149 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698