Example #1
0
__attribute__((visibility("default"))) ovrTextureSwapChain *vrapi_CreateTextureSwapChain(
    ovrTextureType type, ovrTextureFormat format, int width, int height, int levels, bool buffered)
{
  if(vrapi_hooks.vrapi_CreateTextureSwapChain_real == NULL ||
     vrapi_hooks.vrapi_GetTextureSwapChainHandle_real == NULL ||
     vrapi_hooks.vrapi_GetTextureSwapChainLength_real == NULL)
  {
    vrapi_hooks.SetupHooks();
  }

  ovrTextureSwapChain *texture_swapchain =
      vrapi_hooks.vrapi_CreateTextureSwapChain_real(type, format, width, height, levels, buffered);

  if(m_GLDriver)
  {
    int tex_count = vrapi_hooks.vrapi_GetTextureSwapChainLength_real(texture_swapchain);

    SCOPED_LOCK(glLock);

    for(int i = 0; i < tex_count; ++i)
    {
      GLuint tex = vrapi_hooks.vrapi_GetTextureSwapChainHandle_real(texture_swapchain, i);
      GLenum internalformat = GetInternalFormat(format);
      GLenum textureType = GetTextureType(type);

      gl_CurChunk = GLChunk::vrapi_CreateTextureSwapChain;
      m_GLDriver->CreateVRAPITextureSwapChain(tex, textureType, internalformat, width, height,
                                              levels);
    }
  }

  return texture_swapchain;
}
Example #2
0
	//------------------------------------------------------------------------------------
	void D3D11Texture::CreateDSV()
	{
		_AST(GetTextureType() == eTextureType_2D);

		D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
		ZeroMemory( &descDSV, sizeof(descDSV) );
		descDSV.Format = DXGI_FORMAT_D32_FLOAT;
		descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
		descDSV.Flags = 0;
		descDSV.Texture2D.MipSlice=0;

		HRESULT hr = S_OK;
		V(g_pRenderSys->GetDevice()->CreateDepthStencilView(m_pTexture2D, &descDSV, &m_pDSV));
	}
Example #3
0
void CheckStar(_lp_vertex star, int idx)
{
    if (idx < _num_stars)
    {
        star->z++;
        if (star->z > nearest)
        {
            star->x = (rand() % Width) - (Width / 2);
            star->y = (rand() % Height) - (Height / 2);
            star->z = (rand() % nearest);

            star->tex_type = -1;    //set to not have texture by default
            star->id = -1;

            int sidx = (rand() % GetTextureCount());
            if (GetTextureCount() == 1)
                sidx = 0;
            star->tex_type = GetTextureType(sidx);
            star->id = GetTextureID(sidx);
        }
    }
}
Example #4
0
	//--------------------------------------------------------------------------
	D3D11Texture::D3D11Texture(const STRING& filename, eTextureType type, uint32 usage, bool bSRGB)
		: Texture(type, 0, 0, 0, ePF_Unknown, usage, true)
		, m_pTexture2D(nullptr)
		, m_pTexture3D(nullptr)
		, m_pRTV(nullptr)
		, m_pSRV(nullptr)
		, m_pDSV(nullptr)
		, m_pTexStaging(nullptr)
	{
		////////////////////////////////////////////////////////////////
		////////////// Load texture
		HRESULT hr = S_OK;
		D3DX11_IMAGE_LOAD_INFO loadInfo;
		loadInfo.MipLevels = 0;
		loadInfo.BindFlags = 0;
		loadInfo.Format = DXGI_FORMAT_FROM_FILE;
		ID3D11Resource** pTex = nullptr;

		switch (GetTextureType())
		{
		case eTextureType_2D:
			{
				pTex = (ID3D11Resource**)&m_pTexture2D;

				if (usage & eTextureUsage_ReadWrite)
				{
					loadInfo.Usage = D3D11_USAGE_STAGING;
					loadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
				}
			}
			break;

		case eTextureType_CubeMap:
			{
				loadInfo.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
				pTex = (ID3D11Resource**)&m_pTexture2D;
			}
			break;

		case eTextureType_3D:
			{
				pTex = (ID3D11Resource**)&m_pTexture3D;
			}
			break;

		default: _AST(0);
		}

		if (filename.find(".dds") != STRING::npos)
		{
			if (usage & eTextureUsage_ReadWrite)
			{
				V(DirectX::CreateDDSTextureFromFileEx(g_pRenderSys->GetDevice(), EngineToUnicode(filename).c_str(),
					4096, D3D11_USAGE_STAGING, 0, D3D11_CPU_ACCESS_READ, 0, bSRGB, pTex, nullptr));
			} 
			else
			{
				V(DirectX::CreateDDSTextureFromFileEx(g_pRenderSys->GetDevice(), EngineToUnicode(filename).c_str(),
					4096, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, bSRGB, pTex, &m_pSRV));
			}
		} 
		else
		{
			V(D3DX11CreateTextureFromFileA(g_pRenderSys->GetDevice(), filename.c_str(), &loadInfo, nullptr, pTex, nullptr));

			if (!(usage & eTextureUsage_ReadWrite))
			{
				CreateSRV();
			}
		}

		// Store texture dimension and format
		switch (GetTextureType())
		{
		case eTextureType_2D:
		case eTextureType_CubeMap:
			{
				D3D11_TEXTURE2D_DESC desc;
				m_pTexture2D->GetDesc(&desc);

				m_width = desc.Width;
				m_height = desc.Height;

				m_texFormat = ConvertFromDXFormat(desc.Format);
			}
			break;

		case eTextureType_3D:
			{
				D3D11_TEXTURE3D_DESC desc;
				m_pTexture3D->GetDesc(&desc);

				m_width = desc.Width;
				m_height = desc.Height;

				m_texFormat = ConvertFromDXFormat(desc.Format);
			}
			break;

		default: _AST(0);
		}
	}
Example #5
0
	//-------------------------------------------------------------------------------
	void D3D11Texture::CreateSRV()
	{
		SAFE_RELEASE(m_pSRV);

		HRESULT hr = S_OK;
		ID3D11Resource** pTex = nullptr;
		D3D11_SHADER_RESOURCE_VIEW_DESC SMViewDesc;
		ZeroMemory(&SMViewDesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));

		// Specifical for depth texture
		if (m_usage & eTextureUsage_Depth)
		{
			_AST(GetTextureType() == eTextureType_2D);

			SMViewDesc.Format					= DXGI_FORMAT_R32_FLOAT;
			SMViewDesc.ViewDimension             = D3D11_SRV_DIMENSION_TEXTURE2D;
			SMViewDesc.Texture2D.MipLevels       = 1;
			SMViewDesc.Texture2D.MostDetailedMip = 0;

			V(g_pRenderSys->GetDevice()->CreateShaderResourceView(m_pTexture2D, &SMViewDesc, &m_pSRV));

			return;
		}	

		switch (GetTextureType())
		{
		case eTextureType_2D:
			{
				D3D11_TEXTURE2D_DESC SMTextureDesc;
				m_pTexture2D->GetDesc(&SMTextureDesc);

				SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
				SMViewDesc.Texture2D.MipLevels = SMTextureDesc.MipLevels;
				SMViewDesc.Texture2D.MostDetailedMip = 0;
				SMViewDesc.Format = GetTypedFormat(SMTextureDesc.Format);

				pTex = (ID3D11Resource**)&m_pTexture2D;
			}
			break;

		case eTextureType_TextureArray:
			{
				D3D11_TEXTURE2D_DESC SMTextureDesc;
				m_pTexture2D->GetDesc(&SMTextureDesc);

				SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
				SMViewDesc.Texture2DArray.MipLevels = SMTextureDesc.MipLevels;
				SMViewDesc.Texture2DArray.MostDetailedMip = 0;
				SMViewDesc.Texture2DArray.FirstArraySlice = 0;
				SMViewDesc.Texture2DArray.ArraySize = SMTextureDesc.ArraySize;
				SMViewDesc.Format = GetTypedFormat(SMTextureDesc.Format);

				pTex = (ID3D11Resource**)&m_pTexture2D;
			}
			break;

		case eTextureType_CubeMap:
			{
				D3D11_TEXTURE2D_DESC SMTextureDesc;
				m_pTexture2D->GetDesc(&SMTextureDesc);

				SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
				SMViewDesc.TextureCube.MipLevels = SMTextureDesc.MipLevels;
				SMViewDesc.TextureCube.MostDetailedMip = 0;
				SMViewDesc.Format = GetTypedFormat(SMTextureDesc.Format);

				pTex = (ID3D11Resource**)&m_pTexture2D;
			}
			break;

		case eTextureType_3D:
			{
				D3D11_TEXTURE3D_DESC SMTextureDesc;
				m_pTexture3D->GetDesc(&SMTextureDesc);

				SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
				SMViewDesc.Texture3D.MipLevels = SMTextureDesc.MipLevels;
				SMViewDesc.Texture3D.MostDetailedMip = 0;
				SMViewDesc.Format = GetTypedFormat(SMTextureDesc.Format);

				pTex = (ID3D11Resource**)&m_pTexture3D;
			}
			break;

		default: _AST(0);
		}

		V(g_pRenderSys->GetDevice()->CreateShaderResourceView(*pTex, &SMViewDesc, &m_pSRV));
	}
Example #6
0
	//------------------------------------------------------------------------------------
	void D3D11Texture::_CreateManual(const char* pTexData)
	{
		HRESULT hr = S_OK;
		const DXGI_FORMAT dxformat = ConvertToDXFormat(m_texFormat);
		const DWORD bytesPerPixel = GetBytesPerPixelFromFormat(m_texFormat);

		DWORD pitch = bytesPerPixel * m_width;
		char* tmpBuf = (char*)pTexData;

		if (!pTexData)
		{
			tmpBuf = new char[pitch * m_height];
			ZeroMemory(tmpBuf, pitch * m_height * sizeof(char));
		}

		D3D11_SUBRESOURCE_DATA subData;
		D3D11_SUBRESOURCE_DATA* subDataArray = nullptr;
		subData.pSysMem = tmpBuf;
		subData.SysMemPitch = pitch;

		CD3D11_TEXTURE2D_DESC desc(dxformat, m_width, m_height);

		if (m_bMipMap)
		{
			int wid = m_width, hei = m_height;
			// Get mipmap level
			desc.MipLevels = 1;
			while((wid > 1) || (hei > 1))
			{
				wid = Max(wid / 2, 1);
				hei = Max(hei / 2, 1);
				++desc.MipLevels;
			}

			// Not correct mipmap data, just make room for later D3DX11FilterTexture
			subDataArray = new D3D11_SUBRESOURCE_DATA[desc.MipLevels];
			for (size_t i=0; i<desc.MipLevels; ++i)
			{
				subDataArray[i].pSysMem = tmpBuf;
				subDataArray[i].SysMemPitch = pitch;
			}
		}
		else
		{
			desc.MipLevels = 1;
			subDataArray = &subData;
		}

		// Validate usage
		_AST(!((m_usage&eTextureUsage_WriteOnly)&&(m_usage&eTextureUsage_ReadWrite)) && "Invalid usage!");

		if (m_usage & eTextureUsage_RenderTarget)
		{
			desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;

			if (m_usage & eTextureUsage_AutoGenMips)
			{
				desc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
			}
		}

		if (GetTextureType() == eTextureType_CubeMap)
		{
			desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
			desc.ArraySize = 6;
		}

		// Assign usage
		if (m_usage & eTextureUsage_WriteOnly)
		{
			desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
			desc.Usage = D3D11_USAGE_DYNAMIC;
		}
		else if (m_usage & eTextureUsage_ReadWrite)
		{
			D3D11_TEXTURE2D_DESC descStaging = desc;
			descStaging.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
			descStaging.Usage = D3D11_USAGE_STAGING;
			descStaging.BindFlags = 0;

			g_pRenderSys->GetDevice()->CreateTexture2D(&descStaging, subDataArray, &m_pTexStaging);
		}

		if (m_usage & eTextureUsage_Depth)
		{
			desc.Usage			= D3D11_USAGE_DEFAULT;
			desc.BindFlags		= D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;

			g_pRenderSys->GetDevice()->CreateTexture2D(&desc, nullptr, &m_pTexture2D);
		}
		else
		{
			g_pRenderSys->GetDevice()->CreateTexture2D(&desc, subDataArray, &m_pTexture2D);
		}

		if(!pTexData)
		{
			SAFE_DELETE_ARRAY(tmpBuf);
		}

		_AST(SUCCEEDED(hr) && "Create texture failed!");

		// Generate mipmap levels
		if (m_bMipMap && !(m_usage & eTextureUsage_RenderTarget))
		{
			V(D3DX11FilterTexture(g_pRenderSys->GetDeviceContext(), m_pTexture2D, 0, D3DX11_DEFAULT));
		}

		// Create SRV
		CreateSRV();

		// Create DSV
		if (m_usage & eTextureUsage_Depth)
		{
			CreateDSV();
		}

		// Create RTV
		if (m_usage & eTextureUsage_RenderTarget)
		{
			CreateRTV();
		}
	}
Example #7
0
//--------------------------------------------------------------------------
D3D11Texture::D3D11Texture(const STRING& filename, eTextureType type, uint32 usage)
    :m_pTexture2D(nullptr)
    ,m_pTexture3D(nullptr)
    ,m_pRenderSystem(g_env.pRenderSystem)
    ,m_rtView(nullptr)
    ,m_pSRV(nullptr)
    ,m_pDSV(nullptr)
    ,m_usage(usage)
    ,m_texType(type)
    ,m_width(0)
    ,m_height(0)
    ,m_bMipMap(true)
{
    m_pd3dDevice = m_pRenderSystem->GetDevice();
    if (m_pd3dDevice)
        m_pd3dDevice->AddRef();

    ////////////////////////////////////////////////////////////////
    ////////////// Load texture
    HRESULT hr = S_OK;
    D3DX11_IMAGE_LOAD_INFO loadInfo;
    loadInfo.MipLevels = 0;
    ID3D11Resource** pTex = nullptr;

    switch (GetTextureType())
    {
    case eTextureType_2D:
    {
        pTex = (ID3D11Resource**)&m_pTexture2D;
    }
    break;

    case eTextureType_CubeMap:
    {
        loadInfo.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
        pTex = (ID3D11Resource**)&m_pTexture2D;
    }
    break;

    case eTextureType_3D:
    {
        pTex = (ID3D11Resource**)&m_pTexture3D;
    }
    break;

    default:
        assert(0);
    }

    V(D3DX11CreateTextureFromFileA(m_pd3dDevice, filename.c_str(), &loadInfo, nullptr,pTex, nullptr));

    // Create SRV
    CreateSRV();

    // Store texture dimension and format
    switch (GetTextureType())
    {
    case eTextureType_2D:
    case eTextureType_CubeMap:
    {
        D3D11_TEXTURE2D_DESC desc;
        m_pTexture2D->GetDesc(&desc);

        m_width = desc.Width;
        m_height = desc.Height;

        m_texFormat = ConvertFromDXFormat(desc.Format);
    }
    break;

    case eTextureType_3D:
    {
        D3D11_TEXTURE3D_DESC desc;
        m_pTexture3D->GetDesc(&desc);

        m_width = desc.Width;
        m_height = desc.Height;

        m_texFormat = ConvertFromDXFormat(desc.Format);
    }
    break;

    default:
        assert(0);
    }
}