Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef sw_Clipper_hpp |
| 16 | #define sw_Clipper_hpp |
| 17 | |
| 18 | #include "Plane.hpp" |
| 19 | #include "Common/Types.hpp" |
| 20 | |
| 21 | namespace sw |
| 22 | { |
| 23 | struct Polygon; |
| 24 | struct DrawCall; |
| 25 | struct DrawData; |
| 26 | |
| 27 | class Clipper |
| 28 | { |
| 29 | public: |
| 30 | enum ClipFlags |
| 31 | { |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 32 | // Indicates the vertex is outside the respective frustum plane |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 33 | 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 Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 40 | CLIP_FRUSTUM = 0x003F, |
| 41 | |
| 42 | CLIP_FINITE = 1 << 7, // All position coordinates are finite |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 43 | |
| 44 | // User-defined clipping planes |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 45 | 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
Nicolas Capens | 00bfa18 | 2016-05-20 21:30:54 -0700 | [diff] [blame] | 55 | Clipper(bool symmetricNormalizedDepth); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 56 | |
| 57 | ~Clipper(); |
| 58 | |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 59 | unsigned int computeClipFlags(const float4 &v); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 60 | bool clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw); |
| 61 | |
| 62 | private: |
| 63 | void clipNear(Polygon &polygon); |
| 64 | void clipFar(Polygon &polygon); |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 65 | void clipLeft(Polygon &polygon); |
| 66 | void clipRight(Polygon &polygon); |
| 67 | void clipTop(Polygon &polygon); |
| 68 | void clipBottom(Polygon &polygon); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 69 | 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 Capens | 00bfa18 | 2016-05-20 21:30:54 -0700 | [diff] [blame] | 72 | |
| 73 | float n; // Near clip plane distance |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 74 | }; |
| 75 | } |
| 76 | |
| 77 | #endif // sw_Clipper_hpp |