1 /* 2 * Copyright 2019 The Android Open Source Project 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 #pragma once 18 19 #include <math/vec4.h> 20 #include <ui/Rect.h> 21 22 #include "GLSkiaShadowPort.h" 23 24 namespace android { 25 namespace renderengine { 26 27 class Mesh; 28 29 namespace gl { 30 31 /** 32 * Generates gl attributes required to draw shadow spot and/or ambient shadows. 33 * 34 * Each shadow can support different colors. This class generates three vertex attributes for 35 * each shadow, its position, color and shadow params(offset and distance). These can be sent 36 * using a single glDrawElements call. 37 */ 38 class GLShadowVertexGenerator { 39 public: 40 GLShadowVertexGenerator(const FloatRect& casterRect, float casterCornerRadius, float casterZ, 41 bool casterIsTranslucent, const vec4& ambientColor, 42 const vec4& spotColor, const vec3& lightPosition, float lightRadius); 43 ~GLShadowVertexGenerator() = default; 44 45 size_t getVertexCount() const; 46 size_t getIndexCount() const; 47 void fillVertices(Mesh::VertexArray<vec2>& position, Mesh::VertexArray<vec4>& color, 48 Mesh::VertexArray<vec3>& params) const; 49 void fillIndices(uint16_t* indices) const; 50 51 private: 52 bool mDrawAmbientShadow; 53 std::unique_ptr<Geometry> mAmbientShadowGeometry; 54 int mAmbientShadowVertexCount = 0; 55 int mAmbientShadowIndexCount = 0; 56 57 bool mDrawSpotShadow; 58 std::unique_ptr<Geometry> mSpotShadowGeometry; 59 int mSpotShadowVertexCount = 0; 60 int mSpotShadowIndexCount = 0; 61 }; 62 63 } // namespace gl 64 } // namespace renderengine 65 } // namespace android 66