/opengles/src/linux-ftk/Surface.h

http://ftk.googlecode.com/ · C Header · 184 lines · 105 code · 37 blank · 42 comment · 0 complexity · 133f480654ee8ebd4f5dfbb3f7b14cd1 MD5 · raw file

  1. #ifndef EGL_SURFACE_H
  2. #define EGL_SURFACE_H 1
  3. // ==========================================================================
  4. //
  5. // Surface.h Drawing Surface Class for 3D Rendering Library
  6. //
  7. // --------------------------------------------------------------------------
  8. //
  9. // 08-14-2003 Hans-Martin Will initial version
  10. // 08-18-2010 Li XianJing port to ftk
  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. #include <ftk.h>
  40. #include "OGLES.h"
  41. #include "GLES/egl.h"
  42. #include "GLES/gl.h"
  43. #include "Types.h"
  44. #include "Config.h"
  45. #include "fixed.h"
  46. #include "Color.h"
  47. #include "Color.h"
  48. namespace EGL {
  49. class Surface {
  50. friend class Context;
  51. public:
  52. // Create a PBuffer surface
  53. Surface(const Config & config, NativeDisplayType display, NativeWindowType win);
  54. ~Surface();
  55. // Is the depth value re-scaled based on near/far settings?.
  56. void ClearDepthBuffer(U16 depth, bool mask, const Rect& scissor);
  57. void ClearColorBuffer(const Color & rgba, const Color & mask, const Rect& scissor);
  58. void ClearStencilBuffer(U32 value, U32 mask, const Rect& scissor);
  59. void ClearDepthBuffer(U16 depth, bool mask);
  60. void ClearColorBuffer(const Color & rgba, const Color & mask);
  61. void ClearStencilBuffer(U32 value, U32 mask);
  62. U16 GetWidth();
  63. U16 GetHeight();
  64. U32 GetPixels();
  65. const Rect& GetRect() const;
  66. void SetCurrentContext(Context * context);
  67. Context * GetCurrentContext();
  68. U16 * GetColorBuffer();
  69. U8 * GetAlphaBuffer();
  70. U16 * GetDepthBuffer();
  71. U32 * GetStencilBuffer();
  72. Config * GetConfig();
  73. bool Save(const char *filename);
  74. void Dispose();
  75. // Windows integration
  76. NativeDisplayType GetDisplay();
  77. NativeWindowType GetWidget();
  78. NativePixmapType GetBitmap();
  79. int GetSurfaceType();
  80. private:
  81. int m_SurfaceType;
  82. int m_WindowDepth;
  83. Rect m_Rect;
  84. Config m_Config; // configuration arguments
  85. U16 * m_ColorBuffer; // pointer to frame buffer base address 5-6-5
  86. U8 * m_AlphaBuffer; // pointer to alpha buffer
  87. U16 * m_DepthBuffer; // pointer to Z-buffer base address
  88. U32 * m_StencilBuffer; // stencil buffer
  89. NativeWindowType m_Window;
  90. NativePixmapType m_Bitmap;
  91. NativeDisplayType m_Display; // windows device context handle
  92. Context * m_CurrentContext;
  93. bool m_Disposed; // the surface
  94. };
  95. // --------------------------------------------------------------------------
  96. // Inline accessors
  97. // --------------------------------------------------------------------------
  98. inline Config * Surface :: GetConfig() {
  99. return &m_Config;
  100. }
  101. inline U32 Surface :: GetPixels() {
  102. return GetWidth() * GetHeight();
  103. }
  104. inline Context * Surface :: GetCurrentContext() {
  105. return m_CurrentContext;
  106. }
  107. inline NativePixmapType Surface :: GetBitmap() {
  108. return m_Bitmap;
  109. }
  110. inline NativeWindowType Surface :: GetWidget() {
  111. return m_Window;
  112. }
  113. inline int Surface :: GetSurfaceType() {
  114. return m_SurfaceType;
  115. }
  116. inline U16 * Surface :: GetColorBuffer() {
  117. return m_ColorBuffer;
  118. }
  119. inline U8 * Surface :: GetAlphaBuffer() {
  120. return m_AlphaBuffer;
  121. }
  122. inline U16 * Surface :: GetDepthBuffer() {
  123. return m_DepthBuffer;
  124. }
  125. inline U32 * Surface :: GetStencilBuffer() {
  126. return m_StencilBuffer;
  127. }
  128. inline U16 Surface :: GetWidth() {
  129. return m_Rect.width;
  130. }
  131. inline U16 Surface :: GetHeight() {
  132. return m_Rect.height;
  133. }
  134. inline const Rect& Surface :: GetRect() const {
  135. return m_Rect;
  136. }
  137. inline void Surface :: ClearDepthBuffer(U16 depth, bool mask) {
  138. ClearDepthBuffer(depth, mask, GetRect());
  139. }
  140. inline void Surface :: ClearColorBuffer(const Color & rgba, const Color & mask) {
  141. ClearColorBuffer(rgba, mask, GetRect());
  142. }
  143. inline void Surface :: ClearStencilBuffer(U32 value, U32 mask) {
  144. ClearStencilBuffer(value, mask, GetRect());
  145. }
  146. }
  147. #endif // ndef EGL_SURFACE_H