Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#ActualMigi0027

Posted 29 August 2013 - 02:44 PM

Hi guys!

 

So recently I needed a cube map, and I've never actually used one, so, this is my first try. But something goes wrong, some invalid parameters were passed, this is how I create the cube map:

 

PS. The other functions are from the library devIL (http://openil.sourceforge.net/)

// Will be filled and returned
ID3D11ShaderResourceView* pSRV = NULL;

ilInit();
 
// Load image from DevIL
ILuint idImage;
ilGenImages( 1, &idImage );
ilBindImage( idImage );
ilLoadImage( filePath.c_str() );
_ASSERT ( IL_NO_ERROR == ilGetError() );
 
// Fetch dimensions of image
int width = ilGetInteger( IL_IMAGE_WIDTH );
int height = ilGetInteger( IL_IMAGE_HEIGHT );
 
// Load the data
ilConvertImage( IL_RGBA,IL_UNSIGNED_BYTE );
unsigned char * pData = ilGetData();
 
// Build the texture header descriptor
D3D11_TEXTURE2D_DESC descTex;
descTex.Width = width;
descTex.Height = height;
descTex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
descTex.Usage = D3D11_USAGE_DEFAULT;
descTex.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
descTex.CPUAccessFlags = 0;
descTex.MipLevels = 1;
descTex.ArraySize = 1;
descTex.SampleDesc.Count = 1;
descTex.SampleDesc.Quality = 0;
descTex.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
 
// Resource data descriptor
D3D11_SUBRESOURCE_DATA data ;
memset( &data, 0, sizeof(D3D11_SUBRESOURCE_DATA));
data.pSysMem = pData;
data.SysMemPitch = 4 * width;
 
// Create the 2d texture from data
ID3D11Texture2D * pTexture = NULL;
HV( pDevice->CreateTexture2D( &descTex, &data, &pTexture ));
 
// Create resource view descriptor
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = descTex.Format;
srvDesc.ViewDimension = dimension;

srvDesc.TextureCube.MostDetailedMip = 0;
srvDesc.TextureCube.MipLevels = D3D11_RESOURCE_MISC_GENERATE_MIPS;

srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = D3D11_RESOURCE_MISC_GENERATE_MIPS ;
 
// Create the shader resource view
HV( pDevice->CreateShaderResourceView( pTexture, &srvDesc, &pSRV ));
 
// Delete from IL buffer after image loaded correctly
ilDeleteImages( 1, &idImage );
idImage = 0;
 
return pSRV;

Where dimension is D3D11_SRV_DIMENSION_TEXTURECUBE, now what could I be doing wrong? (...Everything)

 

PS. I won't respond in the next 12-24 hours.

 

Thank You smile.png

-MIGI0027


#1Migi0027

Posted 29 August 2013 - 02:44 PM

Hi guys!

 

So recently I needed a cube map, and I've never actually used one, so, this is my first try. But something goes wrong, some invalid parameters were passed, this is how I create the cube map:

 

PS. The other functions are from the library devIL (http://openil.sourceforge.net/)

// Will be filled and returned
ID3D11ShaderResourceView* pSRV = NULL;

ilInit();
 
// Load image from DevIL
ILuint idImage;
ilGenImages( 1, &idImage );
ilBindImage( idImage );
ilLoadImage( filePath.c_str() );
_ASSERT ( IL_NO_ERROR == ilGetError() );
 
// Fetch dimensions of image
int width = ilGetInteger( IL_IMAGE_WIDTH );
int height = ilGetInteger( IL_IMAGE_HEIGHT );
 
// Load the data
ilConvertImage( IL_RGBA,IL_UNSIGNED_BYTE );
unsigned char * pData = ilGetData();
 
// Build the texture header descriptor
D3D11_TEXTURE2D_DESC descTex;
descTex.Width = width;
descTex.Height = height;
descTex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
descTex.Usage = D3D11_USAGE_DEFAULT;
descTex.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
descTex.CPUAccessFlags = 0;
descTex.MipLevels = 1;
descTex.ArraySize = 1;
descTex.SampleDesc.Count = 1;
descTex.SampleDesc.Quality = 0;
descTex.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
 
// Resource data descriptor
D3D11_SUBRESOURCE_DATA data ;
memset( &data, 0, sizeof(D3D11_SUBRESOURCE_DATA));
data.pSysMem = pData;
data.SysMemPitch = 4 * width;
 
// Create the 2d texture from data
ID3D11Texture2D * pTexture = NULL;
HV( pDevice->CreateTexture2D( &descTex, &data, &pTexture ));
 
// Create resource view descriptor
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = descTex.Format;
srvDesc.ViewDimension = dimension;

srvDesc.TextureCube.MostDetailedMip = 0;
srvDesc.TextureCube.MipLevels = D3D11_RESOURCE_MISC_GENERATE_MIPS;

srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = D3D11_RESOURCE_MISC_GENERATE_MIPS ;
 
// Create the shader resource view
HV( pDevice->CreateShaderResourceView( pTexture, &srvDesc, &pSRV ));
 
// Delete from IL buffer after image loaded correctly
ilDeleteImages( 1, &idImage );
idImage = 0;
 
return pSRV;

Where dimension is D3D11_SRV_DIMENSION_TEXTURECUBE, now what could I be doing wrong? (...Everything)

 

PS. I won't respond in the next 12-24 hours.

 

Thank You smile.png

-MIGI0027


PARTNERS