| OLD | NEW |
| 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" |
| 11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
| 12 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
| 13 #include "GrGLGpu.h" | 13 #include "GrGLGpu.h" |
| 14 #include "GrGLBuffer.h" |
| 14 #include "GrGLPathRendering.h" | 15 #include "GrGLPathRendering.h" |
| 15 #include "GrPathProcessor.h" | 16 #include "GrPathProcessor.h" |
| 16 #include "GrPipeline.h" | 17 #include "GrPipeline.h" |
| 17 #include "GrXferProcessor.h" | 18 #include "GrXferProcessor.h" |
| 18 #include "glsl/GrGLSLFragmentProcessor.h" | 19 #include "glsl/GrGLSLFragmentProcessor.h" |
| 19 #include "glsl/GrGLSLGeometryProcessor.h" | 20 #include "glsl/GrGLSLGeometryProcessor.h" |
| 20 #include "glsl/GrGLSLXferProcessor.h" | 21 #include "glsl/GrGLSLXferProcessor.h" |
| 21 #include "SkXfermode.h" | 22 #include "SkXfermode.h" |
| 22 | 23 |
| 23 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 24 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 delete fFragmentProcessors[i]; | 60 delete fFragmentProcessors[i]; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 void GrGLProgram::abandon() { | 64 void GrGLProgram::abandon() { |
| 64 fProgramID = 0; | 65 fProgramID = 0; |
| 65 } | 66 } |
| 66 | 67 |
| 67 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 68 | 69 |
| 69 static void append_texture_bindings(const GrProcessor& processor, | 70 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline
& pipeline) { |
| 70 SkTArray<const GrTextureAccess*>* textureBin
dings) { | |
| 71 if (int numTextures = processor.numTextures()) { | |
| 72 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu
res); | |
| 73 int i = 0; | |
| 74 do { | |
| 75 bindings[i] = &processor.textureAccess(i); | |
| 76 } while (++i < numTextures); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, | |
| 81 const GrPipeline& pipeline, | |
| 82 SkTArray<const GrTextureAccess*>* textureBindings) { | |
| 83 this->setRenderTargetState(primProc, pipeline); | 71 this->setRenderTargetState(primProc, pipeline); |
| 84 | 72 |
| 85 // we set the textures, and uniforms for installed processors in a generic w
ay, but subclasses | 73 // 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 | 74 // of GLProgram determine how to set coord transforms |
| 75 int nextSamplerIdx = 0; |
| 87 fGeometryProcessor->setData(fProgramDataManager, primProc); | 76 fGeometryProcessor->setData(fProgramDataManager, primProc); |
| 88 append_texture_bindings(primProc, textureBindings); | 77 this->bindTextures(primProc, pipeline.getAllowSRGBInputs(), &nextSamplerIdx)
; |
| 89 | 78 |
| 90 this->setFragmentData(primProc, pipeline, textureBindings); | 79 this->setFragmentData(primProc, pipeline, &nextSamplerIdx); |
| 91 | 80 |
| 92 if (primProc.getPixelLocalStorageState() != | 81 if (primProc.getPixelLocalStorageState() != |
| 93 GrPixelLocalStorageState::kDraw_GrPixelLocalStorageState) { | 82 GrPixelLocalStorageState::kDraw_GrPixelLocalStorageState) { |
| 94 const GrXferProcessor& xp = pipeline.getXferProcessor(); | 83 const GrXferProcessor& xp = pipeline.getXferProcessor(); |
| 95 fXferProcessor->setData(fProgramDataManager, xp); | 84 fXferProcessor->setData(fProgramDataManager, xp); |
| 96 append_texture_bindings(xp, textureBindings); | 85 this->bindTextures(xp, pipeline.getAllowSRGBInputs(), &nextSamplerIdx); |
| 97 } | 86 } |
| 98 } | 87 } |
| 99 | 88 |
| 100 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, | 89 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, |
| 101 const GrPipeline& pipeline, | 90 const GrPipeline& pipeline, |
| 102 SkTArray<const GrTextureAccess*>* textureBindi
ngs) { | 91 int* nextSamplerIdx) { |
| 103 int numProcessors = fFragmentProcessors.count(); | 92 int numProcessors = fFragmentProcessors.count(); |
| 104 for (int i = 0; i < numProcessors; ++i) { | 93 for (int i = 0; i < numProcessors; ++i) { |
| 105 const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i); | 94 const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i); |
| 106 fFragmentProcessors[i]->setData(fProgramDataManager, processor); | 95 fFragmentProcessors[i]->setData(fProgramDataManager, processor); |
| 107 this->setTransformData(primProc, processor, i); | 96 this->setTransformData(primProc, processor, i); |
| 108 append_texture_bindings(processor, textureBindings); | 97 this->bindTextures(processor, pipeline.getAllowSRGBInputs(), nextSampler
Idx); |
| 109 } | 98 } |
| 110 } | 99 } |
| 111 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, | 100 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, |
| 112 const GrFragmentProcessor& processor, | 101 const GrFragmentProcessor& processor, |
| 113 int index) { | 102 int index) { |
| 114 fGeometryProcessor->setTransformData(primProc, fProgramDataManager, index, | 103 fGeometryProcessor->setTransformData(primProc, fProgramDataManager, index, |
| 115 processor.coordTransforms()); | 104 processor.coordTransforms()); |
| 116 } | 105 } |
| 117 | 106 |
| 118 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, | 107 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 138 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); | 127 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); |
| 139 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni,
1, rtAdjustmentVec); | 128 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni,
1, rtAdjustmentVec); |
| 140 } | 129 } |
| 141 } else { | 130 } else { |
| 142 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); | 131 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); |
| 143 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); | 132 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); |
| 144 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), | 133 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), |
| 145 size, rt->origin()); | 134 size, rt->origin()); |
| 146 } | 135 } |
| 147 } | 136 } |
| 137 |
| 138 void GrGLProgram::bindTextures(const GrProcessor& processor, |
| 139 bool allowSRGBInputs, |
| 140 int* nextSamplerIdx) { |
| 141 for (int i = 0; i < processor.numTextures(); ++i) { |
| 142 const GrTextureAccess& access = processor.textureAccess(i); |
| 143 fGpu->bindTexture((*nextSamplerIdx)++, access.getParams(), |
| 144 allowSRGBInputs, static_cast<GrGLTexture*>(access.getT
exture())); |
| 145 } |
| 146 for (int i = 0; i < processor.numBuffers(); ++i) { |
| 147 const GrBufferAccess& access = processor.bufferAccess(i); |
| 148 fGpu->bindTexelBuffer((*nextSamplerIdx)++, access.offsetInBytes(), acces
s.texelConfig(), |
| 149 static_cast<GrGLBuffer*>(access.buffer())); |
| 150 } |
| 151 } |
| OLD | NEW |