blob: 057153a9a6f2119ab1cdc3e3d5eaa4ebc85e5512 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15#ifndef sw_Clipper_hpp
16#define sw_Clipper_hpp
17
18#include "Plane.hpp"
19#include "Common/Types.hpp"
20
21namespace sw
22{
23 struct Polygon;
24 struct DrawCall;
25 struct DrawData;
26
27 class Clipper
28 {
29 public:
30 enum ClipFlags
31 {
Nicolas Capens53bf0a12016-05-26 11:19:02 -040032 // Indicates the vertex is outside the respective frustum plane
John Bauman66b8ab22014-05-06 15:57:45 -040033 CLIP_RIGHT = 1 << 0,
34 CLIP_TOP = 1 << 1,
35 CLIP_FAR = 1 << 2,
36 CLIP_LEFT = 1 << 3,
37 CLIP_BOTTOM = 1 << 4,
38 CLIP_NEAR = 1 << 5,
39
Nicolas Capens53bf0a12016-05-26 11:19:02 -040040 CLIP_FRUSTUM = 0x003F,
41
42 CLIP_FINITE = 1 << 7, // All position coordinates are finite
John Bauman66b8ab22014-05-06 15:57:45 -040043
44 // User-defined clipping planes
Nicolas Capens53bf0a12016-05-26 11:19:02 -040045 CLIP_PLANE0 = 1 << 8,
46 CLIP_PLANE1 = 1 << 9,
47 CLIP_PLANE2 = 1 << 10,
48 CLIP_PLANE3 = 1 << 11,
49 CLIP_PLANE4 = 1 << 12,
50 CLIP_PLANE5 = 1 << 13,
51
52 CLIP_USER = 0x3F00
John Bauman66b8ab22014-05-06 15:57:45 -040053 };
54
Nicolas Capens00bfa182016-05-20 21:30:54 -070055 Clipper(bool symmetricNormalizedDepth);
John Bauman66b8ab22014-05-06 15:57:45 -040056
57 ~Clipper();
58
Nicolas Capens53bf0a12016-05-26 11:19:02 -040059 unsigned int computeClipFlags(const float4 &v);
John Bauman66b8ab22014-05-06 15:57:45 -040060 bool clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw);
61
62 private:
63 void clipNear(Polygon &polygon);
64 void clipFar(Polygon &polygon);
Nicolas Capens53bf0a12016-05-26 11:19:02 -040065 void clipLeft(Polygon &polygon);
66 void clipRight(Polygon &polygon);
67 void clipTop(Polygon &polygon);
68 void clipBottom(Polygon &polygon);
John Bauman66b8ab22014-05-06 15:57:45 -040069 void clipPlane(Polygon &polygon, const Plane &plane);
70
71 void clipEdge(float4 &Vo, const float4 &Vi, const float4 &Vj, float di, float dj) const;
Nicolas Capens00bfa182016-05-20 21:30:54 -070072
73 float n; // Near clip plane distance
John Bauman66b8ab22014-05-06 15:57:45 -040074 };
75}
76
77#endif // sw_Clipper_hpp