aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/builders/GrGLLegacyNvprProgramBuilder.cpp
blob: e8b4075b03007df5611d98bb16c8e43212f43084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrGLLegacyNvprProgramBuilder.h"
#include "../GrGLGpu.h"

GrGLLegacyNvprProgramBuilder::GrGLLegacyNvprProgramBuilder(GrGLGpu* gpu,
                                                           const GrOptDrawState& optState)
    : INHERITED(gpu, optState)
    , fTexCoordSetCnt(0) {
}

int GrGLLegacyNvprProgramBuilder::addTexCoordSets(int count) {
    int firstFreeCoordSet = fTexCoordSetCnt;
    fTexCoordSetCnt += count;
    SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fTexCoordSetCnt);
    return firstFreeCoordSet;
}

void GrGLLegacyNvprProgramBuilder::emitTransforms(const GrPendingFragmentStage& processorStage,
                                            GrGLProcessor::TransformedCoordsArray* outCoords,
                                            GrGLInstalledFragProc* ifp) {
    int numTransforms = processorStage.processor()->numTransforms();
    int texCoordIndex = this->addTexCoordSets(numTransforms);

    // Use the first uniform location as the texcoord index.  This may seem a bit hacky but it
    // allows us to use one program effects object for all of our programs which really simplifies
    // the code overall
    ifp->fTransforms.push_back_n(1);
    ifp->fTransforms[0].fHandle = GrGLInstalledFragProc::ShaderVarHandle(texCoordIndex);

    SkString name;
    for (int t = 0; t < numTransforms; ++t) {
        GrSLType type = processorStage.isPerspectiveCoordTransform(t) ? kVec3f_GrSLType :
                                                                        kVec2f_GrSLType;

        name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex++);
        SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, (name, type));
    }
}

GrGLProgram* GrGLLegacyNvprProgramBuilder::createProgram(GrGLuint programID) {
    return SkNEW_ARGS(GrGLLegacyNvprProgram, (fGpu, fDesc, fUniformHandles, programID, fUniforms,
            fGeometryProcessor, fXferProcessor, fFragmentProcessors.get(),
                                              fTexCoordSetCnt));
}