csgfx/renderbuffer.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003-2005 by Marten Svanfeldt 00003 Anders Stenberg 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSGFX_RENDERBUFFER_H__ 00021 #define __CS_CSGFX_RENDERBUFFER_H__ 00022 00027 #include "csextern.h" 00028 #include "csutil/csstring.h" 00029 #include "csutil/leakguard.h" 00030 #include "csutil/scf_implementation.h" 00031 #include "csutil/weakref.h" 00032 #include "imap/renderbufferpersistence.h" 00033 #include "ivideo/rndbuf.h" 00034 00043 struct csInterleavedSubBufferOptions 00044 { 00046 csRenderBufferComponentType componentType; 00048 uint componentCount; 00049 }; 00050 00051 #ifdef CS_DEBUG 00052 class csCallStack; 00053 #endif 00054 00058 class CS_CRYSTALSPACE_EXPORT csRenderBuffer : 00059 public scfImplementation1<csRenderBuffer, iRenderBuffer> 00060 { 00061 protected: 00065 csRenderBuffer (size_t size, csRenderBufferType type, 00066 csRenderBufferComponentType componentType, uint componentCount, 00067 size_t rangeStart, size_t rangeEnd, bool copy = true); 00068 public: 00069 CS_LEAKGUARD_DECLARE (csRenderBuffer); 00070 00074 virtual ~csRenderBuffer (); 00075 00078 virtual void* Lock (csRenderBufferLockType lockType); 00079 00080 virtual void Release(); 00081 00082 virtual void CopyInto (const void *data, size_t elementCount, 00083 size_t elemOffset = 0); 00084 00085 virtual int GetComponentCount () const 00086 { 00087 return props.compCount; 00088 } 00089 00090 virtual csRenderBufferComponentType GetComponentType () const 00091 { 00092 return props.comptype; 00093 } 00094 00095 virtual csRenderBufferType GetBufferType() const 00096 { 00097 return props.bufferType; 00098 } 00099 00100 virtual size_t GetSize() const 00101 { 00102 return bufferSize; 00103 } 00104 00105 virtual size_t GetStride() const 00106 { 00107 return props.stride; 00108 } 00109 00110 virtual size_t GetElementDistance() const 00111 { 00112 return props.stride ? props.stride : 00113 props.compCount * csRenderBufferComponentSizes[props.comptype]; 00114 } 00115 00116 virtual size_t GetOffset() const 00117 { return props.offset; } 00118 00120 virtual uint GetVersion () 00121 { 00122 return version; 00123 } 00124 00125 bool IsMasterBuffer () 00126 { 00127 return !masterBuffer.IsValid(); 00128 } 00129 00130 virtual iRenderBuffer* GetMasterBuffer () const 00131 { 00132 return masterBuffer; 00133 } 00134 00135 virtual bool IsIndexBuffer() const 00136 { return props.isIndex; } 00137 00138 virtual size_t GetRangeStart() const 00139 { return rangeStart; } 00140 virtual size_t GetRangeEnd() const 00141 { return rangeEnd; } 00142 00143 virtual size_t GetElementCount() const; 00144 00145 virtual void SetCallback (iRenderBufferCallback *cb) 00146 { 00147 callback = cb; 00148 } 00149 virtual void SetData (const void *data); 00169 static csRef<csRenderBuffer> CreateRenderBuffer (size_t elementCount, 00170 csRenderBufferType type, csRenderBufferComponentType componentType, 00171 uint componentCount); 00172 00173 CS_DEPRECATED_METHOD_MSG("Using the 'copy' flag is deprecated; " 00174 "use SetData() instead if data copying is not desired") 00175 static csRef<csRenderBuffer> CreateRenderBuffer (size_t elementCount, 00176 csRenderBufferType type, csRenderBufferComponentType componentType, 00177 uint componentCount, bool copy); 00178 00196 static csRef<csRenderBuffer> CreateIndexRenderBuffer (size_t elementCount, 00197 csRenderBufferType type, csRenderBufferComponentType componentType, 00198 size_t rangeStart, size_t rangeEnd); 00199 00200 CS_DEPRECATED_METHOD_MSG("Using the 'copy' flag is deprecated; " 00201 "use SetData() instead of data copying is not desired") 00202 static csRef<csRenderBuffer> CreateIndexRenderBuffer (size_t elementCount, 00203 csRenderBufferType type, csRenderBufferComponentType componentType, 00204 size_t rangeStart, size_t rangeEnd, bool copy); 00205 00230 static csRef<csRenderBuffer> CreateInterleavedRenderBuffers ( 00231 size_t elementCount, 00232 csRenderBufferType type, uint count, 00233 const csInterleavedSubBufferOptions* elements, 00234 csRef<iRenderBuffer>* buffers); 00243 static const char* GetDescrFromBufferName (csRenderBufferName bufferName); 00248 static csRenderBufferName GetBufferNameFromDescr (const char* name); 00259 void SetRenderBufferProperties (size_t elementCount, 00260 csRenderBufferType type, csRenderBufferComponentType componentType, 00261 uint componentCount, bool copy = true); 00262 void SetIndexBufferProperties (size_t elementCount, 00263 csRenderBufferType type, csRenderBufferComponentType componentType, 00264 size_t rangeStart, size_t rangeEnd, bool copy = true); 00266 protected: 00268 size_t bufferSize; 00269 00274 struct Props 00275 { 00277 csRenderBufferType bufferType : 2; 00279 csRenderBufferComponentType comptype : 4; 00280 00282 uint compCount : 8; 00284 size_t stride : 8; 00286 size_t offset : 8; 00287 00289 bool doCopy : 1; 00291 bool doDelete : 1; 00293 bool isLocked : 1; 00295 bool isIndex : 1; 00296 00298 uint lastLock : 2; 00299 00300 Props (csRenderBufferType type, csRenderBufferComponentType componentType, 00301 uint componentCount, bool copy) : bufferType (type), 00302 comptype (componentType), compCount (componentCount), stride(0), 00303 offset (0), doCopy (copy), doDelete (false), isLocked (false), 00304 isIndex (false), lastLock (0) 00305 { 00306 CS_ASSERT(componentCount <= 255); // Just to be sure... 00307 } 00308 } props; 00309 00311 size_t rangeStart; 00313 size_t rangeEnd; 00314 00316 unsigned int version; 00317 00319 unsigned char *buffer; 00320 00321 csRef<iRenderBuffer> masterBuffer; 00322 00323 csWeakRef<iRenderBufferCallback> callback; 00324 00325 #ifdef CS_DEBUG 00326 csCallStack* lockStack; 00327 #endif 00328 }; 00329 00332 namespace CS 00333 { 00338 00339 class RenderBufferPersistent : 00340 public scfImplementation2<RenderBufferPersistent, 00341 iRenderBuffer, 00342 iRenderBufferPersistence> 00343 { 00344 csRef<iRenderBuffer> wrappedBuffer; 00345 csString filename; 00346 public: 00347 RenderBufferPersistent (iRenderBuffer* wrappedBuffer) : 00348 scfImplementationType (this), wrappedBuffer (wrappedBuffer) {} 00349 00350 void SetFileName (const char* filename) { this->filename = filename; } 00351 const char* GetFileName () { return filename; } 00352 00355 void* Lock (csRenderBufferLockType lockType) 00356 { return wrappedBuffer->Lock (lockType); } 00357 void Release() { wrappedBuffer->Release (); } 00358 void CopyInto (const void *data, size_t elementCount, 00359 size_t elemOffset = 0) 00360 { wrappedBuffer->CopyInto (data, elementCount, elemOffset); } 00361 int GetComponentCount () const 00362 { return wrappedBuffer->GetComponentCount(); } 00363 csRenderBufferComponentType GetComponentType () const 00364 { return wrappedBuffer->GetComponentType(); } 00365 csRenderBufferType GetBufferType() const 00366 { return wrappedBuffer->GetBufferType(); } 00367 size_t GetSize() const 00368 { return wrappedBuffer->GetSize(); } 00369 size_t GetStride() const 00370 { return wrappedBuffer->GetStride(); } 00371 size_t GetElementDistance() const 00372 { return wrappedBuffer->GetElementDistance(); } 00373 size_t GetOffset() const 00374 { return wrappedBuffer->GetOffset(); } 00375 uint GetVersion () 00376 { return wrappedBuffer->GetVersion (); } 00377 iRenderBuffer* GetMasterBuffer () const 00378 { return wrappedBuffer->GetMasterBuffer (); } 00379 bool IsIndexBuffer() const 00380 { return wrappedBuffer->IsIndexBuffer (); } 00381 size_t GetRangeStart() const 00382 { return wrappedBuffer->GetRangeStart (); } 00383 size_t GetRangeEnd() const 00384 { return wrappedBuffer->GetRangeEnd (); } 00385 size_t GetElementCount() const 00386 { return wrappedBuffer->GetElementCount (); } 00387 void SetCallback (iRenderBufferCallback *cb) 00388 { wrappedBuffer->SetCallback (cb); } 00389 void SetData (const void *data) 00390 { wrappedBuffer->SetData (data); } 00392 }; 00393 00395 } // namespace CS 00396 00397 #endif // __CS_CSGFX_RENDERBUFFER_H__
Generated for Crystal Space 1.2 by doxygen 1.4.7