blob: 2da697ff30e1ab123cd48588ac82a4173c98b543 [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>
Ethan Nicholas762466e2017-06-29 10:03:38 -040014#include "SkPoint.h"
15
Ethan Nicholas82399462017-10-16 12:35:44 -040016using std::abs;
17
Ethan Nicholase9d172a2017-11-20 12:12:24 -050018struct 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 Nicholase9d172a2017-11-20 12:12:24 -050029private:
30 float fX;
31 float fY;
32 float fZ;
33 float fW;
34};
35
Ethan Nicholas762466e2017-06-29 10:03:38 -040036// macros to make sk_Caps.<cap name> work from C++ code
37#define sk_Caps (*args.fShaderCaps)
38
Chris Dalton47c8ed32017-11-15 18:27:09 -070039#define floatIs32Bits floatIs32Bits()
Ethan Nicholas762466e2017-06-29 10:03:38 -040040
41// functions to make GLSL constructors work from C++ code
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040042inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); }
Ethan Nicholas762466e2017-06-29 10:03:38 -040043
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040044inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); }
Ethan Nicholas762466e2017-06-29 10:03:38 -040045
Ethan Nicholase9d172a2017-11-20 12:12:24 -050046inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); }
Ethan Nicholas8dca18a2017-11-15 15:33:33 -050047
Ethan Nicholase9d172a2017-11-20 12:12:24 -050048inline Float4 float4(float x, float y, float z, float w) { return Float4(x, y, z, w); }
Ethan Nicholas8dca18a2017-11-15 15:33:33 -050049
Ethan Nicholasf7b88202017-09-18 14:10:39 -040050#define half2 float2
51
Ethan Nicholase9d172a2017-11-20 12:12:24 -050052#define half3 float3
53
54#define half4 float4
55
Ethan Nicholas762466e2017-06-29 10:03:38 -040056#endif