OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkNormalSource_DEFINED |
| 9 #define SkNormalSource_DEFINED |
| 10 |
| 11 #include "SkFlattenable.h" |
| 12 |
| 13 /** Abstract class that generates or reads in normals for use by SkLightingShade
r. Not to be |
| 14 used as part of the API yet. Used internally by SkLightingShader. |
| 15 */ |
| 16 class SK_API SkNormalSource : public SkFlattenable { |
| 17 public: |
| 18 virtual ~SkNormalSource() override; |
| 19 |
| 20 #if SK_SUPPORT_GPU |
| 21 /** Returns a fragment processor that takes no input and outputs a normal (a
lready rotated) |
| 22 as its output color. To be used as a child fragment processor. |
| 23 */ |
| 24 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor( |
| 25 GrContext* context, |
| 26 const SkMatrix& viewM, |
| 27 const SkMatrix* localMatrix, |
| 28 SkFilterQuality filterQuality, |
| 29 SkSourceGammaTreatment gammaTreatment) const = 0; |
| 30 #endif |
| 31 |
| 32 class Provider { |
| 33 public: |
| 34 virtual ~Provider() {}; |
| 35 |
| 36 /** Called for each span of the object being drawn on the CPU. Your subc
lass should set |
| 37 the appropriate normals that correspond to the specified device coor
dinates. |
| 38 */ |
| 39 virtual void fillScanLine(int x, int y, SkPoint3 output[], int count) co
nst = 0; |
| 40 }; |
| 41 |
| 42 /** Returns an instance of 'Provider' that provides normals for the CPU pipe
line. The |
| 43 necessary data will be initialized in place at 'storage'. |
| 44 */ |
| 45 virtual Provider* asProvider(const SkShader::ContextRec&, void* storage) con
st = 0; |
| 46 |
| 47 /** Amount of memory needed to store a provider object and its dependencies. |
| 48 */ |
| 49 virtual size_t providerSize(const SkShader::ContextRec&) const = 0; |
| 50 |
| 51 /** Returns a normal source that provides normals sourced from the the norma
l map argument. |
| 52 Not to be used as part of the API yet. Used internally by SkLightingShad
er. |
| 53 |
| 54 @param map a shader that outputs the normal map |
| 55 @param normRotation rotation applied to the normal map's normals, i
n the |
| 56 [cos a, sin a] form. |
| 57 |
| 58 nullptr will be returned if 'map' is null |
| 59 |
| 60 The normal map is currently assumed to be an 8888 image where the normal
at a texel |
| 61 is retrieved by: |
| 62 N.x = R-127; |
| 63 N.y = G-127; |
| 64 N.z = B-127; |
| 65 N.normalize(); |
| 66 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is |
| 67 (127, 127, 0). |
| 68 */ |
| 69 static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, |
| 70 const SkVector& normRotation)
; |
| 71 |
| 72 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) |
| 73 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
| 74 }; |
| 75 |
| 76 #endif |
OLD | NEW |