OgreD3D9HardwarePixelBuffer.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __D3D9PIXELBUFFER_H__
00029 #define __D3D9PIXELBUFFER_H__
00030 
00031 #include "OgreD3D9Prerequisites.h"
00032 #include "OgreHardwarePixelBuffer.h"
00033 #include "Threading/OgreThreadHeaders.h"
00034 
00035 namespace Ogre {
00036 
00037     class D3D9Texture;
00038     class D3D9RenderTexture;
00039 
00040     class _OgreD3D9Export D3D9HardwarePixelBuffer: public HardwarePixelBuffer
00041     {
00042     protected:      
00043         struct BufferResources
00044         {           
00046             IDirect3DSurface9* surface;
00048             IDirect3DSurface9* fSAASurface;
00050             IDirect3DVolume9* volume;
00052             IDirect3DSurface9* tempSurface;
00054             IDirect3DVolume9* tempVolume;
00056             IDirect3DBaseTexture9 *mipTex;          
00057         };
00058 
00059         typedef map<IDirect3DDevice9*, BufferResources*>::type  DeviceToBufferResourcesMap;
00060         typedef DeviceToBufferResourcesMap::iterator            DeviceToBufferResourcesIterator;
00061 
00063         DeviceToBufferResourcesMap  mMapDeviceToBufferResources;
00064                 
00066         bool mDoMipmapGen;
00067         bool mHWMipmaps;
00068         
00070         D3D9RenderTexture* mRenderTexture;
00071 
00072         // The owner texture if exists.
00073         D3D9Texture* mOwnerTexture;
00074         
00075         // The current lock flags of this surface.
00076         DWORD mLockFlags;
00077 
00078         // Device access mutex.
00079         OGRE_STATIC_MUTEX(msDeviceAccessMutex);
00080     protected:
00082         PixelBox lockImpl(const Image::Box lockBox,  LockOptions options);
00083         PixelBox lockBuffer(BufferResources* bufferResources, const Image::Box &lockBox, DWORD flags);
00084 
00086         void unlockImpl(void);
00087         void unlockBuffer(BufferResources* bufferResources);
00088 
00089         BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
00090         BufferResources* createBufferResources();
00091     
00093         void updateRenderTexture(bool writeGamma, uint fsaa, const String& srcName);
00095         void destroyRenderTexture();
00096 
00097         void blit(IDirect3DDevice9* d3d9Device, const HardwarePixelBufferSharedPtr &src,
00098                 const Image::Box &srcBox, const Image::Box &dstBox, 
00099                 BufferResources* srcBufferResources, 
00100                 BufferResources* dstBufferResources);
00101         void blitFromMemory(const PixelBox &src, const Image::Box &dstBox, BufferResources* dstBufferResources);
00102 
00103         void blitToMemory(const Image::Box &srcBox, const PixelBox &dst, BufferResources* srcBufferResources, IDirect3DDevice9* d3d9Device);
00104             
00105     public:
00106         D3D9HardwarePixelBuffer(HardwareBuffer::Usage usage, 
00107             D3D9Texture* ownerTexture);
00108         ~D3D9HardwarePixelBuffer();
00109 
00111         void bind(IDirect3DDevice9 *dev, IDirect3DSurface9 *mSurface, IDirect3DSurface9* fsaaSurface,
00112                   bool writeGamma, uint fsaa, const String& srcName, IDirect3DBaseTexture9 *mipTex);
00113         void bind(IDirect3DDevice9 *dev, IDirect3DVolume9 *mVolume, IDirect3DBaseTexture9 *mipTex);
00114         
00116         void blit(const HardwarePixelBufferSharedPtr &src, const Image::Box &srcBox, const Image::Box &dstBox);
00117         
00119         void blitFromMemory(const PixelBox &src, const Image::Box &dstBox);
00120     
00122         void blitToMemory(const Image::Box &srcBox, const PixelBox &dst);
00123         
00125         void _genMipmaps(IDirect3DBaseTexture9* mipTex);
00126         
00128         void _setMipmapping(bool doMipmapGen, bool HWMipmaps);
00129         
00130         
00132         RenderTexture *getRenderTarget(size_t zoffset);
00133 
00135         IDirect3DSurface9 *getSurface(IDirect3DDevice9* d3d9Device);
00136         
00138         IDirect3DSurface9 *getFSAASurface(IDirect3DDevice9* d3d9Device);
00139 
00141         virtual void _clearSliceRTT(size_t zoffset);
00142 
00144         void releaseSurfaces(IDirect3DDevice9* d3d9Device);
00145 
00147         void destroyBufferResources(IDirect3DDevice9* d3d9Device);
00148 
00149         // Called when device state is changing. Access to any device should be locked.
00150         // Relevant for multi thread application.
00151         static void lockDeviceAccess();
00152 
00153         // Called when device state change completed. Access to any device is allowed.
00154         // Relevant for multi thread application.
00155         static void unlockDeviceAccess();
00156     };
00157 };
00158 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:41