Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
rbuflock.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2004 by Jorrit Tyberghein 00003 (C) 2004 by Frank Richter 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_CSTOOL_RBUFLOCK_H__ 00021 #define __CS_CSTOOL_RBUFLOCK_H__ 00022 00027 #include "csutil/ref.h" 00028 #include "ivideo/graph3d.h" 00029 #include "ivideo/rndbuf.h" 00030 00036 template <class T> 00037 class csRenderBufferLock 00038 { 00039 csRef<iRenderBuffer> buffer; 00040 csRenderBufferLockType lockType; 00041 bool isLocked; 00042 T* lockBuf; 00043 size_t bufOfs, bufStride; 00044 00045 csRenderBufferLock() {} 00046 public: 00050 csRenderBufferLock (iRenderBuffer* buf, 00051 csRenderBufferLockType lock = CS_BUF_LOCK_NORMAL) : buffer(buf), 00052 lockType(lock), isLocked(false), bufOfs(buf->GetOffset()), 00053 bufStride(buf->GetElementDistance()) 00054 { 00055 } 00056 00060 ~csRenderBufferLock() 00061 { 00062 Unlock(); 00063 } 00064 00069 T* Lock () 00070 { 00071 if (!isLocked) 00072 { 00073 lockBuf = (T*)((uint8*)buffer->Lock (lockType) + bufOfs); 00074 isLocked = true; 00075 } 00076 return lockBuf; 00077 } 00078 00080 void Unlock () 00081 { 00082 if (isLocked) 00083 { 00084 buffer->Release(); 00085 isLocked = false; 00086 } 00087 } 00088 00093 operator T* () 00094 { 00095 return Lock(); 00096 } 00097 00099 T& operator [] (size_t n) 00100 { 00101 return Get (n); 00102 } 00103 00105 T& Get (size_t n) 00106 { 00107 return *((T*)((uint8*)Lock() + n * bufStride)); 00108 } 00109 }; 00110 00111 #endif // __CS_CSTOOL_RBUFLOCK_H__
Generated for Crystal Space by doxygen 1.3.9.1