Commits

rride_a  committed 99ca113

updated NULL NPB and RenderTexture

  • Participants
  • Parent commits b40cb89

Comments (0)

Files changed (4)

File NullHardwarePixelBuffer.cpp

 #include "NULLHardwarePixelBuffer.h"
+#include "NULLTexture.h"
+NULLHardwarePixelBuffer::NULLHardwarePixelBuffer( size_t mWidth, size_t mHeight, size_t mDepth, PixelFormat mFormat, 
+													HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer )
+	:	HardwarePixelBuffer( mWidth, mHeight, mDepth, mFormat, usage, useSystemMemory, useShadowBuffer ),
+		mRenderTexture(0)
+{
+	_data.resize(PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat) );
+	if (usage & TU_RENDERTARGET)
+	{
+		_updateRenderTexture(true);
+	}
+}
 
-void NULLHardwarePixelBuffer::updateRenderTexture( bool writeGamma, uint fsaa, const String& srcName )
+NULLHardwarePixelBuffer::~NULLHardwarePixelBuffer()
 {
-	if (mRenderTexture == NULL)
+	_data.clear();
+
+	if (mUsage & TU_RENDERTARGET)
 	{
-		String name;
-		name = "rtt/" +Ogre::StringConverter::toString((size_t)this) + "/" + srcName;
-
-		mRenderTexture = new D3D9RenderTexture(name, this, writeGamma, fsaa);		
-		Root::getSingleton().getRenderSystem()->attachRenderTarget(*mRenderTexture);
+		_updateRenderTexture(false);
+	}
+}
+
+void NULLHardwarePixelBuffer::_updateRenderTexture( bool enable )
+{
+	if(enable)
+	{
+    	if (mRenderTexture == NULL)
+    	{
+    		String name = "rtt/" +Ogre::StringConverter::toString((size_t)this);
+    
+    		mRenderTexture = new NULLRenderTexture(name, this);		
+    		Root::getSingleton().getRenderSystem()->attachRenderTarget(*mRenderTexture);
+    	}
+	}
+	else
+	{
+		if (mRenderTexture)
+		{
+    		Root::getSingleton().getRenderSystem()->detachRenderTarget(mRenderTexture->getName());
+			mRenderTexture = 0;
+		}
 	}
 }
 
 Ogre::PixelBox NULLHardwarePixelBuffer::lockImpl( const Image::Box lockBox, LockOptions options )
 {
+	Ogre::PixelBox box(mWidth, mHeight, mDepth, getFormat(), &_data[0] );
 
+	box.rowPitch	= box.getWidth();
+	box.slicePitch	= box.rowPitch * box.getHeight();
+
+	unsigned bitsPerByte = 8;
+	unsigned byteOffset = (lockBox.top * box.getWidth() + lockBox.left ) * PixelUtil::getNumElemBits(getFormat()) / bitsPerByte;
+	box.data = &_data[byteOffset];
+
+	return box;
 }
 
 void NULLHardwarePixelBuffer::unlockImpl( void )
 {
 
 }
+
+void NULLHardwarePixelBuffer::blitFromMemory( const PixelBox &src, const Image::Box &dstBox )
+{
+
+}
+
+void NULLHardwarePixelBuffer::blitToMemory( const Image::Box &srcBox, const PixelBox &dst )
+{
+
+}

File NullHardwarePixelBuffer.h

 
 class NULLHardwarePixelBuffer: public HardwarePixelBuffer
 {
-protected: 
-    /// Internal implementation of lock(), must be overridden in subclasses
-    virtual PixelBox lockImpl(const Image::Box lockBox,  LockOptions options);
-
-    virtual void unlockImpl(void);
-	friend class RenderTexture;
 public:
     /// Should be called by HardwareBufferManager
     NULLHardwarePixelBuffer(size_t mWidth, size_t mHeight, size_t mDepth, PixelFormat mFormat,
             HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
     ~NULLHardwarePixelBuffer();
         
-    virtual RenderTexture *getRenderTarget(size_t slice);
-    void updateRenderTexture(bool writeGamma, uint fsaa, const String& srcName);
+	virtual RenderTexture *getRenderTarget(size_t slice){return mRenderTexture;}
 
-};
+    virtual void blitFromMemory(const PixelBox &src, const Image::Box &dstBox);
+    virtual void blitToMemory(const Image::Box &srcBox, const PixelBox &dst);
+
+protected:
+	vector<int8>::type _data;
+	
+    virtual PixelBox lockImpl(const Image::Box lockBox,  LockOptions options);
+    virtual void unlockImpl(void);
+
+    void _updateRenderTexture( bool enable );
+
+	RenderTexture*	mRenderTexture;
+	friend class RenderTexture;
+};
+
+
+/// RenderTexture implementation for D3D9

File NullTexture.cpp

 
 }
 
-void NULLTexture::loadImage( const Ogre::Image & )
+void NULLTexture::createInternalResourcesImpl( void )
+{
+	if( _pixBuf.isNull() )
+	{
+		unsigned int bufusage;
+		if (mUsage & TU_DYNAMIC )
+		{
+			bufusage = HardwareBuffer::HBU_DYNAMIC;
+		}
+		else
+		{
+			bufusage = HardwareBuffer::HBU_STATIC;
+		}
+		if (mUsage & TU_RENDERTARGET)
+		{
+			bufusage |= TU_RENDERTARGET;
+		}
+
+    	_pixBuf.bind( new NULLHardwarePixelBuffer( mWidth, mHeight, 1, getFormat(), (HardwareBuffer::Usage)bufusage, false, false ) );
+	}
+}
+
+void NULLTexture::freeInternalResourcesImpl( void )
+{
+	_pixBuf.setNull();
+}
+
+NULLRenderTexture::NULLRenderTexture( const String &name, NULLHardwarePixelBuffer* buffer )
+	: RenderTexture(buffer, 0)
+{
+	mName = name;
+}
+
+NULLRenderTexture::~NULLRenderTexture()
 {
 
 }
-
-void NULLTexture::createInternalResources( void )
-{
-	if( _pixBuf.isNull() )
-	{
-    	_pixBuf.bind( new NULLHardwarePixelBuffer( mWidth, mHeight, 1, getFormat(), getUsage(), false, false ) );
-	}
-}
-
-void NULLTexture::freeInternalResources( void )
-{
-	_pixBuf.setNull();
-}

File NullTexture.h

 	~NULLTexture();
 
 	void loadImpl(void);
-	void loadImage (const Ogre::Image &);
 	HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) { return _pixBuf; }
 
-    void createInternalResources(void);
-    void freeInternalResources(void);
+ 
+protected:
 
-private:
+    void createInternalResourcesImpl(void);
+    void freeInternalResourcesImpl(void);
 
 	HardwarePixelBufferSharedPtr	_pixBuf;
 };
-
+
+{
+public:
+    NULLRenderTexture(const String &name, NULLHardwarePixelBuffer* buffer);
+    ~NULLRenderTexture();
+  	bool	requiresTextureFlipping	() const { return false; }
+};
+	
 #endif