2013-12-03 10:38:55 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_HWUI_SHADOW_TESSELLATOR_H
|
|
|
|
#define ANDROID_HWUI_SHADOW_TESSELLATOR_H
|
|
|
|
|
2014-10-15 15:46:42 -04:00
|
|
|
#include <SkPath.h>
|
|
|
|
|
2013-12-03 10:38:55 -08:00
|
|
|
#include "Debug.h"
|
|
|
|
#include "Matrix.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2014-10-15 15:46:42 -04:00
|
|
|
class VertexBuffer;
|
|
|
|
|
2014-02-14 13:13:41 -08:00
|
|
|
// All SHADOW_* are used to define all the geometry property of shadows.
|
|
|
|
// Use a simplified example to illustrate the geometry setup here.
|
|
|
|
// Assuming we use 6 rays and only 1 layer, Then we will have 2 hexagons, which
|
|
|
|
// are 0 to 5 and 6 to 11. The area between them will be the penumbra area, and
|
|
|
|
// the area inside the 2nd hexagon is the umbra.
|
2014-03-11 16:52:30 -07:00
|
|
|
// Ambient shadow is using only 1 layer for opaque caster, otherwise, spot
|
|
|
|
// shadow and ambient shadow are using 2 layers.
|
2014-02-14 13:13:41 -08:00
|
|
|
// Triange strip indices for penumbra area: (0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 0, 6)
|
|
|
|
// 0
|
|
|
|
//
|
|
|
|
// 5 6 1
|
|
|
|
// 11 7
|
2014-03-11 16:52:30 -07:00
|
|
|
//
|
2014-02-14 13:13:41 -08:00
|
|
|
// 10 8
|
|
|
|
// 4 9 2
|
|
|
|
//
|
|
|
|
// 3
|
|
|
|
|
|
|
|
// The total number of rays starting from the centroid of shadow area, in order
|
|
|
|
// to generate the shadow geometry.
|
2014-03-07 18:27:49 -08:00
|
|
|
#define SHADOW_RAY_COUNT 128
|
2014-02-14 13:13:41 -08:00
|
|
|
|
|
|
|
// The total number of all the vertices representing the shadow.
|
2014-03-11 16:52:30 -07:00
|
|
|
// For the case we only have 1 layer, then we will just fill only 2/3 of it.
|
|
|
|
#define SHADOW_VERTEX_COUNT (3 * SHADOW_RAY_COUNT)
|
2014-02-14 13:13:41 -08:00
|
|
|
|
|
|
|
// The total number of indices used for drawing the shadow geometry as triangle strips.
|
2014-03-11 16:52:30 -07:00
|
|
|
// Depending on the mode we are drawing, we can have 1 layer or 2 layers.
|
|
|
|
// Therefore, we only build the longer index buffer.
|
|
|
|
#define TWO_POLY_RING_SHADOW_INDEX_COUNT (4 * (SHADOW_RAY_COUNT + 1))
|
|
|
|
#define ONE_POLY_RING_SHADOW_INDEX_COUNT (2 * (SHADOW_RAY_COUNT + 1))
|
|
|
|
|
|
|
|
#define MAX_SHADOW_INDEX_COUNT TWO_POLY_RING_SHADOW_INDEX_COUNT
|
2014-02-14 13:13:41 -08:00
|
|
|
|
2014-03-11 17:42:29 -07:00
|
|
|
#define SHADOW_MIN_CASTER_Z 0.001f
|
|
|
|
|
2014-04-22 11:21:49 -07:00
|
|
|
#define MINIMAL_DELTA_THETA (M_PI / 180 / 1000)
|
|
|
|
|
2013-12-03 10:38:55 -08:00
|
|
|
class ShadowTessellator {
|
|
|
|
public:
|
2017-11-03 10:12:19 -07:00
|
|
|
static void tessellateAmbientShadow(bool isCasterOpaque, const Vector3* casterPolygon,
|
|
|
|
int casterVertexCount, const Vector3& centroid3d,
|
|
|
|
const Rect& casterBounds, const Rect& localClip, float maxZ,
|
|
|
|
VertexBuffer& shadowVertexBuffer);
|
2014-01-07 10:42:55 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
static void tessellateSpotShadow(bool isCasterOpaque, const Vector3* casterPolygon,
|
|
|
|
int casterVertexCount, const Vector3& casterCentroid,
|
|
|
|
const mat4& receiverTransform, const Vector3& lightCenter,
|
|
|
|
int lightRadius, const Rect& casterBounds,
|
|
|
|
const Rect& localClip, VertexBuffer& shadowVertexBuffer);
|
2014-02-14 13:13:41 -08:00
|
|
|
|
|
|
|
static Vector2 centroid2d(const Vector2* poly, int polyLength);
|
2014-04-28 16:43:13 -07:00
|
|
|
|
2014-08-21 13:47:54 -07:00
|
|
|
static Vector2 calculateNormal(const Vector2& p1, const Vector2& p2);
|
2014-04-28 16:43:13 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
static int getExtraVertexNumber(const Vector2& vector1, const Vector2& vector2, float divisor);
|
2014-09-10 13:08:20 -07:00
|
|
|
|
|
|
|
static void checkOverflow(int used, int total, const char* bufferName);
|
2017-11-03 10:12:19 -07:00
|
|
|
}; // ShadowTessellator
|
2013-12-03 10:38:55 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
2013-12-03 10:38:55 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
#endif // ANDROID_HWUI_SHADOW_TESSELLATOR_H
|