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