blob: 11b5b004079f0d4231228adef26b33444d3d24a3 [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001/*
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 Nicholas82399462017-10-16 12:35:44 -040013#include <cmath>
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkPoint.h"
Hal Canary02eefbe2019-06-26 13:54:14 -040015#include "include/core/SkRect.h"
Ethan Nicholas762466e2017-06-29 10:03:38 -040016
Ethan Nicholas82399462017-10-16 12:35:44 -040017using std::abs;
18
Ethan Nicholase9d172a2017-11-20 12:12:24 -050019struct 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 Nicholase9d172a2017-11-20 12:12:24 -050030private:
31 float fX;
32 float fY;
33 float fZ;
34 float fW;
35};
36
Ethan Nicholas762466e2017-06-29 10:03:38 -040037// macros to make sk_Caps.<cap name> work from C++ code
38#define sk_Caps (*args.fShaderCaps)
39
Chris Dalton47c8ed32017-11-15 18:27:09 -070040#define floatIs32Bits floatIs32Bits()
Ethan Nicholas762466e2017-06-29 10:03:38 -040041
42// functions to make GLSL constructors work from C++ code
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040043inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); }
Ethan Nicholas762466e2017-06-29 10:03:38 -040044
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040045inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); }
Ethan Nicholas762466e2017-06-29 10:03:38 -040046
Ethan Nicholase9d172a2017-11-20 12:12:24 -050047inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); }
Ethan Nicholas8dca18a2017-11-15 15:33:33 -050048
Ethan Nicholase9d172a2017-11-20 12:12:24 -050049inline Float4 float4(float x, float y, float z, float w) { return Float4(x, y, z, w); }
Ethan Nicholas8dca18a2017-11-15 15:33:33 -050050
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051#define half2 float2
52
Ethan Nicholase9d172a2017-11-20 12:12:24 -050053#define half3 float3
54
55#define half4 float4
56
Ethan Nicholas762466e2017-06-29 10:03:38 -040057#endif