void HSWDisplay::LoadGraphics()
{
    // As of this writing, we don't yet have an abstraction for Textures, Buffers, and Shaders like we do for D3D11, D3D11, and OpenGL.
    #if defined(OVR_BUILD_DEBUG)
        if(!pTexture)
            pTexture = *LoadTextureTga(RenderParams, "C:\\TestPath\\TestFile.tga", 255);
    #endif

    if(!pTexture)
    {
        D3DCAPS9 caps;
        RenderParams.Device->GetDeviceCaps(&caps);

        if(caps.TextureCaps & (D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_POW2))
            { HSWDISPLAY_LOG(("[HSWDisplay D3D9] Square textures allowed only.")); }

        size_t textureSize;
        const uint8_t* TextureData = GetDefaultTexture(textureSize);
        pTexture = *LoadTextureTga(RenderParams, TextureData, (int)textureSize, 255);
        OVR_ASSERT(pTexture);
    }

    if(!pVB)
    {
        HRESULT hResult = RenderParams.Device->CreateVertexBuffer(4 * sizeof(HASWVertex), NULL, HASWVertexD3D9Format, D3DPOOL_MANAGED, &pVB.GetRawRef(), NULL);

        if(FAILED(hResult))
            { HSWDISPLAY_LOG(("[HSWDisplay D3D9] CreateVertexBuffer failed. %d (%x)", hResult, hResult)); }
        else
        {
            void* pVerticesVoid;
            hResult = pVB->Lock(0, 0, (void**)&pVerticesVoid, 0);

            if(FAILED(hResult))
                { HSWDISPLAY_LOG(("[HSWDisplay D3D9] Lock failed. %d (%x)", hResult, hResult)); }
            else
            {
                HASWVertex* pVertices = reinterpret_cast<HASWVertex*>(pVerticesVoid);

                const bool  flip   = ((RenderState.DistortionCaps & ovrDistortionCap_FlipInput) != 0);
                const float left   = -1.0f;
                const float top    = -1.1f;
                const float right  = +1.0f;
                const float bottom = +0.9f;

                pVertices[0] = HASWVertex(left,  top,    0.f, Color(255, 255, 255, 255), 0.f, flip ? 1.f : 0.f); // To do: Make this branchless 
                pVertices[1] = HASWVertex(left,  bottom, 0.f, Color(255, 255, 255, 255), 0.f, flip ? 0.f : 1.f);
                pVertices[2] = HASWVertex(right, top,    0.f, Color(255, 255, 255, 255), 1.f, flip ? 1.f : 0.f); 
                pVertices[3] = HASWVertex(right, bottom, 0.f, Color(255, 255, 255, 255), 1.f, flip ? 0.f : 1.f);

                pVB->Unlock();
            }
        }
    }
}
Пример #2
0
GLuint	RTRS::TextureManager::GetTextureByName(const char* pcTextureName, TEXTURETYPE eTextureType)
{
	RTRS::TextureMap* pTextureMap = NULL;

	switch(eTextureType)
	{
	case TEXTURETYPE::COLOR: pTextureMap = m_pColorTextureMap; break;
	case TEXTURETYPE::NORMAL: pTextureMap = m_pNormalTextureMap; break;
	case TEXTURETYPE::BUMP: pTextureMap = m_pBumpTextureMap; break;
	case TEXTURETYPE::SPECULAR: pTextureMap = m_pSpecularTextureMap; break;
	}

	assert(pTextureMap != NULL);

	RTRS::TextureMap::iterator iter = pTextureMap->find(pcTextureName);

	if(iter != pTextureMap->end())
		return iter->second;
	else
	{
		return GetDefaultTexture(eTextureType);
	}
}
Пример #3
0
	void LodTextureManager::loadResource(Ogre::Resource* res)
	{
		int alpha = 0;
		angel::Log << angel::aeLog::debug <<"loading texture " << res->getName() << angel::aeLog::endl;
		
		angel::pLodData ldata = angel::LodManager.LoadFileData( res->getName() );

//		angel::pLodData ldata=angel::LodManager.LoadFile( res->getName() );
		
		if(!ldata)
			return GetDefaultTexture(res);
		angel::pLodData hdr = angel::LodManager.LoadFileHdr( res->getName() );

		BYTE*data= &((*ldata)[0]);
		BYTE*hdrdata= &((*hdr)[0]);
		int size = (int)ldata->size();
		int psize = *(int*)(hdrdata+0x4);
		unsigned int unpsize1 = *(int*)(hdrdata+0x0);
		unsigned long unpsize2 = *(int*)(hdrdata+0x18);

		if( unpsize2+0x300 != size )
		{
			//angel::Log <<"texture " << res->getName() << " error datasize "  << unpsize2 << "/" << size<< angel::aeLog::endl;
			//return GetDefaultTexture(res);
			return loadSprite(res,hdr,ldata);
		}
//		if( unpsize2 && unpsize2 < unpsize1)
//			return GetDefaultTexture(res);
		BYTE* pal = data + unpsize2;
		int width  = *(WORD*)(hdrdata+0x8);
		int height = *(WORD*)(hdrdata+0xa);
		int imgsize = width*height;
		BYTE *pSrc=data;


/*		BYTE*data= &((*ldata)[0]);
		int size = (int)ldata->size();
		int psize = *(int*)(data+0x14);
		unsigned int unpsize1 = *(int*)(data+0x10);
		unsigned long unpsize2 = *(int*)(data+0x28);

		if( psize+0x30+0x300 != size )
			return GetDefaultTexture(res);
		if( unpsize2 && unpsize2 < unpsize1)
			return GetDefaultTexture(res);
		BYTE* pal = data + 0x30 + psize;
		BYTE*unpdata = new BYTE[unpsize2 ];
		boost::scoped_array<BYTE> sunpdata(unpdata);
		if ( uncompress( unpdata, &unpsize2 , data + 0x30, psize ) != Z_OK )
			return;
		int width  = *(WORD*)(data+0x18);
		int height = *(WORD*)(data+0x1a);
		int imgsize = width*height;
		BYTE *pSrc=unpdata;*/

		
		int nummipmaps = 3;
		// Create the texture
		Texture* texture = static_cast<Texture*>(res);
		texture->setTextureType(TEX_TYPE_2D);
		texture->setWidth(width);
		texture->setHeight(height);
		texture->setNumMipmaps(nummipmaps);
		texture->setFormat(PF_BYTE_BGRA);
		texture->setUsage(TU_DEFAULT);
		texture->setDepth(1);
		texture->setHardwareGammaEnabled(false);
		texture->setFSAA(0);
		texture->createInternalResources();

		/*TextureManager::getSingleton().createManual(
		name + ".Texture", // name
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D,      // type
		width, height,         // width & height
		nummipmaps,                // number of mipmaps
		PF_BYTE_BGRA,     // pixel format
		TU_DEFAULT);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
		*/


		// Fill in some pixel data. This will give a semi-transparent blue,
		// but this is of course dependent on the chosen pixel format.
		int w=width;
		int h=height;

		int n=0,off=0; 
		nummipmaps = (int)texture->getNumMipmaps();
		for ( n = 0,off= 0; off < (int)unpsize2 && n <nummipmaps + 1 ;  n++)
		{
			if( w < 1 || h <1 )
				break;
			// Get the pixel buffer
			HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(0,n);

			// Lock the pixel buffer and get a pixel box
			pixelBuffer->lock(HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
			const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

			uint8* pDest = static_cast<uint8*>(pixelBox.data);

			for (int j = 0; j < w; j++)
				for(int i = 0; i < h; i++)
				{
					int index=*pSrc++;
					int r = pal[index*3+0]; 
					int g = pal[index*3+1]; 
					int b = pal[index*3+2]; 
					int a = 0xff;
					if( index == 0 && ((r == 0 && g >250 && b > 250) || (r > 250 && g ==0 && b > 250)))
					{
						alpha=1;
						a= 0;
						r=g=b=0;
					}
					*pDest++ =   b; // G
					*pDest++ =   g; // R
					*pDest++ =   r;
					*pDest++ = a; // A
				}
				pixelBuffer->unlock();


				//off += w*h;
				w/=2;
				h/=2;
		}
		// Unlock the pixel buffer

	}
Пример #4
0
	void LodTextureManager::loadSprite(Ogre::Resource* res, pLodData hdr, pLodData ldata)
	{
		Texture* texture = static_cast<Texture*>(res);
		angel::Log <<"texture " << res->getName() << " error datasize "  << angel::aeLog::endl;
		return GetDefaultTexture(res);
	}
Пример #5
0
	TexturePtr GetLodTexture(const std::string& name)
	{

		std::string texname(name + ".Texture");
		

		if(TextureManager::getSingleton().resourceExists(texname))
			return TextureManager::getSingleton().getByName(texname);
		angel::Log << "loading texture " << name << angel::aeLog::endl;

		int alpha = 0;

		angel::pLodData ldata=angel::LodManager.LoadFile( name );

		if(!ldata)
			return GetDefaultTexture();
		BYTE*data= &((*ldata)[0]);
		int size = (int)ldata->size();
		int psize = *(int*)(data+0x14);
		unsigned int unpsize1 = *(int*)(data+0x10);
		unsigned long unpsize2 = *(int*)(data+0x28);

		if( psize+0x30+0x300 != size )
			return GetDefaultTexture();
		if( unpsize2 && unpsize2 < unpsize1)
			return GetDefaultTexture();
		BYTE* pal = data + 0x30 + psize;
		BYTE*unpdata = new BYTE[unpsize2 ];
		boost::scoped_array<BYTE> sunpdata(unpdata);
		if ( uncompress( unpdata, &unpsize2 , data + 0x30, psize ) != Z_OK )
			return GetDefaultTexture();
		int width  = *(WORD*)(data+0x18);
		int height = *(WORD*)(data+0x1a);
		int imgsize = width*height;
		BYTE *pSrc=unpdata;

        int nummipmaps = 3;
		// Create the texture
		TexturePtr texture = TextureManager::getSingleton().createManual(
			name + ".Texture", // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,      // type
			width, height,         // width & height
			nummipmaps,                // number of mipmaps
			PF_BYTE_BGRA,     // pixel format
			TU_DEFAULT);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for



		// Fill in some pixel data. This will give a semi-transparent blue,
		// but this is of course dependent on the chosen pixel format.
		int w=width;
		int h=height;

		int n=0,off=0; 
		nummipmaps = (int)texture->getNumMipmaps();
		for ( n = 0,off= 0; off < (int)unpsize2 && n <nummipmaps + 1 ;  n++)
		{
			if( w < 1 || h <1 )
				break;
			// Get the pixel buffer
			HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(0,n);

			// Lock the pixel buffer and get a pixel box
			pixelBuffer->lock(HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
			const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

			uint8* pDest = static_cast<uint8*>(pixelBox.data);

			for (int j = 0; j < w; j++)
				for(int i = 0; i < h; i++)
				{
					int index=*pSrc++;
					int r = pal[index*3+0]; 
					int g = pal[index*3+1]; 
					int b = pal[index*3+2]; 
					int a = 0xff;
					if( index == 0 && ((r == 0 && g >250 && b > 250) || (r > 250 && g ==0 && b > 250)))
					{
						alpha=1;
						a= 0;
						r=g=b=0;
					}
					*pDest++ =   b; // G
					*pDest++ =   g; // R
					*pDest++ =   r;
					*pDest++ = a; // A
				}
				pixelBuffer->unlock();
				

				//off += w*h;
				w/=2;
				h/=2;
		}
		// Unlock the pixel buffer
		
		return texture;
	}
void HSWDisplay::LoadGraphics()
{
    // We assume here that the current GL context is the one our resources will be associated with.

    if(GLVersionInfo.MajorVersion == 0)
        GetGLVersionAndExtensions(GLVersionInfo);
    
    if (FrameBuffer == 0)
    {
        glGenFramebuffers(1, &FrameBuffer);
    }

    if (!pTexture) // To do: Add support for .dds files, which would be significantly smaller than the size of the tga.
    {
        size_t textureSize;
        const uint8_t* TextureData = GetDefaultTexture(textureSize);
        pTexture = *LoadTextureTga(RenderParams, Sample_Linear | Sample_Clamp, TextureData, (int)textureSize, 255);
    }

    if (!pShaderSet)
    {
        pShaderSet = *new ShaderSet();
    }

    if(!pVertexShader)
    {
        OVR::String strShader((GLVersionInfo.MajorVersion >= 3) ? glsl3Prefix : glsl2Prefix);
        strShader += SimpleTexturedQuad_vs;

        pVertexShader = *new VertexShader(&RenderParams, const_cast<char*>(strShader.ToCStr()), strShader.GetLength(), SimpleTexturedQuad_vs_refl, OVR_ARRAY_COUNT(SimpleTexturedQuad_vs_refl));
        pShaderSet->SetShader(pVertexShader);
    }

    if(!pFragmentShader)
    {
        OVR::String strShader((GLVersionInfo.MajorVersion >= 3) ? glsl3Prefix : glsl2Prefix);
        strShader += SimpleTexturedQuad_ps;

        pFragmentShader = *new FragmentShader(&RenderParams, const_cast<char*>(strShader.ToCStr()), strShader.GetLength(), SimpleTexturedQuad_ps_refl, OVR_ARRAY_COUNT(SimpleTexturedQuad_ps_refl));
        pShaderSet->SetShader(pFragmentShader);
    }

    if(!pVB)
    {
        pVB = *new Buffer(&RenderParams);

        pVB->Data(Buffer_Vertex, NULL, 4 * sizeof(HASWVertex));
        HASWVertex* pVertices = (HASWVertex*)pVB->Map(0, 4 * sizeof(HASWVertex), Map_Discard);
        OVR_ASSERT(pVertices);

        if(pVertices)
        {
            const bool  flip   = ((RenderState.DistortionCaps & ovrDistortionCap_FlipInput) != 0);
            const float left   = -1.0f; // We currently draw this in normalized device coordinates with an stereo translation
            const float top    = -1.1f; // applied as a vertex shader uniform. In the future when we have a more formal graphics
            const float right  =  1.0f; // API abstraction we may move this draw to an overlay layer or to a more formal 
            const float bottom =  0.9f; // model/mesh scheme with a perspective projection.

            pVertices[0] = HASWVertex(left,  top,    0.f, Color(255, 255, 255, 255), 0.f, flip ? 1.f : 0.f);
            pVertices[1] = HASWVertex(left,  bottom, 0.f, Color(255, 255, 255, 255), 0.f, flip ? 0.f : 1.f);
            pVertices[2] = HASWVertex(right, top,    0.f, Color(255, 255, 255, 255), 1.f, flip ? 1.f : 0.f); 
            pVertices[3] = HASWVertex(right, bottom, 0.f, Color(255, 255, 255, 255), 1.f, flip ? 0.f : 1.f);

            pVB->Unmap(pVertices);
        }
    }

    // We don't generate the vertex arrays here
    if (!VAO && GLVersionInfo.SupportsVAO)
    {
        OVR_ASSERT(!VAOInitialized);
        
        #ifdef OVR_OS_MAC
            if(GLVersionInfo.WholeVersion >= 302)
                glGenVertexArrays(1, &VAO);
            else
                glGenVertexArraysAPPLE(1, &VAO);
        #else
            glGenVertexArrays(1, &VAO);
        #endif
    }
}