Hash :
e3e680ca
        
        Author :
  
        
        Date :
2018-12-03T17:49:08
        
      
Remove State::syncProgramTextures. Removes the concept of the program textures dirty object. Instead we use a set of dirty bits to represent dirty texture samples. We mark certain textures dirty and update state structures whenever there is a new Texture/Program/Sampler bound, or when Texture/Program/Sampler state changes. This is in preparation for making clearing the uncleared active textures into a dirty bit as well. Also includes new dirty bit handling for texture image units. These are a GLES 3.1 feature. Bug: angleproject:2966 Change-Id: Ibb8619dd2669bb39fdbcd75e3685be9a8aeeee91 Reviewed-on: https://chromium-review.googlesource.com/c/1346649 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// GLES1Renderer.h: Defines GLES1 emulation rendering operations on top of a GLES3
// context. Used by Context.h.
#ifndef LIBANGLE_GLES1_RENDERER_H_
#define LIBANGLE_GLES1_RENDERER_H_
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/angletypes.h"
#include <memory>
#include <string>
#include <unordered_map>
namespace gl
{
class Context;
class GLES1State;
class Program;
class State;
class Shader;
class ShaderProgramManager;
class GLES1Renderer final : angle::NonCopyable
{
  public:
    GLES1Renderer();
    ~GLES1Renderer();
    void onDestroy(Context *context, State *state);
    angle::Result prepareForDraw(PrimitiveMode mode, Context *context, State *glState);
    static int VertexArrayIndex(ClientVertexArrayType type, const GLES1State &gles1);
    static int TexCoordArrayIndex(unsigned int unit);
    void drawTexture(Context *context,
                     State *glState,
                     float x,
                     float y,
                     float z,
                     float width,
                     float height);
    static constexpr int kTexUnitCount = 4;
  private:
    using Mat4Uniform = float[16];
    using Vec4Uniform = float[4];
    using Vec3Uniform = float[3];
    Shader *getShader(GLuint handle) const;
    Program *getProgram(GLuint handle) const;
    angle::Result compileShader(Context *context,
                                ShaderType shaderType,
                                const char *src,
                                GLuint *shaderOut);
    angle::Result linkProgram(Context *context,
                              State *glState,
                              GLuint vshader,
                              GLuint fshader,
                              const std::unordered_map<GLint, std::string> &attribLocs,
                              GLuint *programOut);
    angle::Result initializeRendererProgram(Context *context, State *glState);
    void setUniform1i(Context *context, Program *programObject, GLint loc, GLint value);
    void setUniform1iv(Context *context,
                       Program *programObject,
                       GLint loc,
                       GLint count,
                       const GLint *value);
    void setUniformMatrix4fv(Program *programObject,
                             GLint loc,
                             GLint count,
                             GLboolean transpose,
                             const GLfloat *value);
    void setUniform4fv(Program *programObject, GLint loc, GLint count, const GLfloat *value);
    void setUniform3fv(Program *programObject, GLint loc, GLint count, const GLfloat *value);
    void setUniform2fv(Program *programObject, GLint loc, GLint count, const GLfloat *value);
    void setUniform1f(Program *programObject, GLint loc, GLfloat value);
    void setUniform1fv(Program *programObject, GLint loc, GLint count, const GLfloat *value);
    void setAttributesEnabled(Context *context, State *glState, AttributesMask mask);
    static constexpr int kLightCount     = 8;
    static constexpr int kClipPlaneCount = 6;
    static constexpr int kVertexAttribIndex           = 0;
    static constexpr int kNormalAttribIndex           = 1;
    static constexpr int kColorAttribIndex            = 2;
    static constexpr int kPointSizeAttribIndex        = 3;
    static constexpr int kTextureCoordAttribIndexBase = 4;
    bool mRendererProgramInitialized;
    ShaderProgramManager *mShaderPrograms;
    struct GLES1ProgramState
    {
        GLuint program;
        GLint projMatrixLoc;
        GLint modelviewMatrixLoc;
        GLint textureMatrixLoc;
        GLint modelviewInvTrLoc;
        // Texturing
        GLint enableTexture2DLoc;
        GLint enableTextureCubeMapLoc;
        std::array<GLint, kTexUnitCount> tex2DSamplerLocs;
        std::array<GLint, kTexUnitCount> texCubeSamplerLocs;
        GLint textureFormatLoc;
        GLint textureEnvModeLoc;
        GLint combineRgbLoc;
        GLint combineAlphaLoc;
        GLint src0rgbLoc;
        GLint src0alphaLoc;
        GLint src1rgbLoc;
        GLint src1alphaLoc;
        GLint src2rgbLoc;
        GLint src2alphaLoc;
        GLint op0rgbLoc;
        GLint op0alphaLoc;
        GLint op1rgbLoc;
        GLint op1alphaLoc;
        GLint op2rgbLoc;
        GLint op2alphaLoc;
        GLint textureEnvColorLoc;
        GLint rgbScaleLoc;
        GLint alphaScaleLoc;
        GLint pointSpriteCoordReplaceLoc;
        // Alpha test
        GLint enableAlphaTestLoc;
        GLint alphaFuncLoc;
        GLint alphaTestRefLoc;
        // Shading, materials, and lighting
        GLint shadeModelFlatLoc;
        GLint enableLightingLoc;
        GLint enableRescaleNormalLoc;
        GLint enableNormalizeLoc;
        GLint enableColorMaterialLoc;
        GLint materialAmbientLoc;
        GLint materialDiffuseLoc;
        GLint materialSpecularLoc;
        GLint materialEmissiveLoc;
        GLint materialSpecularExponentLoc;
        GLint lightModelSceneAmbientLoc;
        GLint lightModelTwoSidedLoc;
        GLint lightEnablesLoc;
        GLint lightAmbientsLoc;
        GLint lightDiffusesLoc;
        GLint lightSpecularsLoc;
        GLint lightPositionsLoc;
        GLint lightDirectionsLoc;
        GLint lightSpotlightExponentsLoc;
        GLint lightSpotlightCutoffAnglesLoc;
        GLint lightAttenuationConstsLoc;
        GLint lightAttenuationLinearsLoc;
        GLint lightAttenuationQuadraticsLoc;
        // Fog
        GLint fogEnableLoc;
        GLint fogModeLoc;
        GLint fogDensityLoc;
        GLint fogStartLoc;
        GLint fogEndLoc;
        GLint fogColorLoc;
        // Clip planes
        GLint enableClipPlanesLoc;
        GLint clipPlaneEnablesLoc;
        GLint clipPlanesLoc;
        // Point rasterization
        GLint pointRasterizationLoc;
        GLint pointSizeMinLoc;
        GLint pointSizeMaxLoc;
        GLint pointDistanceAttenuationLoc;
        GLint pointSpriteEnabledLoc;
        // Draw texture
        GLint enableDrawTextureLoc;
        GLint drawTextureCoordsLoc;
        GLint drawTextureDimsLoc;
        GLint drawTextureNormalizedCropRectLoc;
    };
    struct GLES1UniformBuffers
    {
        std::array<Mat4Uniform, kTexUnitCount> textureMatrices;
        std::array<GLint, kTexUnitCount> tex2DEnables;
        std::array<GLint, kTexUnitCount> texCubeEnables;
        std::array<GLint, kTexUnitCount> texEnvModes;
        std::array<GLint, kTexUnitCount> texCombineRgbs;
        std::array<GLint, kTexUnitCount> texCombineAlphas;
        std::array<GLint, kTexUnitCount> texCombineSrc0Rgbs;
        std::array<GLint, kTexUnitCount> texCombineSrc0Alphas;
        std::array<GLint, kTexUnitCount> texCombineSrc1Rgbs;
        std::array<GLint, kTexUnitCount> texCombineSrc1Alphas;
        std::array<GLint, kTexUnitCount> texCombineSrc2Rgbs;
        std::array<GLint, kTexUnitCount> texCombineSrc2Alphas;
        std::array<GLint, kTexUnitCount> texCombineOp0Rgbs;
        std::array<GLint, kTexUnitCount> texCombineOp0Alphas;
        std::array<GLint, kTexUnitCount> texCombineOp1Rgbs;
        std::array<GLint, kTexUnitCount> texCombineOp1Alphas;
        std::array<GLint, kTexUnitCount> texCombineOp2Rgbs;
        std::array<GLint, kTexUnitCount> texCombineOp2Alphas;
        std::array<Vec4Uniform, kTexUnitCount> texEnvColors;
        std::array<GLfloat, kTexUnitCount> texEnvRgbScales;
        std::array<GLfloat, kTexUnitCount> texEnvAlphaScales;
        std::array<GLint, kTexUnitCount> pointSpriteCoordReplaces;
        // Lighting
        std::array<GLint, kLightCount> lightEnables;
        std::array<Vec4Uniform, kLightCount> lightAmbients;
        std::array<Vec4Uniform, kLightCount> lightDiffuses;
        std::array<Vec4Uniform, kLightCount> lightSpeculars;
        std::array<Vec4Uniform, kLightCount> lightPositions;
        std::array<Vec3Uniform, kLightCount> lightDirections;
        std::array<GLfloat, kLightCount> spotlightExponents;
        std::array<GLfloat, kLightCount> spotlightCutoffAngles;
        std::array<GLfloat, kLightCount> attenuationConsts;
        std::array<GLfloat, kLightCount> attenuationLinears;
        std::array<GLfloat, kLightCount> attenuationQuadratics;
        // Clip planes
        std::array<GLint, kClipPlaneCount> clipPlaneEnables;
        std::array<Vec4Uniform, kClipPlaneCount> clipPlanes;
        // Texture crop rectangles
        std::array<Vec4Uniform, kTexUnitCount> texCropRects;
    };
    GLES1UniformBuffers mUniformBuffers;
    GLES1ProgramState mProgramState;
    bool mDrawTextureEnabled      = false;
    GLfloat mDrawTextureCoords[4] = {0.0f, 0.0f, 0.0f, 0.0f};
    GLfloat mDrawTextureDims[2]   = {0.0f, 0.0f};
};
}  // namespace gl
#endif  // LIBANGLE_GLES1_RENDERER_H_