Commit 0aedba6b authored by Gargaj's avatar Gargaj
Browse files

add hdr support to dx11/glsl backend (dx9 already supported it)

parent af3a97d9
......@@ -694,8 +694,21 @@ namespace Renderer
int comp = 0;
int width = 0;
int height = 0;
unsigned char * c = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha );
if (!c) return NULL;
void * data = nullptr;
GLenum internalFormat = GL_SRGB8_ALPHA8;
GLenum srcFormat = GL_RGBA;
GLenum format = GL_UNSIGNED_BYTE;
if ( stbi_is_hdr( szFilename ) )
{
internalFormat = GL_RGBA32F;
format = GL_FLOAT;
data = stbi_loadf( szFilename, &width, &height, &comp, STBI_rgb_alpha );
}
else
{
data = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha );
}
if (!data) return NULL;
GLuint glTexId = 0;
glGenTextures( 1, &glTexId );
......@@ -706,12 +719,9 @@ namespace Renderer
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
GLenum internalFormat = GL_SRGB8_ALPHA8;
GLenum srcFormat = GL_RGBA;
glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, width, height, 0, srcFormat, GL_UNSIGNED_BYTE, c );
glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, width, height, 0, srcFormat, format, data );
stbi_image_free(c);
stbi_image_free(data);
GLTexture * tex = new GLTexture();
tex->width = width;
......
......@@ -916,14 +916,27 @@ namespace Renderer
int comp = 0;
int width = 0;
int height = 0;
unsigned char * c = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha );
if (!c) return NULL;
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
void * data = NULL;
unsigned int pitch = 0;
if ( stbi_is_hdr( szFilename ) )
{
data = stbi_loadf( szFilename, &width, &height, &comp, STBI_rgb_alpha );
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
pitch = width * sizeof( float ) * 4;
}
else
{
data = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha );
pitch = width * sizeof( unsigned char ) * 4;
}
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
desc.Width = width;
desc.Height = height;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
desc.Format = format;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
......@@ -931,15 +944,15 @@ namespace Renderer
D3D11_SUBRESOURCE_DATA subData;
ZeroMemory(&subData,sizeof(D3D11_SUBRESOURCE_DATA));
subData.pSysMem = c;
subData.SysMemPitch = width * sizeof(unsigned char) * 4;
subData.pSysMem = data;
subData.SysMemPitch = pitch;
ID3D11Texture2D * pTex = NULL;
if (pDevice->CreateTexture2D( &desc, &subData, &pTex ) != S_OK)
return NULL;
stbi_image_free(c);
stbi_image_free(data);
DX11Texture * tex = new DX11Texture();
tex->width = width;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment