void DirectX11Texture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format)
	{
		destroy();

		D3D11_TEXTURE2D_DESC desc;
		desc.ArraySize = 1;
		desc.Width = mWidth = _width;
		desc.Height = mHeight = _height;
		desc.MipLevels = 1;
		desc.SampleDesc.Count = 1;
		desc.SampleDesc.Quality = 0;
		desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
		desc.Usage = D3D11_USAGE_DEFAULT;
		if (_usage == TextureUsage::RenderTarget)
			desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
		else
			desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		desc.CPUAccessFlags = 0;
		desc.MiscFlags = 0;
		HRESULT hr = mManager->mpD3DDevice->CreateTexture2D(&desc, 0, &mTexture);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Create Texture failed!");

		D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
		srvDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
		srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		srvDesc.Texture2D.MipLevels = 1;
		srvDesc.Texture2D.MostDetailedMip = 0;

		hr = mManager->mpD3DDevice->CreateShaderResourceView(mTexture, &srvDesc, &mResourceView);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Create Shader ResourceView failed!");
	}
	Vertex* OpenGLESVertexBuffer::lock()
	{
		MYGUI_PLATFORM_ASSERT(mBufferID, "Vertex buffer in not created");

		// Use glMapBuffer
		//glBindBufferARB(GL_ARRAY_BUFFER_ARB, mBufferID);
        glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
        //CHECK_GL_ERROR_DEBUG();
        
        GLenum __error = glGetError();
        if(__error)
        {
            MYGUI_PLATFORM_LOG(Info, "OpenGL error " << __error << " in " << __FILE__<< " " << __FUNCTION__<< " "<< __LINE__);
        }
        assert(__error==0);

		// Discard the buffer
		//glBufferDataARB(GL_ARRAY_BUFFER_ARB, mSizeInBytes, 0, GL_STREAM_DRAW_ARB);
        glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, 0, GL_STREAM_DRAW);
        CHECK_GL_ERROR_DEBUG();


		Vertex* pBuffer = (Vertex*)glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
        CHECK_GL_ERROR_DEBUG();

		MYGUI_PLATFORM_ASSERT(pBuffer, "Error lock vertex buffer");

		glBindBuffer(GL_ARRAY_BUFFER, 0);
        CHECK_GL_ERROR_DEBUG();

		return pBuffer;
	}
	void OpenGLVertexBuffer::unlock()
	{
		MYGUI_PLATFORM_ASSERT(mBufferID, "Vertex buffer in not created");

		glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
		GLboolean result = glUnmapBuffer(GL_ARRAY_BUFFER);
		glBindBuffer(GL_ARRAY_BUFFER, 0);

		MYGUI_PLATFORM_ASSERT(result, "Error unlock vertex buffer");
	}
	void Cocos2dRenderManager::initialise()
	{
		CCDirector *pDirector = CCDirector::sharedDirector();
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		CCSize s = pDirector->getWinSizeInPixels();

		this->setPosition(0, 0);
		this->setContentSize(s);
		setViewSize(int(s.width), int(s.height));

		// 绑定到cocos2d节点
		pDirector->setNotificationNode(this);

		mInfo.pixWidth = s.width;
		mInfo.pixHeight = s.height;

		mVertexFormat = VertexColourType::ColourABGR;

		mUpdate = true;

		kmMat4 tmp;
		kmGLGetMatrix(KM_GL_PROJECTION, &tmp);
		kmMat4Inverse(&mMatrix, &tmp);

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;

		CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
			callfuncO_selector(Cocos2dRenderManager::listenForeToBackground),
			EVENT_COME_TO_BACKGROUND,
			NULL);
		pDirector->getScheduler()->scheduleUpdateForTarget(this, kCCPriorityNonSystemMin, false);
	}
	void DirectXRenderManager::initialise(IDirect3DDevice9* _device)
	{
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		mpD3DDevice = _device;

		mVertexFormat = VertexColourType::ColourARGB;

		memset(&mInfo, 0, sizeof(mInfo));
		if (mpD3DDevice != nullptr)
		{
			D3DVIEWPORT9 vp;
			mpD3DDevice->GetViewport(&vp);
			setViewSize(vp.Width, vp.Height);
		}

		mUpdate = false;

		if (mpD3DDevice != nullptr)
		{
			D3DCAPS9 caps;
			mpD3DDevice->GetDeviceCaps(&caps);
			if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
			{
				MYGUI_PLATFORM_LOG(Warning, "Non-squared textures not supported.");
			}
		}

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;
	}
	DirectX11RTTexture::DirectX11RTTexture( DirectX11Texture* _texture, DirectX11RenderManager* _manager ) :
		mOldDepthStencil(nullptr),
		mOldRenderTarget(nullptr),
		mTexture(_texture),
		mManager(_manager),
		mRenderTarget(nullptr)
	{
		int width = mTexture->getWidth();
		int height = mTexture->getHeight();

		mRenderTargetInfo.maximumDepth = 0.0f;
		mRenderTargetInfo.hOffset = 0.0f;
		mRenderTargetInfo.vOffset = 0.0f;
		mRenderTargetInfo.aspectCoef = float(height) / float(width);
		mRenderTargetInfo.pixScaleX = 1.0f / float(width);
		mRenderTargetInfo.pixScaleY = 1.0f / float(height);

		D3D11_RENDER_TARGET_VIEW_DESC desc;
		desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
		desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
		desc.Texture2D.MipSlice = 0;

		HRESULT hr = mManager->mpD3DDevice->CreateRenderTargetView(mTexture->mTexture, 0, &mRenderTarget);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Create Render Target View failed!");
	}
	void OpenGLESVertexBuffer::create()
	{
		MYGUI_PLATFORM_ASSERT(!mBufferID, "Vertex buffer already exist");

		mSizeInBytes = mNeedVertexCount * sizeof(MyGUI::Vertex);
		void* data = 0;

		glGenBuffers(1, (GLuint*)&mBufferID); //wdy
        CHECK_GL_ERROR_DEBUG();
		glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
        CHECK_GL_ERROR_DEBUG();
		glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, data, GL_STREAM_DRAW);
        CHECK_GL_ERROR_DEBUG();
        
        //MYGUI_LOG(Info, mBufferID);
		

		// check data size in VBO is same as input array, if not return 0 and delete VBO
		int bufferSize = 0;
		glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, (GLint*)&bufferSize); //wdy
        CHECK_GL_ERROR_DEBUG();
		if (mSizeInBytes != (size_t)bufferSize)
		{
			destroy();
			MYGUI_PLATFORM_EXCEPT("Data size is mismatch with input array");
		}

		glBindBuffer(GL_ARRAY_BUFFER, 0);
        CHECK_GL_ERROR_DEBUG();
	}
	void OpenGLTexture::unlock()
	{
		if (!mLock && mBuffer)
		{
			delete mBuffer;
			mBuffer = 0;

			glBindTexture(GL_TEXTURE_2D, 0);

			return;
		}

		MYGUI_PLATFORM_ASSERT(mLock, "Texture is not locked");

		// release the mapped buffer
		glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);

		// copy pixels from PBO to texture object
		// Use offset instead of ponter.
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mWidth, mHeight, mPixelFormat, GL_UNSIGNED_BYTE, 0);

		// it is good idea to release PBOs with ID 0 after use.
		// Once bound with 0, all pixel operations are back to normal ways.
		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

		glBindTexture(GL_TEXTURE_2D, 0);

		mBuffer = 0;
		mLock = false;
	}
Example #9
0
    void initialise(Ogre::RenderWindow* _window, Ogre::SceneManager* _scene)
    {
        MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
        MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

        mColorBlendMode.blendType = Ogre::LBT_COLOUR;
        mColorBlendMode.source1 = Ogre::LBS_TEXTURE;
        mColorBlendMode.source2 = Ogre::LBS_DIFFUSE;
        mColorBlendMode.operation = Ogre::LBX_MODULATE;

        mAlphaBlendMode.blendType = Ogre::LBT_ALPHA;
        mAlphaBlendMode.source1 = Ogre::LBS_TEXTURE;
        mAlphaBlendMode.source2 = Ogre::LBS_DIFFUSE;
        mAlphaBlendMode.operation = Ogre::LBX_MODULATE;

        mTextureAddressMode.u = Ogre::TextureUnitState::TAM_CLAMP;
        mTextureAddressMode.v = Ogre::TextureUnitState::TAM_CLAMP;
        mTextureAddressMode.w = Ogre::TextureUnitState::TAM_CLAMP;

        mSceneManager = nullptr;
        mWindow = nullptr;
        mUpdate = false;
        mRenderSystem = nullptr;
        mActiveViewport = 0;

        Ogre::Root* root = Ogre::Root::getSingletonPtr();
        if (root != nullptr)
            setRenderSystem(root->getRenderSystem());
        setRenderWindow(_window);
        setSceneManager(_scene);


        MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
        mIsInitialise = true;
    }
	void DirectX11DataManager::initialise()
	{
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;
	}
	void DirectX11DataManager::shutdown()
	{
		MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
		MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
		mIsInitialise = false;
	}
Example #12
0
    void initialise(Ogre::RenderWindow* _window, Ogre::SceneManager* _scene)
    {
        MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
        MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

        mColorBlendMode.blendType = Ogre::LBT_COLOUR;
        mColorBlendMode.source1 = Ogre::LBS_TEXTURE;
        mColorBlendMode.source2 = Ogre::LBS_DIFFUSE;
        mColorBlendMode.operation = Ogre::LBX_MODULATE;

        mAlphaBlendMode.blendType = Ogre::LBT_ALPHA;
        mAlphaBlendMode.source1 = Ogre::LBS_TEXTURE;
        mAlphaBlendMode.source2 = Ogre::LBS_DIFFUSE;
        mAlphaBlendMode.operation = Ogre::LBX_MODULATE;

        mTextureAddressMode.u = Ogre::TextureUnitState::TAM_CLAMP;
        mTextureAddressMode.v = Ogre::TextureUnitState::TAM_CLAMP;
        mTextureAddressMode.w = Ogre::TextureUnitState::TAM_CLAMP;

        mSceneManager = nullptr;
        mWindow = nullptr;
        mUpdate = false;
        mRenderSystem = nullptr;
        mActiveViewport = 0;

        Ogre::Root* root = Ogre::Root::getSingletonPtr();
        if (root != nullptr)
            setRenderSystem(root->getRenderSystem());
        setRenderWindow(_window);
        setSceneManager(_scene);

        // ADDED
        sh::MaterialInstance* mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/NoTexture");
        sh::Factory::getInstance()._ensureMaterial("MyGUI/NoTexture", "Default");
        mVertexProgramNoTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
                                  ->getVertexProgram()->_getBindingDelegate();

        mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/OneTexture");
        sh::Factory::getInstance()._ensureMaterial("MyGUI/OneTexture", "Default");
        mVertexProgramOneTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
                                   ->getVertexProgram()->_getBindingDelegate();

        mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/NoTexture");
        sh::Factory::getInstance()._ensureMaterial("MyGUI/NoTexture", "Default");
        mFragmentProgramNoTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
                                    ->getFragmentProgram()->_getBindingDelegate();

        mat = sh::Factory::getInstance().getMaterialInstance("MyGUI/OneTexture");
        sh::Factory::getInstance()._ensureMaterial("MyGUI/OneTexture", "Default");
        mFragmentProgramOneTexture = static_cast<sh::OgreMaterial*>(mat->getMaterial())->getOgreTechniqueForConfiguration("Default")->getPass(0)
                                     ->getFragmentProgram()->_getBindingDelegate();



        MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
        mIsInitialise = true;
    }
Example #13
0
    ITexture* createTexture(const std::string& _name)
    {
        MapTexture::const_iterator item = mTextures.find(_name);
        MYGUI_PLATFORM_ASSERT(item == mTextures.end(), "Texture '" << _name << "' already exist");

        OgreTexture* texture = new OgreTexture(_name, OgreDataManager::getInstance().getGroup());
        mTextures[_name] = texture;
        return texture;
    }
	ITexture* OpenGLRenderManager::createTexture(const std::string& _name)
	{
		MapTexture::const_iterator item = mTextures.find(_name);
		MYGUI_PLATFORM_ASSERT(item == mTextures.end(), "Texture '" << _name << "' already exist");

		OpenGLTexture* texture = new OpenGLTexture(_name, mImageLoader);
		mTextures[_name] = texture;
		return texture;
	}
	ITexture* DirectXRenderManager::createTexture(const std::string& _name)
	{
		MapTexture::const_iterator item = mTextures.find(_name);
		MYGUI_PLATFORM_ASSERT(item == mTextures.end(), "Texture '" << _name << "' already exist");

		DirectXTexture* texture = new DirectXTexture(_name, mpD3DDevice);
		mTextures[_name] = texture;
		return texture;
	}
Example #16
0
    void destroyTexture(ITexture* _texture)
    {
        if (_texture == nullptr) return;

        MapTexture::iterator item = mTextures.find(_texture->getName());
        MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '" << _texture->getName() << "' not found");

        mTextures.erase(item);
        delete _texture;
    }
	void OpenGLRenderManager::shutdown()
	{
		MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
		MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());

		destroyAllResources();

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
		mIsInitialise = false;
	}
	Vertex* OpenGLVertexBuffer::lock()
	{
		MYGUI_PLATFORM_ASSERT(mBufferID, "Vertex buffer in not created");

		// Use glMapBuffer
		glBindBuffer(GL_ARRAY_BUFFER, mBufferID);

		// Discard the buffer
		glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, 0, GL_STREAM_DRAW);


		Vertex* pBuffer = reinterpret_cast<Vertex*>(glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY));

		MYGUI_PLATFORM_ASSERT(pBuffer, "Error lock vertex buffer");

		glBindBuffer(GL_ARRAY_BUFFER, 0);

		return pBuffer;
	}
	void DirectX11Texture::loadFromFile(const std::string& _filename)
	{
		destroy();

		std::string fullname = DirectX11DataManager::getInstance().getDataPath(_filename);


		D3DX11_IMAGE_INFO fileInfo;
		D3DX11GetImageInfoFromFile( fullname.c_str(), NULL, &fileInfo, NULL );

		mWidth = fileInfo.Width;
		mHeight = fileInfo.Height;

		D3DX11_IMAGE_LOAD_INFO loadInfo;
		loadInfo.Width          = fileInfo.Width;
		loadInfo.Height         = fileInfo.Height;
		loadInfo.FirstMipLevel  = 0;
		loadInfo.MipLevels      = fileInfo.MipLevels;
		loadInfo.Usage          = D3D11_USAGE_DEFAULT;
		loadInfo.BindFlags      = D3D11_BIND_SHADER_RESOURCE;
		loadInfo.CpuAccessFlags = 0;
		loadInfo.MiscFlags      = 0;
		loadInfo.Format         = fileInfo.Format;
		loadInfo.Filter         = D3DX11_FILTER_NONE;
		loadInfo.MipFilter      = D3DX11_FILTER_NONE;
		loadInfo.pSrcInfo       = &fileInfo;

		HRESULT hr = D3DX11CreateTextureFromFileA( mManager->mpD3DDevice, fullname.c_str(), &loadInfo, NULL, (ID3D11Resource**)&mTexture, NULL );
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "CreateTextureFromFile failed!");

		D3D11_TEXTURE2D_DESC desc;
		mTexture->GetDesc(&desc);

		D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
		srvDesc.Format = desc.Format;
		srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		srvDesc.Texture2D.MipLevels = 1;
		srvDesc.Texture2D.MostDetailedMip = 0;

		hr = mManager->mpD3DDevice->CreateShaderResourceView(mTexture, &srvDesc, &mResourceView);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Create Shader ResourceView failed!");
	}
	bool DirectX11VertexBuffer::create()
	{
		D3D11_BUFFER_DESC desc;
		desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		desc.MiscFlags = 0;
		desc.StructureByteStride = 0;
		desc.ByteWidth = sizeof(Vertex) * (mNeedVertexCount);
		desc.Usage = D3D11_USAGE_DYNAMIC;
		HRESULT hr = mManager->mpD3DDevice->CreateBuffer(&desc, 0, &mBuffer);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Create Buffer failed!");
		return hr == S_OK ? true : false;
	}
Example #21
0
	void* OpenGLTexture::lock(TextureUsage _access)
	{
		MYGUI_PLATFORM_ASSERT(mTextureID, "Texture is not created");

		if (_access == TextureUsage::Read)
		{
			glBindTexture(GL_TEXTURE_2D, mTextureID);

			mBuffer = new unsigned char[mDataSize];
			glGetTexImage(GL_TEXTURE_2D, 0, mPixelFormat, GL_UNSIGNED_BYTE, mBuffer);

			mLock = false;

			return mBuffer;
		}

		// bind the texture
		glBindTexture(GL_TEXTURE_2D, mTextureID);
		if (!OpenGLRenderManager::getInstance().isPixelBufferObjectSupported())
		{
			//Fallback if PBO's are not supported
			mBuffer = new unsigned char[mDataSize];
		}
		else
		{
			// bind the PBO
			glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID);
			
			// Note that glMapBufferARB() causes sync issue.
			// If GPU is working with this buffer, glMapBufferARB() will wait(stall)
			// until GPU to finish its job. To avoid waiting (idle), you can call
			// first glBufferDataARB() with NULL pointer before glMapBufferARB().
			// If you do that, the previous data in PBO will be discarded and
			// glMapBufferARB() returns a new allocated pointer immediately
			// even if GPU is still working with the previous data.
			glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage);

			// map the buffer object into client's memory
			mBuffer = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mAccess);
			if (!mBuffer)
			{
				glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
				glBindTexture(GL_TEXTURE_2D, 0);
				MYGUI_PLATFORM_EXCEPT("Error texture lock");
			}
		}

		mLock = true;

		return mBuffer;
	}
Example #22
0
	void Ogre2DataManager::initialise(const std::string& _group)
	{
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		mGroup = _group;
		if (mGroup == Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME)
			mAllGroups = true;
		else
			mAllGroups = false;

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;
	}
Example #23
0
    void shutdown()
    {
        MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
        MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());

        destroyAllResources();

        setSceneManager(nullptr);
        setRenderWindow(nullptr);
        setRenderSystem(nullptr);

        MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
        mIsInitialise = false;
    }
	void OpenGLRenderManager::initialise(OpenGLImageLoader* _loader)
	{
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		mVertexFormat = VertexColourType::ColourABGR;

		mUpdate = false;
		mImageLoader = _loader;

		glewInit();

		mPboIsSupported = glewIsExtensionSupported("GL_EXT_pixel_buffer_object") != 0;

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;
	}
	void Cocos2dRenderManager::shutdown()
	{
		MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
		MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());

		CCDirector *pDirector = CCDirector::sharedDirector();
		pDirector->getScheduler()->unscheduleUpdateForTarget(this);

		// 注意  (maybe)CCNotificationCenter的生命周期在mainloop结束之前就结束了
		CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVENT_COME_TO_BACKGROUND);


		// 解除与cocos2d节点的绑定
		pDirector->setNotificationNode(NULL);

		destroyAllResources();

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
		mIsInitialise = false;
	}
	void DirectX11RenderManager::shutdown()
	{
		MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
		MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName());

		destroyAllResources();

		if ( mVertexShader0 ) mVertexShader0->Release();
		if ( mVertexShader1 ) mVertexShader1->Release();
		if ( mPixelShader0 ) mPixelShader0->Release();
		if ( mPixelShader1 ) mPixelShader1->Release();
		if ( mSamplerState ) mSamplerState->Release();
		if ( mBlendState ) mBlendState->Release();
		if ( mDepthStencilState ) mDepthStencilState->Release();
		if ( mRasterizerState ) mRasterizerState->Release();
		if ( mInputLayout0 ) mInputLayout0->Release();
		if ( mInputLayout1 ) mInputLayout1->Release();

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown");
		mIsInitialise = false;
	}
	void OpenGLRenderManager::doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count)
	{
		OpenGLVertexBuffer* buffer = static_cast<OpenGLVertexBuffer*>(_buffer);
		unsigned int buffer_id = buffer->getBufferID();
		MYGUI_PLATFORM_ASSERT(buffer_id, "Vertex buffer is not created");

		unsigned int texture_id = 0;
		if (_texture)
		{
			OpenGLTexture* texture = static_cast<OpenGLTexture*>(_texture);
			texture_id = texture->getTextureID();
			//MYGUI_PLATFORM_ASSERT(texture_id, "Texture is not created");
		}

		glBindTexture(GL_TEXTURE_2D, texture_id);

		glBindBuffer(GL_ARRAY_BUFFER, buffer_id);

		// enable vertex arrays
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);

		// before draw, specify vertex and index arrays with their offsets
		size_t offset = 0;
		glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void*)offset);
		offset += (sizeof(float) * 3);
		glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)offset);
		offset += (4);
		glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (void*)offset);

		glDrawArrays(GL_TRIANGLES, 0, _count);

		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_COLOR_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindTexture(GL_TEXTURE_2D, 0);
	}
	void DirectXRenderManager::initialise(IDirect3DDevice9 *_device)
	{
		MYGUI_PLATFORM_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);

		mpD3DDevice = _device;

		mVertexFormat = VertexColourType::ColourARGB;  

		memset(&mInfo, 0, sizeof(mInfo));
		if (mpD3DDevice != nullptr)
		{
			D3DVIEWPORT9 vp;
			mpD3DDevice->GetViewport(&vp);
			setViewSize(vp.Width, vp.Height);
		}

		mUpdate = false;

		MYGUI_PLATFORM_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
		mIsInitialise = true;
	}
	void DirectX11RenderManager::initialise(ID3D11Device* _device)
	{
		MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
		MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName());

		mpD3DDevice = _device;
		_device->GetImmediateContext(&mpD3DContext);

		mVertexFormat = VertexColourType::ColourABGR;

		std::string vertexProfile, pixelProfile;
		if ( mpD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_11_0 )
		{
			vertexProfile = "vs_5_0";
			pixelProfile = "ps_5_0";
		}
		else if ( mpD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_10_1 )
		{
			vertexProfile = "vs_4_1";
			pixelProfile = "ps_4_1";
		}
		else if ( mpD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_10_0 )
		{
			vertexProfile = "vs_4_0";
			pixelProfile = "ps_4_0";
		}
		else if ( mpD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_9_3 )
		{
			vertexProfile = "vs_4_0_level_9_3";
			pixelProfile = "ps_4_0_level_9_3";
		}
		else if ( mpD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_9_2 )
		{
			vertexProfile = "vs_4_0_level_9_1";
			pixelProfile = "ps_4_0_level_9_1";
		}
		else if ( mpD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_9_1 )
		{
			vertexProfile = "vs_4_0_level_9_1";
			pixelProfile = "ps_4_0_level_9_1";
		}

		// Get Current viewports
		memset(&mInfo, 0, sizeof(mInfo));
		UINT numViewports = 0;
		D3D11_VIEWPORT viewports[8];

		mpD3DContext->RSGetViewports(&numViewports, viewports);
		MYGUI_PLATFORM_ASSERT(numViewports == 0, getClassTypeName() << " 0 viewport sets");

		setViewSize((int)viewports[0].Width, (int)viewports[0].Height);

		UINT flags = (1 << 11) | (1 << 15);

		// Build Flat Vertex Shader
		ID3DBlob* bytecode = 0, *errors = 0, *signature0 = 0, *signature1 = 0;
		HRESULT hr = D3DCompile(vsSource, strlen(vsSource), "VertexShader0", 0, 0, "main", vertexProfile.c_str(), flags, 0, &bytecode, &errors);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Compilation failed, unknown errors!"));

		hr = D3DGetInputSignatureBlob(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), &signature0);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Compilation failed, failed to get input signature!"));

		hr = mpD3DDevice->CreateVertexShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), 0, &mVertexShader0);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Create failed!"));

		if ( bytecode ) bytecode->Release();
		if ( errors ) errors->Release();


		// Build Textured Vertex Shader
		bytecode = 0;
		errors = 0;
		hr = D3DCompile(vsTexturedSource, strlen(vsTexturedSource), "VertexShader1", 0, 0, "main", vertexProfile.c_str(), flags, 0, &bytecode, &errors);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Compilation failed, unknown errors!"));

		hr = D3DGetInputSignatureBlob(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), &signature1);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Compilation failed, failed to get input signature!"));

		hr = mpD3DDevice->CreateVertexShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), 0, &mVertexShader1);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Create failed!"));

		if ( bytecode ) bytecode->Release();
		if ( errors ) errors->Release();

		// Build Flat Pixel Shader
		bytecode = 0;
		errors = 0;
		hr = D3DCompile(psSource, strlen(psSource), "PixelShader0", 0, 0, "main", pixelProfile.c_str(), flags, 0, &bytecode, &errors);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Compilation failed, unknown errors!"));

		hr = mpD3DDevice->CreatePixelShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), 0, &mPixelShader0);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Create failed!"));

		if ( bytecode ) bytecode->Release();
		if ( errors ) errors->Release();


		// Build Textured Pixel Shader
		bytecode = 0;
		errors = 0;
		hr = D3DCompile(psTexturedSource, strlen(psTexturedSource), "PixelShader1", 0, 0, "main", pixelProfile.c_str(), flags, 0, &bytecode, &errors);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Compilation failed, unknown errors!"));

		hr = mpD3DDevice->CreatePixelShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), 0, &mPixelShader1);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, (errors ? (char*)errors->GetBufferPointer() : "Vertex Shader Create failed!"));

		if ( bytecode ) bytecode->Release();
		if ( errors ) errors->Release();

		// Create Sampler State
		D3D11_SAMPLER_DESC samplerDesc;
		samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
		samplerDesc.BorderColor[0] = samplerDesc.BorderColor[1] = samplerDesc.BorderColor[2] = samplerDesc.BorderColor[3] = 0.0f;
		samplerDesc.ComparisonFunc = (D3D11_COMPARISON_FUNC)0;
		samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
		samplerDesc.MaxAnisotropy = 1;
		samplerDesc.MaxLOD = 0;
		samplerDesc.MinLOD = 0;
		samplerDesc.MipLODBias = 0.0f;
		hr = mpD3DDevice->CreateSamplerState(&samplerDesc, &mSamplerState);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Sampler State Create failed!");

		// Create Blend State
		D3D11_BLEND_DESC blendDesc;
		blendDesc.AlphaToCoverageEnable = false;
		blendDesc.IndependentBlendEnable = false;
		blendDesc.RenderTarget[0].BlendEnable = true;
		blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
		blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
		blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
		blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
		blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
		blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
		blendDesc.RenderTarget[0].RenderTargetWriteMask = 0x0f;
		hr = mpD3DDevice->CreateBlendState(&blendDesc, &mBlendState);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Blend State Create failed!");

		// Create Depth Stencil State
		D3D11_DEPTH_STENCIL_DESC depthDesc;
		depthDesc.DepthEnable = false;
		depthDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
		depthDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
		depthDesc.StencilEnable = false;
		depthDesc.StencilReadMask = depthDesc.StencilWriteMask = 0;
		depthDesc.BackFace.StencilDepthFailOp = depthDesc.BackFace.StencilFailOp = depthDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
		depthDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
		depthDesc.FrontFace = depthDesc.BackFace;
		hr = mpD3DDevice->CreateDepthStencilState(&depthDesc, &mDepthStencilState);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Depth Stencil State Create failed!");

		// Create Rasterizer State
		D3D11_RASTERIZER_DESC rastDesc;
		rastDesc.FillMode              = D3D11_FILL_SOLID;
		rastDesc.CullMode              = D3D11_CULL_NONE;
		rastDesc.FrontCounterClockwise = FALSE;
		rastDesc.DepthBias             = 0;
		rastDesc.DepthBiasClamp        = 0;
		rastDesc.SlopeScaledDepthBias  = 0;
		rastDesc.ScissorEnable         = FALSE;
		rastDesc.MultisampleEnable     = FALSE;
		rastDesc.AntialiasedLineEnable = FALSE;
		hr = mpD3DDevice->CreateRasterizerState(&rastDesc, &mRasterizerState);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Rasterizer State Create failed!");

		// Create Input Layout
		hr = mpD3DDevice->CreateInputLayout(vertexLayout, 3, signature0->GetBufferPointer(), signature0->GetBufferSize(), &mInputLayout0);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Input Layout Create failed!");

		signature0->Release();

		// Create Input Layout
		hr = mpD3DDevice->CreateInputLayout(vertexLayout, 3, signature1->GetBufferPointer(), signature1->GetBufferSize(), &mInputLayout1);
		MYGUI_PLATFORM_ASSERT(hr == S_OK, "Input Layout Create failed!");

		signature1->Release();

		mUpdate = false;

		MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
		mIsInitialise = true;
	}
	void OpenGLTexture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format, void* _data)
	{
		MYGUI_PLATFORM_ASSERT(!mTextureID, "Texture already exist");

		//FIXME перенести в метод
		mInternalPixelFormat = 0;
		mPixelFormat = 0;
		mNumElemBytes = 0;
		if (_format == PixelFormat::L8)
		{
			mInternalPixelFormat = GL_LUMINANCE8;
			mPixelFormat = GL_LUMINANCE;
			mNumElemBytes = 1;
		}
		else if (_format == PixelFormat::L8A8)
		{
			mInternalPixelFormat = GL_LUMINANCE8_ALPHA8;
			mPixelFormat = GL_LUMINANCE_ALPHA;
			mNumElemBytes = 2;
		}
		else if (_format == PixelFormat::R8G8B8)
		{
			mInternalPixelFormat = GL_RGB8;
			mPixelFormat = GL_BGR;
			mNumElemBytes = 3;
		}
		else if (_format == PixelFormat::R8G8B8A8)
		{
			mInternalPixelFormat = GL_RGBA8;
			mPixelFormat = GL_BGRA;
			mNumElemBytes = 4;
		}
		else
		{
			MYGUI_PLATFORM_EXCEPT("format not support");
		}

		mWidth = _width;
		mHeight = _height;
		mDataSize = _width * _height * mNumElemBytes;
		setUsage(_usage);
		//MYGUI_PLATFORM_ASSERT(mUsage, "usage format not support");

		mOriginalFormat = _format;
		mOriginalUsage = _usage;

		// Set unpack alignment to one byte
		int alignment = 0;
		glGetIntegerv( GL_UNPACK_ALIGNMENT, &alignment );
		glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

		// создаем тукстуру
		glGenTextures(1, &mTextureID);
		glBindTexture(GL_TEXTURE_2D, mTextureID);
		// Set texture parameters
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexImage2D(GL_TEXTURE_2D, 0, mInternalPixelFormat, mWidth, mHeight, 0, mPixelFormat, GL_UNSIGNED_BYTE, (GLvoid*)_data);
		glBindTexture(GL_TEXTURE_2D, 0);

		// Restore old unpack alignment
		glPixelStorei( GL_UNPACK_ALIGNMENT, alignment );

		if (!_data)
		{
			//создаем текстурнный буфер
			glGenBuffersARB(1, &mPboID);
			glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID);
			glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage);
			glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
		}
	}