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

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: fix build 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
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
59 delete fFragmentProcessors[i];
60 }
58 } 61 }
59 62
60 void GrGLProgram::abandon() { 63 void GrGLProgram::abandon() {
61 fProgramID = 0; 64 fProgramID = 0;
62 } 65 }
63 66
64 /////////////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////////////
65 68
66 template <class Proc> 69 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) { 70 SkTArray<const GrTextureAccess*>* textureBin dings) {
70 if (int numTextures = processor.numTextures()) { 71 if (int numTextures = processor.numTextures()) {
71 SkASSERT(textureBindings->count() == ip->fSamplersIdx);
72 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res); 72 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res);
73 int i = 0; 73 int i = 0;
74 do { 74 do {
75 bindings[i] = &processor.textureAccess(i); 75 bindings[i] = &processor.textureAccess(i);
76 } while (++i < numTextures); 76 } while (++i < numTextures);
77 } 77 }
78 } 78 }
79 79
80 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, 80 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc,
81 const GrPipeline& pipeline, 81 const GrPipeline& pipeline,
82 SkTArray<const GrTextureAccess*>* textureBindings) { 82 SkTArray<const GrTextureAccess*>* textureBindings) {
83 this->setRenderTargetState(primProc, pipeline); 83 this->setRenderTargetState(primProc, pipeline);
84 84
85 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses 85 // 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 86 // of GLProgram determine how to set coord transforms
87 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc); 87 fGeometryProcessor->setData(fProgramDataManager, primProc);
88 append_texture_bindings(fGeometryProcessor.get(), primProc, textureBindings) ; 88 append_texture_bindings(primProc, textureBindings);
89 89
90 this->setFragmentData(primProc, pipeline, textureBindings); 90 this->setFragmentData(primProc, pipeline, textureBindings);
91 91
92 const GrXferProcessor& xp = pipeline.getXferProcessor(); 92 const GrXferProcessor& xp = pipeline.getXferProcessor();
93 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); 93 fXferProcessor->setData(fProgramDataManager, xp);
94 append_texture_bindings(fXferProcessor.get(), xp, textureBindings); 94 append_texture_bindings(xp, textureBindings);
95 } 95 }
96 96
97 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, 97 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc,
98 const GrPipeline& pipeline, 98 const GrPipeline& pipeline,
99 SkTArray<const GrTextureAccess*>* textureBindi ngs) { 99 SkTArray<const GrTextureAccess*>* textureBindi ngs) {
100 int numProcessors = fFragmentProcessors->fProcs.count(); 100 int numProcessors = fFragmentProcessors.count();
101 for (int i = 0; i < numProcessors; ++i) { 101 for (int i = 0; i < numProcessors; ++i) {
102 const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i); 102 const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i);
103 fFragmentProcessors->fProcs[i]->fGLProc->setData(fProgramDataManager, pr ocessor); 103 fFragmentProcessors[i]->setData(fProgramDataManager, processor);
104 this->setTransformData(primProc, 104 this->setTransformData(primProc, processor, i);
105 processor, 105 append_texture_bindings(processor, textureBindings);
106 i,
107 fFragmentProcessors->fProcs[i]);
108 append_texture_bindings(fFragmentProcessors->fProcs[i], processor, textu reBindings);
109 } 106 }
110 } 107 }
111 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, 108 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc,
112 const GrFragmentProcessor& processor, 109 const GrFragmentProcessor& processor,
113 int index, 110 int index) {
114 GrGLInstalledFragProc* ip) { 111 fGeometryProcessor->setTransformData(primProc, fProgramDataManager, index,
115 GrGLSLPrimitiveProcessor* gp = fGeometryProcessor.get()->fGLProc.get(); 112 processor.coordTransforms());
116 gp->setTransformData(primProc, fProgramDataManager, index,
117 processor.coordTransforms());
118 } 113 }
119 114
120 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, 115 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc,
121 const GrPipeline& pipeline) { 116 const GrPipeline& pipeline) {
122 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 117 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
123 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && 118 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
124 fRenderTargetState.fRenderTargetSize.fHeight != pipeline.getRenderTarget ()->height()) { 119 fRenderTargetState.fRenderTargetSize.fHeight != pipeline.getRenderTarget ()->height()) {
125 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, 120 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
126 SkIntToScalar(pipeline.getRenderTarget()->hei ght())); 121 SkIntToScalar(pipeline.getRenderTarget()->hei ght()));
127 } 122 }
(...skipping 12 matching lines...) Expand all
140 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); 135 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec);
141 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); 136 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
142 } 137 }
143 } else { 138 } else {
144 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); 139 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport());
145 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); 140 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
146 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), 141 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(),
147 size, rt->origin()); 142 size, rt->origin());
148 } 143 }
149 } 144 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698