1/* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef GrGLSL_DEFINED 9#define GrGLSL_DEFINED 10 11#include "gl/GrGLInterface.h" 12 13class GrGLShaderVar; 14 15// Limited set of GLSL versions we build shaders for. Caller should round 16// down the GLSL version to one of these enums. 17enum GrGLSLGeneration { 18 /** 19 * Desktop GLSL 1.10 and ES2 shading lang (based on desktop GLSL 1.20) 20 */ 21 k110_GrGLSLGeneration, 22 /** 23 * Desktop GLSL 1.30 24 */ 25 k130_GrGLSLGeneration, 26 /** 27 * Dekstop GLSL 1.50 28 */ 29 k150_GrGLSLGeneration, 30}; 31 32/** 33 * Gets the most recent GLSL Generation compatible with the OpenGL context. 34 */ 35GrGLSLGeneration GrGetGLSLGeneration(GrGLBinding binding, 36 const GrGLInterface* gl); 37 38/** 39 * Returns a string to include at the begining of a shader to declare the GLSL 40 * version. 41 */ 42const char* GrGetGLSLVersionDecl(GrGLBinding binding, 43 GrGLSLGeneration v); 44 45/** 46 * Returns a string to include in a variable decleration to set the fp precision 47 * or an emptry string if precision is not required. 48 */ 49const char* GrGetGLSLVarPrecisionDeclType(GrGLBinding binding); 50 51/** 52 * Returns a string to set the default fp precision for an entire shader, or 53 * an emptry string if precision is not required. 54 */ 55const char* GrGetGLSLShaderPrecisionDecl(GrGLBinding binding); 56 57/** 58 * Depending on the GLSL version being emitted there may be an assumed output 59 * variable from the fragment shader for the color. Otherwise, the shader must 60 * declare an output variable for the color. If this function returns true: 61 * * Parameter var's name will be set to nameIfDeclared 62 * * The variable must be declared in the fragment shader 63 * * The variable has to be bound as the color output 64 * (using glBindFragDataLocation) 65 * If the function returns false: 66 * * Parameter var's name will be set to the GLSL built-in color output name. 67 * * Do not declare the variable in the shader. 68 * * Do not use glBindFragDataLocation to bind the variable 69 * In either case var is initialized to represent the color output in the 70 * shader. 71 */ 72 bool GrGLSLSetupFSColorOuput(GrGLSLGeneration gen, 73 const char* nameIfDeclared, 74 GrGLShaderVar* var); 75 76#endif 77