Skip to content

Commit

Permalink
add hdr support to dx11/glsl backend (dx9 already supported it)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargaj committed Jul 28, 2019
1 parent af3a97d commit 0aedba6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
24 changes: 17 additions & 7 deletions src/platform_glfw/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
Expand Down
25 changes: 19 additions & 6 deletions src/platform_w32_dx11/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,30 +916,43 @@ 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;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

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;
Expand Down

0 comments on commit 0aedba6

Please sign in to comment.