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