17ea439b2203855db97330b25945b87dd4b170b8begdaniel/* 27ea439b2203855db97330b25945b87dd4b170b8begdaniel * Copyright 2015 Google Inc. 37ea439b2203855db97330b25945b87dd4b170b8begdaniel * 47ea439b2203855db97330b25945b87dd4b170b8begdaniel * Use of this source code is governed by a BSD-style license that can be 57ea439b2203855db97330b25945b87dd4b170b8begdaniel * found in the LICENSE file. 67ea439b2203855db97330b25945b87dd4b170b8begdaniel */ 77ea439b2203855db97330b25945b87dd4b170b8begdaniel 87ea439b2203855db97330b25945b87dd4b170b8begdaniel#ifndef GrGLSLUniformHandler_DEFINED 97ea439b2203855db97330b25945b87dd4b170b8begdaniel#define GrGLSLUniformHandler_DEFINED 107ea439b2203855db97330b25945b87dd4b170b8begdaniel 117ea439b2203855db97330b25945b87dd4b170b8begdaniel#include "GrGLSLProgramDataManager.h" 127ea439b2203855db97330b25945b87dd4b170b8begdaniel#include "GrGLSLShaderVar.h" 137ea439b2203855db97330b25945b87dd4b170b8begdaniel 147ea439b2203855db97330b25945b87dd4b170b8begdanielclass GrGLSLProgramBuilder; 157ea439b2203855db97330b25945b87dd4b170b8begdaniel 167ea439b2203855db97330b25945b87dd4b170b8begdanielclass GrGLSLUniformHandler { 177ea439b2203855db97330b25945b87dd4b170b8begdanielpublic: 187ea439b2203855db97330b25945b87dd4b170b8begdaniel virtual ~GrGLSLUniformHandler() {} 197ea439b2203855db97330b25945b87dd4b170b8begdaniel 207ea439b2203855db97330b25945b87dd4b170b8begdaniel typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; 217ea439b2203855db97330b25945b87dd4b170b8begdaniel 227ea439b2203855db97330b25945b87dd4b170b8begdaniel /** Add a uniform variable to the current program, that has visibility in one or more shaders. 235e58ceea8569f0d90ff7e3daf5de2def50407212cdalton visibility is a bitfield of GrShaderFlag values indicating from which shaders the uniform 245e58ceea8569f0d90ff7e3daf5de2def50407212cdalton should be accessible. At least one bit must be set. Geometry shader uniforms are not 257ea439b2203855db97330b25945b87dd4b170b8begdaniel supported at this time. The actual uniform name will be mangled. If outName is not nullptr 267ea439b2203855db97330b25945b87dd4b170b8begdaniel then it will refer to the final uniform name after return. Use the addUniformArray variant 277ea439b2203855db97330b25945b87dd4b170b8begdaniel to add an array of uniforms. */ 287ea439b2203855db97330b25945b87dd4b170b8begdaniel UniformHandle addUniform(uint32_t visibility, 297ea439b2203855db97330b25945b87dd4b170b8begdaniel GrSLType type, 307ea439b2203855db97330b25945b87dd4b170b8begdaniel GrSLPrecision precision, 317ea439b2203855db97330b25945b87dd4b170b8begdaniel const char* name, 327ea439b2203855db97330b25945b87dd4b170b8begdaniel const char** outName = nullptr) { 337ea439b2203855db97330b25945b87dd4b170b8begdaniel return this->addUniformArray(visibility, type, precision, name, 0, outName); 347ea439b2203855db97330b25945b87dd4b170b8begdaniel } 357ea439b2203855db97330b25945b87dd4b170b8begdaniel 367ea439b2203855db97330b25945b87dd4b170b8begdaniel UniformHandle addUniformArray(uint32_t visibility, 377ea439b2203855db97330b25945b87dd4b170b8begdaniel GrSLType type, 387ea439b2203855db97330b25945b87dd4b170b8begdaniel GrSLPrecision precision, 397ea439b2203855db97330b25945b87dd4b170b8begdaniel const char* name, 407ea439b2203855db97330b25945b87dd4b170b8begdaniel int arrayCount, 417ea439b2203855db97330b25945b87dd4b170b8begdaniel const char** outName = nullptr) { 427ea439b2203855db97330b25945b87dd4b170b8begdaniel return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount, 437ea439b2203855db97330b25945b87dd4b170b8begdaniel outName); 447ea439b2203855db97330b25945b87dd4b170b8begdaniel } 457ea439b2203855db97330b25945b87dd4b170b8begdaniel 467ea439b2203855db97330b25945b87dd4b170b8begdaniel virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0; 477ea439b2203855db97330b25945b87dd4b170b8begdaniel 487ea439b2203855db97330b25945b87dd4b170b8begdaniel /** 497ea439b2203855db97330b25945b87dd4b170b8begdaniel * Shortcut for getUniformVariable(u).c_str() 507ea439b2203855db97330b25945b87dd4b170b8begdaniel */ 517ea439b2203855db97330b25945b87dd4b170b8begdaniel virtual const char* getUniformCStr(UniformHandle u) const = 0; 527ea439b2203855db97330b25945b87dd4b170b8begdanielprotected: 537ea439b2203855db97330b25945b87dd4b170b8begdaniel explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {} 547ea439b2203855db97330b25945b87dd4b170b8begdaniel 557ea439b2203855db97330b25945b87dd4b170b8begdaniel // This is not owned by the class 567ea439b2203855db97330b25945b87dd4b170b8begdaniel GrGLSLProgramBuilder* fProgramBuilder; 577ea439b2203855db97330b25945b87dd4b170b8begdaniel 587ea439b2203855db97330b25945b87dd4b170b8begdanielprivate: 597ea439b2203855db97330b25945b87dd4b170b8begdaniel virtual UniformHandle internalAddUniformArray(uint32_t visibility, 607ea439b2203855db97330b25945b87dd4b170b8begdaniel GrSLType type, 617ea439b2203855db97330b25945b87dd4b170b8begdaniel GrSLPrecision precision, 627ea439b2203855db97330b25945b87dd4b170b8begdaniel const char* name, 637ea439b2203855db97330b25945b87dd4b170b8begdaniel bool mangleName, 647ea439b2203855db97330b25945b87dd4b170b8begdaniel int arrayCount, 657ea439b2203855db97330b25945b87dd4b170b8begdaniel const char** outName) = 0; 667ea439b2203855db97330b25945b87dd4b170b8begdaniel 675e58ceea8569f0d90ff7e3daf5de2def50407212cdalton virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const = 0; 687ea439b2203855db97330b25945b87dd4b170b8begdaniel 697ea439b2203855db97330b25945b87dd4b170b8begdaniel friend class GrGLSLProgramBuilder; 707ea439b2203855db97330b25945b87dd4b170b8begdaniel}; 717ea439b2203855db97330b25945b87dd4b170b8begdaniel 727ea439b2203855db97330b25945b87dd4b170b8begdaniel#endif 737ea439b2203855db97330b25945b87dd4b170b8begdaniel 74