PageRenderTime 454ms CodeModel.GetById 281ms app.highlight 5ms RepoModel.GetById 166ms app.codeStats 0ms

/opengles/src/Types.h

http://ftk.googlecode.com/
C++ Header | 89 lines | 36 code | 18 blank | 35 comment | 2 complexity | 679222bb6ecf381e9b05c510eb205a41 MD5 | raw file
 1#ifndef EGL_TYPES_H
 2#define EGL_TYPES_H 1
 3
 4// ==========================================================================
 5//
 6// Types.h			Type declarations and helpers 
 7//
 8// --------------------------------------------------------------------------
 9//
10// 05-26-2004		Hans-Martin Will	initial version
11//
12// --------------------------------------------------------------------------
13//
14// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
15// 
16// Redistribution and use in source and binary forms, with or without 
17// modification, are permitted provided that the following conditions are 
18// met:
19// 
20//	 *  Redistributions of source code must retain the above copyright
21// 		notice, this list of conditions and the following disclaimer. 
22//   *	Redistributions in binary form must reproduce the above copyright
23// 		notice, this list of conditions and the following disclaimer in the 
24// 		documentation and/or other materials provided with the distribution. 
25// 
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
31// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
36// THE POSSIBILITY OF SUCH DAMAGE.
37//
38// ==========================================================================
39
40
41#include "OGLES.h"
42#include "GLES/gl.h"
43
44
45namespace EGL {
46
47	template<class T> T Min(const T& a, const T& b) {
48		return a < b ? a : b;
49	}
50
51	template<class T> T Max(const T& a, const T& b) {
52		return a > b ? a : b;
53	}
54
55	struct Rect {
56
57		Rect(GLint _x = 0, GLint _y = 0, GLsizei _width = 0, GLsizei _height = 0): 
58			x(_x), y(_y), width(_width), height(_height) 
59		{}
60
61		static Rect Intersect(const Rect& first, const Rect& second) {
62
63			GLint x = Max(first.x, second.x);
64			GLint y = Max(first.y, second.y);
65
66			GLint xtop = Min(first.x + first.width, second.x + second.width);
67			GLint ytop = Min(first.y + first.height, second.y + second.height);
68
69			return Rect(x, y, xtop - x, ytop - y);
70		}
71
72		bool Contains(const Rect& other) const {
73			return 
74				x <= other.x && 
75				y <= other.y &&
76				x + width >= other.x + other.width && 
77				y + height >= other.y + other.height;
78		}
79
80		GLint x;
81		GLint y;
82		GLsizei width;
83		GLsizei height;
84	};
85
86}
87
88
89#endif //ndef EGL_TYPES_H