Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 SKSL_CPP |
| 9 | #define SKSL_CPP |
| 10 | |
| 11 | // functions used by CPP programs created by skslc |
| 12 | |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 13 | #include <cmath> |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 14 | #include "SkPoint.h" |
| 15 | |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 16 | using std::abs; |
| 17 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 18 | struct Float4 { |
| 19 | Float4(float x, float y, float z, float w) |
| 20 | : fX(x) |
| 21 | , fY(y) |
| 22 | , fZ(z) |
| 23 | , fW(w) {} |
| 24 | |
| 25 | operator SkRect() const { |
| 26 | return SkRect::MakeLTRB(fX, fY, fZ, fW); |
| 27 | } |
| 28 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 29 | private: |
| 30 | float fX; |
| 31 | float fY; |
| 32 | float fZ; |
| 33 | float fW; |
| 34 | }; |
| 35 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 36 | // macros to make sk_Caps.<cap name> work from C++ code |
| 37 | #define sk_Caps (*args.fShaderCaps) |
| 38 | |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 39 | #define floatIs32Bits floatIs32Bits() |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 40 | |
| 41 | // functions to make GLSL constructors work from C++ code |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 42 | inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 43 | |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 44 | inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 45 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 46 | inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); } |
Ethan Nicholas | 8dca18a | 2017-11-15 15:33:33 -0500 | [diff] [blame] | 47 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 48 | inline Float4 float4(float x, float y, float z, float w) { return Float4(x, y, z, w); } |
Ethan Nicholas | 8dca18a | 2017-11-15 15:33:33 -0500 | [diff] [blame] | 49 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 50 | #define half2 float2 |
| 51 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 52 | #define half3 float3 |
| 53 | |
| 54 | #define half4 float4 |
| 55 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 56 | #endif |