blob: bba63f6f12565bac5be21eacee329474598bee43 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef GrGpuGLShaders2_DEFINED
19#define GrGpuGLShaders2_DEFINED
20
21#include "GrGpuGL.h"
22
23// Programmable OpenGL or OpenGL ES 2.0
24class GrGpuGLShaders2 : public GrGpuGL {
25public:
26 GrGpuGLShaders2();
27 virtual ~GrGpuGLShaders2();
28
29 virtual void resetContext();
30
31protected:
32 // overrides from GrGpu
33 virtual bool flushGraphicsState(PrimitiveType type);
34 virtual void setupGeometry(uint32_t startVertex,
35 uint32_t startIndex,
36 uint32_t vertexCount,
37 uint32_t indexCount);
38
39private:
reed@google.comac10a2d2010-12-22 21:39:39 +000040
41 void resetContextHelper();
42
43 // sets the texture matrix uniform for currently bound program
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000044 void flushTextureMatrix(int stage);
45
reed@google.comac10a2d2010-12-22 21:39:39 +000046 // sets the MVP matrix uniform for currently bound program
47 void flushViewMatrix();
48
49 // flushes the parameters to two point radial gradient
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000050 void flushRadial2(int stage);
reed@google.comac10a2d2010-12-22 21:39:39 +000051
52 // called at flush time to setup the appropriate program
53 void flushProgram(PrimitiveType type);
54
55 struct Program;
56
57 struct StageDesc;
58 struct ProgramDesc;
59
60 struct UniLocations;
61 struct StageUniLocations;
62
63 struct ShaderCodeSegments;
64
65 class ProgramCache;
66
67 // gets a description of needed shader
68 void getProgramDesc(PrimitiveType primType, ProgramDesc* desc);
69
70 // generates and compiles a program from a description and vertex layout
71 // will change GL's bound program
72 static void GenProgram(const ProgramDesc& desc, Program* program);
73
74 // generates code for a stage of the shader
75 static void GenStageCode(int stageNum,
76 const StageDesc& desc,
77 const char* psInColor,
78 const char* psOutColor,
79 const char* vsInCoord,
80 ShaderCodeSegments* segments,
81 StageUniLocations* locations);
82
83 // Compiles a GL shader, returns shader ID or 0 if failed
84 // params have same meaning as glShaderSource
85 static GLuint CompileShader(GLenum type, int stringCnt,
86 const char** strings,
87 int* stringLengths);
88 static void DeleteProgram(Program* program);
89
90 void ProgramUnitTest();
91
92 GrGLTexture::Orientation fTextureOrientation;
93
94 ProgramCache* fProgramCache;
95 Program* fProgram;
96 GLuint fHWProgramID;
97
98 typedef GrGpuGL INHERITED;
99};
100
101#endif
102