/opengles/src/linux-ftk/Surface.h
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// 6// Surface.h Drawing Surface Class for 3D Rendering Library 7// 8// -------------------------------------------------------------------------- 9// 10// 08-14-2003 Hans-Martin Will initial version 11// 08-18-2010 Li XianJing port to ftk 12// 13// -------------------------------------------------------------------------- 14// 15// Copyright (c) 2004, Hans-Martin Will. All rights reserved. 16// 17// Redistribution and use in source and binary forms, with or without 18// modification, are permitted provided that the following conditions are 19// met: 20// 21// * Redistributions of source code must retain the above copyright 22// notice, this list of conditions and the following disclaimer. 23// * Redistributions in binary form must reproduce the above copyright 24// notice, this list of conditions and the following disclaimer in the 25// documentation and/or other materials provided with the distribution. 26// 27// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 31// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 32// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 37// THE POSSIBILITY OF SUCH DAMAGE. 38// 39// ========================================================================== 40 41 42#include <ftk.h> 43#include "OGLES.h" 44#include "GLES/egl.h" 45#include "GLES/gl.h" 46#include "Types.h" 47#include "Config.h" 48#include "fixed.h" 49#include "Color.h" 50#include "Color.h" 51 52namespace EGL { 53 54 class Surface { 55 friend class Context; 56 57 public: 58 59 // Create a PBuffer surface 60 Surface(const Config & config, NativeDisplayType display, NativeWindowType win); 61 ~Surface(); 62 63 // Is the depth value re-scaled based on near/far settings?. 64 void ClearDepthBuffer(U16 depth, bool mask, const Rect& scissor); 65 void ClearColorBuffer(const Color & rgba, const Color & mask, const Rect& scissor); 66 void ClearStencilBuffer(U32 value, U32 mask, const Rect& scissor); 67 68 void ClearDepthBuffer(U16 depth, bool mask); 69 void ClearColorBuffer(const Color & rgba, const Color & mask); 70 void ClearStencilBuffer(U32 value, U32 mask); 71 72 U16 GetWidth(); 73 U16 GetHeight(); 74 U32 GetPixels(); 75 const Rect& GetRect() const; 76 77 void SetCurrentContext(Context * context); 78 Context * GetCurrentContext(); 79 80 U16 * GetColorBuffer(); 81 U8 * GetAlphaBuffer(); 82 U16 * GetDepthBuffer(); 83 U32 * GetStencilBuffer(); 84 85 Config * GetConfig(); 86 bool Save(const char *filename); 87 void Dispose(); 88 89 // Windows integration 90 NativeDisplayType GetDisplay(); 91 NativeWindowType GetWidget(); 92 NativePixmapType GetBitmap(); 93 94 int GetSurfaceType(); 95 96 private: 97 int m_SurfaceType; 98 int m_WindowDepth; 99 Rect m_Rect; 100 Config m_Config; // configuration arguments 101 U16 * m_ColorBuffer; // pointer to frame buffer base address 5-6-5 102 U8 * m_AlphaBuffer; // pointer to alpha buffer 103 U16 * m_DepthBuffer; // pointer to Z-buffer base address 104 U32 * m_StencilBuffer; // stencil buffer 105 106 NativeWindowType m_Window; 107 NativePixmapType m_Bitmap; 108 NativeDisplayType m_Display; // windows device context handle 109 110 Context * m_CurrentContext; 111 bool m_Disposed; // the surface 112 }; 113 114 115 // -------------------------------------------------------------------------- 116 // Inline accessors 117 // -------------------------------------------------------------------------- 118 119 inline Config * Surface :: GetConfig() { 120 return &m_Config; 121 } 122 123 inline U32 Surface :: GetPixels() { 124 return GetWidth() * GetHeight(); 125 } 126 127 inline Context * Surface :: GetCurrentContext() { 128 return m_CurrentContext; 129 } 130 131 inline NativePixmapType Surface :: GetBitmap() { 132 return m_Bitmap; 133 } 134 135 inline NativeWindowType Surface :: GetWidget() { 136 return m_Window; 137 } 138 139 inline int Surface :: GetSurfaceType() { 140 return m_SurfaceType; 141 } 142 143 inline U16 * Surface :: GetColorBuffer() { 144 return m_ColorBuffer; 145 } 146 147 inline U8 * Surface :: GetAlphaBuffer() { 148 return m_AlphaBuffer; 149 } 150 151 inline U16 * Surface :: GetDepthBuffer() { 152 return m_DepthBuffer; 153 } 154 155 inline U32 * Surface :: GetStencilBuffer() { 156 return m_StencilBuffer; 157 } 158 159 inline U16 Surface :: GetWidth() { 160 return m_Rect.width; 161 } 162 163 inline U16 Surface :: GetHeight() { 164 return m_Rect.height; 165 } 166 167 inline const Rect& Surface :: GetRect() const { 168 return m_Rect; 169 } 170 171 inline void Surface :: ClearDepthBuffer(U16 depth, bool mask) { 172 ClearDepthBuffer(depth, mask, GetRect()); 173 } 174 175 inline void Surface :: ClearColorBuffer(const Color & rgba, const Color & mask) { 176 ClearColorBuffer(rgba, mask, GetRect()); 177 } 178 179 inline void Surface :: ClearStencilBuffer(U32 value, U32 mask) { 180 ClearStencilBuffer(value, mask, GetRect()); 181 } 182} 183 184#endif // ndef EGL_SURFACE_H