| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsD3D9Prerequisites.h"
- #include "BsPixelBuffer.h"
- namespace BansheeEngine
- {
- /** @addtogroup D3D9
- * @{
- */
- /** DirectX9 implementation of a pixel buffer. Represents a hardware buffer containing a surface of pixels. */
- class BS_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
- {
- protected:
- /** Internal DX9 buffer resources container. */
- struct BufferResources
- {
- IDirect3DSurface9* surface;
- IDirect3DVolume9* volume;
- IDirect3DSurface9* tempSurface;
- IDirect3DVolume9* tempVolume;
- IDirect3DBaseTexture9* mipTex;
- };
- public:
- D3D9PixelBuffer(GpuBufferUsage usage, D3D9TextureCore* ownerTexture);
- ~D3D9PixelBuffer();
- /**
- * Binds the specified surface object to this buffer. This needs to be called in order to initialize the pixel
- * buffer.
- *
- * @param[in] dev Device the surface was created on.
- * @param[in] surface DirectX 9 object representing the surface.
- * @param[in] mipTex Base texture that will be used for generating mipmaps. Usually the parent texture of
- * the surface.
- */
- void bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex);
- /**
- * Binds the specified volume object to this buffer. This needs to be called in order to initialize the pixel
- * buffer.
- *
- * @param[in] dev Device the volume was created on.
- * @param[in] volume DirectX 9 object representing the volume.
- * @param[in] mipTex Base texture that will be used for generating mipmaps. Usually the parent texture of
- * the volume.
- */
- void bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex);
- /**
- * Enables/disabled automatic mipmap generation on updates.
- *
- * @param[in] doMipmapGen If true, mipmaps will be regenerated whenever data is written to the buffer.
- * @param[in] HWMipmaps If true the mipmaps will be generated by the hardware, otherwise software (slower).
- */
- void setMipmapping(bool doMipmapGen, bool HWMipmaps);
- /** Returns internal DirectX 9 surface object for this buffer. */
- IDirect3DSurface9* getSurface(IDirect3DDevice9* d3d9Device);
- /** Release all surface objects held by this buffer for the specified device. */
- void releaseSurfaces(IDirect3DDevice9* d3d9Device);
- /** Destroy all resources associated with the specified device. */
- void destroyBufferResources(IDirect3DDevice9* d3d9Device);
- /** Called when device state is changing. Access to any device should be locked. */
- static void lockDeviceAccess();
- /** Called when device state change completed. Access to any device is allowed. */
- static void unlockDeviceAccess();
- /** Initializes the provided pixel data buffer with information provided in the D3D9 locked rectangle. */
- static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_RECT& lrect);
- /** Initializes the provided pixel data buffer with information provided in the D3D9 locked box. */
- static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_BOX& lrect);
- protected:
- /** @copydoc PixelBuffer::lockImpl */
- PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) override;
- /** @copydoc PixelBuffer::unlockImpl */
- void unlockImpl() override;
- /**
- * Locks the specified volume of the provided buffer objects and returns a data buffer that you may use to access
- * it.
- */
- PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
- /** Unlocks the specified buffer objects. */
- void unlockBuffer(BufferResources* bufferResources);
- /** Generates mip-map chain for the specified texture. */
- void genMipmaps(IDirect3DBaseTexture9* mipTex);
- /** Retrieves buffer resources for the specified device, or null if they do not exist. */
- BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
- /** Creates a new empty set of buffer resources. */
- BufferResources* createBufferResources();
- protected:
- Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
- bool mDoMipmapGen;
- bool mHWMipmaps;
- D3D9TextureCore* mOwnerTexture;
- DWORD mLockFlags;
- };
- /** @} */
- };
|