Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
Bonzomatic
Commits
0aedba6b
Commit
0aedba6b
authored
Jul 28, 2019
by
Gargaj
Browse files
add hdr support to dx11/glsl backend (dx9 already supported it)
parent
af3a97d9
Changes
2
Show whitespace changes
Inline
Side-by-side
src/platform_glfw/Renderer.cpp
View file @
0aedba6b
...
@@ -694,8 +694,21 @@ namespace Renderer
...
@@ -694,8 +694,21 @@ namespace Renderer
int
comp
=
0
;
int
comp
=
0
;
int
width
=
0
;
int
width
=
0
;
int
height
=
0
;
int
height
=
0
;
unsigned
char
*
c
=
stbi_load
(
szFilename
,
&
width
,
&
height
,
&
comp
,
STBI_rgb_alpha
);
void
*
data
=
nullptr
;
if
(
!
c
)
return
NULL
;
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
;
GLuint
glTexId
=
0
;
glGenTextures
(
1
,
&
glTexId
);
glGenTextures
(
1
,
&
glTexId
);
...
@@ -706,12 +719,9 @@ namespace Renderer
...
@@ -706,12 +719,9 @@ namespace Renderer
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
GLenum
internalFormat
=
GL_SRGB8_ALPHA8
;
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
internalFormat
,
width
,
height
,
0
,
srcFormat
,
format
,
data
);
GLenum
srcFormat
=
GL_RGBA
;
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
internalFormat
,
width
,
height
,
0
,
srcFormat
,
GL_UNSIGNED_BYTE
,
c
);
stbi_image_free
(
c
);
stbi_image_free
(
data
);
GLTexture
*
tex
=
new
GLTexture
();
GLTexture
*
tex
=
new
GLTexture
();
tex
->
width
=
width
;
tex
->
width
=
width
;
...
...
src/platform_w32_dx11/Renderer.cpp
View file @
0aedba6b
...
@@ -916,14 +916,27 @@ namespace Renderer
...
@@ -916,14 +916,27 @@ namespace Renderer
int
comp
=
0
;
int
comp
=
0
;
int
width
=
0
;
int
width
=
0
;
int
height
=
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
;
D3D11_TEXTURE2D_DESC
desc
;
ZeroMemory
(
&
desc
,
sizeof
(
D3D11_TEXTURE2D_DESC
));
ZeroMemory
(
&
desc
,
sizeof
(
D3D11_TEXTURE2D_DESC
));
desc
.
Width
=
width
;
desc
.
Width
=
width
;
desc
.
Height
=
height
;
desc
.
Height
=
height
;
desc
.
Format
=
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
;
desc
.
Format
=
format
;
desc
.
MipLevels
=
1
;
desc
.
MipLevels
=
1
;
desc
.
ArraySize
=
1
;
desc
.
ArraySize
=
1
;
desc
.
SampleDesc
.
Count
=
1
;
desc
.
SampleDesc
.
Count
=
1
;
...
@@ -931,15 +944,15 @@ namespace Renderer
...
@@ -931,15 +944,15 @@ namespace Renderer
D3D11_SUBRESOURCE_DATA
subData
;
D3D11_SUBRESOURCE_DATA
subData
;
ZeroMemory
(
&
subData
,
sizeof
(
D3D11_SUBRESOURCE_DATA
));
ZeroMemory
(
&
subData
,
sizeof
(
D3D11_SUBRESOURCE_DATA
));
subData
.
pSysMem
=
c
;
subData
.
pSysMem
=
data
;
subData
.
SysMemPitch
=
width
*
sizeof
(
unsigned
char
)
*
4
;
subData
.
SysMemPitch
=
pitch
;
ID3D11Texture2D
*
pTex
=
NULL
;
ID3D11Texture2D
*
pTex
=
NULL
;
if
(
pDevice
->
CreateTexture2D
(
&
desc
,
&
subData
,
&
pTex
)
!=
S_OK
)
if
(
pDevice
->
CreateTexture2D
(
&
desc
,
&
subData
,
&
pTex
)
!=
S_OK
)
return
NULL
;
return
NULL
;
stbi_image_free
(
c
);
stbi_image_free
(
data
);
DX11Texture
*
tex
=
new
DX11Texture
();
DX11Texture
*
tex
=
new
DX11Texture
();
tex
->
width
=
width
;
tex
->
width
=
width
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment