Home | History | Annotate | Download | only in src
      1 /*
      2     Copyright 2011 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 GrGpuGLShaders_DEFINED
     19 #define GrGpuGLShaders_DEFINED
     20 
     21 #include "GrGpuGL.h"
     22 #include "GrGLProgram.h"
     23 
     24 class GrGpuGLProgram;
     25 
     26 // Programmable OpenGL or OpenGL ES 2.0
     27 class GrGpuGLShaders : public GrGpuGL {
     28 public:
     29              GrGpuGLShaders();
     30     virtual ~GrGpuGLShaders();
     31 
     32     virtual void resetContext();
     33 
     34     virtual void abandonResources();
     35 
     36 protected:
     37     // overrides from GrGpu
     38     virtual bool flushGraphicsState(GrPrimitiveType type);
     39     virtual void setupGeometry(int* startVertex,
     40                                int* startIndex,
     41                                int vertexCount,
     42                                int indexCount);
     43     virtual void postDraw();
     44 
     45 private:
     46 
     47     class ProgramCache;
     48 
     49     // Helpers to make code more readable
     50     const GrMatrix& getHWSamplerMatrix(int stage);
     51     void recordHWSamplerMatrix(int stage, const GrMatrix& matrix);
     52 
     53     // sets the texture matrix uniform for currently bound program
     54     void flushTextureMatrix(int stage);
     55 
     56     // sets the texture domain uniform for currently bound program
     57     void flushTextureDomain(int stage);
     58 
     59     // sets the color specified by GrDrawTarget::setColor()
     60     void flushColor();
     61 
     62     // sets the MVP matrix uniform for currently bound program
     63     void flushViewMatrix();
     64 
     65     // flushes the parameters to two point radial gradient
     66     void flushRadial2(int stage);
     67 
     68     // flushes the normalized texel size
     69     void flushTexelSize(int stage);
     70 
     71     // flushes the edges for edge AA
     72     void flushEdgeAAData();
     73 
     74     static void DeleteProgram(GrGLProgram::CachedData* programData);
     75 
     76     void ProgramUnitTest();
     77 
     78     void buildProgram(GrPrimitiveType type);
     79 
     80     ProgramCache*               fProgramCache;
     81     GrGLProgram::CachedData*    fProgramData;
     82     GrGLuint                    fHWProgramID;
     83     GrGLProgram                 fCurrentProgram;
     84 
     85     typedef GrGpuGL INHERITED;
     86 };
     87 
     88 #endif
     89 
     90