| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /*
- -----------------------------------------------------------------------------
- This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
- For the latest info, see http://www.ogre3d.org/
- Copyright (c) 2000-2011 Torus Knot Software Ltd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -----------------------------------------------------------------------------
- */
- #ifndef __D3D9PIXELBUFFER_H__
- #define __D3D9PIXELBUFFER_H__
- #include "CmD3D9Prerequisites.h"
- #include "CmHardwarePixelBuffer.h"
- namespace CamelotEngine {
- class D3D9Texture;
- class D3D9RenderTexture;
- class _OgreD3D9Export D3D9HardwarePixelBuffer: public HardwarePixelBuffer
- {
- protected:
- struct BufferResources
- {
- /// Surface abstracted by this buffer
- IDirect3DSurface9* surface;
- /// AA Surface abstracted by this buffer
- IDirect3DSurface9* fSAASurface;
- /// Volume abstracted by this buffer
- IDirect3DVolume9* volume;
- /// Temporary surface in main memory if direct locking of mSurface is not possible
- IDirect3DSurface9* tempSurface;
- /// Temporary volume in main memory if direct locking of mVolume is not possible
- IDirect3DVolume9* tempVolume;
- /// Mip map texture.
- IDirect3DBaseTexture9 *mipTex;
- };
- typedef map<IDirect3DDevice9*, BufferResources*>::type DeviceToBufferResourcesMap;
- typedef DeviceToBufferResourcesMap::iterator DeviceToBufferResourcesIterator;
- /// Map between device to buffer resources.
- DeviceToBufferResourcesMap mMapDeviceToBufferResources;
-
- /// Mipmapping
- bool mDoMipmapGen;
- bool mHWMipmaps;
-
- /// Render target
- D3D9RenderTexture* mRenderTexture;
- // The owner texture if exists.
- D3D9Texture* mOwnerTexture;
-
- // The current lock flags of this surface.
- DWORD mLockFlags;
- // Device access mutex.
- CM_STATIC_MUTEX(msDeviceAccessMutex)
- protected:
- /// Lock a box
- PixelData lockImpl(const Box lockBox, LockOptions options);
- PixelData lockBuffer(BufferResources* bufferResources, const Box &lockBox, DWORD flags);
- /// Unlock a box
- void unlockImpl(void);
- void unlockBuffer(BufferResources* bufferResources);
- BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
- BufferResources* createBufferResources();
-
- /// updates render texture.
- void updateRenderTexture(bool writeGamma, UINT32 fsaa, const String& srcName);
- /// destroy render texture.
- void destroyRenderTexture();
- void blit(IDirect3DDevice9* d3d9Device, const HardwarePixelBufferPtr &src,
- const Box &srcBox, const Box &dstBox,
- BufferResources* srcBufferResources,
- BufferResources* dstBufferResources);
- void blitFromMemory(const PixelData &src, const Box &dstBox, BufferResources* dstBufferResources);
- void blitToMemory(const Box &srcBox, const PixelData &dst, BufferResources* srcBufferResources, IDirect3DDevice9* d3d9Device);
-
- public:
- D3D9HardwarePixelBuffer(HardwareBuffer::Usage usage,
- D3D9Texture* ownerTexture);
- ~D3D9HardwarePixelBuffer();
- /// Call this to associate a D3D surface or volume with this pixel buffer
- void bind(IDirect3DDevice9 *dev, IDirect3DSurface9 *mSurface, IDirect3DSurface9* fsaaSurface,
- bool writeGamma, UINT32 fsaa, const String& srcName, IDirect3DBaseTexture9 *mipTex);
- void bind(IDirect3DDevice9 *dev, IDirect3DVolume9 *mVolume, IDirect3DBaseTexture9 *mipTex);
-
- /// @copydoc HardwarePixelBuffer::blit
- void blit(const HardwarePixelBufferPtr &src, const Box &srcBox, const Box &dstBox);
-
- /// @copydoc HardwarePixelBuffer::blitFromMemory
- void blitFromMemory(const PixelData &src, const Box &dstBox);
-
- /// @copydoc HardwarePixelBuffer::blitToMemory
- void blitToMemory(const Box &srcBox, const PixelData &dst);
-
- /// Internal function to update mipmaps on update of level 0
- void _genMipmaps(IDirect3DBaseTexture9* mipTex);
-
- /// Function to set mipmap generation
- void _setMipmapping(bool doMipmapGen, bool HWMipmaps);
-
-
- /// Get rendertarget for z slice
- RenderTexture *getRenderTarget(size_t zoffset);
- /// Accessor for surface
- IDirect3DSurface9 *getSurface(IDirect3DDevice9* d3d9Device);
-
- /// Accessor for AA surface
- IDirect3DSurface9 *getFSAASurface(IDirect3DDevice9* d3d9Device);
- /// Notify TextureBuffer of destruction of render target
- virtual void _clearSliceRTT(size_t zoffset);
- /// Release surfaces held by this pixel buffer.
- void releaseSurfaces(IDirect3DDevice9* d3d9Device);
- /// Destroy resources associated with the given device.
- void destroyBufferResources(IDirect3DDevice9* d3d9Device);
- // Called when device state is changing. Access to any device should be locked.
- // Relevant for multi thread application.
- static void lockDeviceAccess();
- // Called when device state change completed. Access to any device is allowed.
- // Relevant for multi thread application.
- static void unlockDeviceAccess();
- };
- };
- #endif
|