Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johannes Braun
glare
Commits
f79061d1
Commit
f79061d1
authored
Sep 04, 2017
by
Johannes Braun
Browse files
Made all execs (except game) working again.
parent
ff3b77e8
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
assets/shaders/pathtracer/pathtracer.comp
View file @
f79061d1
...
...
@@ -81,24 +81,16 @@ struct Bounce
int iArray(const in int array[num_effects], int index)
{
for(int i=0; i<4; ++i)
{
for(int i=0; i<num_effects; ++i)
if(i==index)
{
return array[i];
}
}
}
int iArrayComp(const in int array1[num_effects], const in int array2[num_effects], int index)
{
for(int i=0; i<4; ++i)
{
for(int i=0; i<num_effects; ++i)
if(i==index)
{
return array1[i] < array2[i] ? 1 : (array1[i] > array2[i] ? -1 : 0);
}
}
}
LightData sampleLight(const in Light light, const in Vertex vertex, const in vec2 random_sample)
...
...
@@ -165,10 +157,8 @@ bool shade(inout Bounce bounce)
bounce.path_distance += distance(bounce.ray.origin, vertex.position.xyz);
//int someID = img_dimen % 2;//clamp(int(bsdf_result.bsdf_id), 0, 1);
bool exceeds_bounces = false;
for(int i=0; i<
4
; ++i)
for(int i=0; i<
num_effects
; ++i)
{
if(i==bsdf_result.bsdf_id)
{
...
...
@@ -188,9 +178,7 @@ bool shade(inout Bounce bounce)
return bounce.hit.invalidate();
}
if(exceeds_bounces
|| bsdf_result.radiance == vec3(0)
|| bounce.pdf_accumulation <= 1e-5f)
if(exceeds_bounces || bsdf_result.radiance == vec3(0) || bounce.pdf_accumulation <= 1e-5f)
{
return bounce.hit.invalidate();
}
...
...
@@ -235,15 +223,9 @@ void main()
Bounce bounce;
bounce.hit = current.hit;
bounce.ray = current.ray;
ivec2 pixel = ivec2(bounce.ray.px, bounce.ray.py);
//u_render_target.imageStore(pixel, vec4(bounce.hit.barycentric, 0, 1));
//return;
//Threshold properties
bounce.path_distance = 0;
bounce.pdf_accumulation = 1.f;
bounce.bounce_amount = int[
4
](0,0,0,0);
bounce.bounce_amount = int[
num_effects
](0,0,0,0);
bounce.color = vec3(0);
bounce.radiance = vec3(1);
...
...
@@ -255,6 +237,7 @@ void main()
bounce.trace();
}
ivec2 pixel = ivec2(bounce.ray.px, bounce.ray.py);
vec4 color = u_render_target.imageLoad(pixel);
// Divide color storage by sample count to retrieve the final color.
...
...
assets/shaders/util/tracing/tracing.glsl
View file @
f79061d1
...
...
@@ -32,18 +32,6 @@ struct Hit
uint
mesh
;
};
/*
@bytesize 16
*/
// struct traceproperties
// {
// float accuracy_importance;
// float shadow_importance;
//
// uint bounce_amount;
// float travelled_distance;
// };
/*
@bytesize 64
*/
...
...
@@ -51,9 +39,6 @@ struct Trace
{
Ray
ray
;
Hit
hit
;
//Additional properties for BVH-LS-Hybrid
// TraceProperties properties;
};
...
...
src/executables/hdr_viewer/main.cpp
View file @
f79061d1
...
...
@@ -29,15 +29,15 @@ int main(int argc, char* argv[])
core
::
Context
::
createAsCurrent
(
files
::
asset
(
"/preferences/default.xml"
));
core
::
Context
::
current
().
callbacks
().
addScrollCallback
(
"main"
,
on_scroll
);
auto
texture_renderer
=
core
::
Default
TextureRenderer
s
::
makeCenterTexture
();
auto
texture_renderer
=
core
::
TextureRenderer
::
makeCenterTexture
();
texture_renderer
->
addPreDrawCallback
([](
const
core
::
Program
&
program
)
{
program
.
uniform
(
"u_scale"
,
zoom
);
});
std
::
shared_ptr
<
core
::
Texture
RGBA_32F
>
image
;
std
::
shared_ptr
<
core
::
Texture
RGBA_32F
>
heatmap_other_image
;
std
::
shared_ptr
<
core
::
Texture
RGBA_32F
>
heatmap
;
std
::
shared_ptr
<
core
::
Texture
>
image
;
std
::
shared_ptr
<
core
::
Texture
>
heatmap_other_image
;
std
::
shared_ptr
<
core
::
Texture
>
heatmap
;
std
::
sort
(
extensions
.
begin
(),
extensions
.
end
());
core
::
Program
heatmap_generator
(
files
::
shader
(
"/heatmap/heatmap.comp"
));
...
...
@@ -75,7 +75,7 @@ int main(int argc, char* argv[])
// ... draw a button which loads a dae file.
else
if
(
std
::
binary_search
(
extensions
.
begin
(),
extensions
.
end
(),
path
.
extension
().
string
())
&&
ImGui
::
FeatureButton
(
path
.
filename
().
string
().
c_str
(),
ImVec2
(
ImGui
::
GetContentRegionAvailWidth
(),
32
)))
{
image
=
core
::
global_resources
::
textures
_hdr
.
get
(
path
);
image
=
core
::
global_resources
::
textures
.
get
(
path
);
zoom
=
1.
f
;
}
}
...
...
@@ -97,7 +97,10 @@ int main(int argc, char* argv[])
std
::
string
name
=
std
::
string
(
buf
)
+
(
hdr
?
".hdr"
:
".png"
);
fs
::
path
output
=
root
/
name
;
core
::
textures
::
saveTexture
(
output
,
*
heatmap
);
if
(
hdr
)
heatmap
->
get
<
float
>
().
save
(
output
);
else
heatmap
->
get
<
uint8_t
>
().
save
(
output
);
}
ImGui
::
Separator
();
}
...
...
@@ -115,25 +118,25 @@ int main(int argc, char* argv[])
// ... draw a button which loads a dae file.
else
if
(
std
::
binary_search
(
extensions
.
begin
(),
extensions
.
end
(),
path
.
extension
().
string
())
&&
ImGui
::
FeatureButton
(
path
.
filename
().
string
().
c_str
(),
ImVec2
(
ImGui
::
GetContentRegionAvailWidth
(),
32
)))
{
heatmap_other_image
=
core
::
global_resources
::
textures
_hdr
.
get
(
path
);
heatmap_other_image
=
core
::
global_resources
::
textures
.
get
(
path
);
if
(
!
image
)
{
Log_Error
<<
"Please select a source image first!"
;
}
else
if
(
heatmap_other_image
->
getSize
()
!=
image
->
getSize
())
else
if
(
heatmap_other_image
->
width
()
!=
image
->
width
()
||
heatmap_other_image
->
height
()
!=
image
->
height
())
{
Log_Error
<<
"Selected an image with different dimensions!"
;
}
else
{
heatmap
=
std
::
make_shared
<
core
::
Texture
RGBA_32F
>
(
image
->
getSize
().
x
,
image
->
getSize
().
y
);
heatmap
=
std
::
make_shared
<
core
::
Texture
>
(
core
::
Image
<
float
>
({
image
->
width
(),
image
->
height
()
},
4
)
);
heatmap_generator
.
use
();
heatmap_generator
.
uniform
(
"u_first_image"
,
image
->
makeImageResident
(
gl
::
Access
::
eReadOnly
));
heatmap_generator
.
uniform
(
"u_second_image"
,
heatmap_other_image
->
makeImageResident
(
gl
::
Access
::
eReadOnly
));
heatmap_generator
.
uniform
(
"u_result_heatmap"
,
heatmap
->
makeImageResident
(
gl
::
Access
::
eWriteOnly
));
heatmap_generator
.
uniform
(
"u_first_image"
,
image
->
imageAddress
(
gl
::
Access
::
eReadOnly
));
heatmap_generator
.
uniform
(
"u_second_image"
,
heatmap_other_image
->
imageAddress
(
gl
::
Access
::
eReadOnly
));
heatmap_generator
.
uniform
(
"u_result_heatmap"
,
heatmap
->
imageAddress
(
gl
::
Access
::
eWriteOnly
));
heatmap_generator
.
dispatch2D
(
image
->
getSize
().
x
,
24
,
image
->
getSize
().
y
,
24
);
heatmap_generator
.
dispatch2D
(
image
->
width
()
,
24
,
image
->
height
()
,
24
);
}
zoom
=
1.
f
;
}
...
...
src/executables/minimal_gui/main.cpp
View file @
f79061d1
...
...
@@ -17,15 +17,15 @@ void gui(std::vector<std::string> extensions, std::function<void(const fs::path&
int
main
(
int
argc
,
char
*
argv
[])
{
// Initialize engine from settings xml
core
::
state
::
initialize
(
files
::
asset
(
"/preferences/default.xml"
));
core
::
Context
::
createAsCurrent
(
files
::
asset
(
"/preferences/default.xml"
));
// Create a skybox
core
::
state
::
skybox
->
reset
(
core
::
Skybox
::
collectFilesFrom
(
files
::
asset
(
"textures/ryfjallet/"
))
)
;
core
::
Context
::
current
().
skybox
()
->
reset
(
files
::
asset
(
"textures/ryfjallet/"
));
core
::
state
::
camera
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
core
::
Context
::
current
().
camera
()
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
// Render the scene with the pathtracer
core
::
state
::
mainL
oop
([]()
{
core
::
Context
::
current
().
l
oop
([]()
{
gui
({
".png"
,
".hdr"
,
".glsl"
},
[](
const
fs
::
path
&
p
)
{
...
...
src/executables/minimal_opengl/main.cpp
View file @
f79061d1
...
...
@@ -14,13 +14,13 @@ using namespace glare;
int
main
(
int
argc
,
char
*
argv
[])
{
auto
context_id
=
core
::
Context
::
createAsCurrent
(
files
::
asset
(
"/preferences/default.xml"
));
core
::
Context
::
createAsCurrent
(
files
::
asset
(
"/preferences/default.xml"
));
// Load a scene and attach it to the constant root
core
::
Context
::
current
().
graph
()
->
attach
(
core
::
global_resources
::
scenes
.
get
(
files
::
asset
(
"meshes/scenery/cbox.dae"
),
1.0
f
));
// Create a skybox
core
::
Context
::
current
().
skybox
()
->
reset
(
core
::
Skybox
::
collectFilesFrom
(
files
::
asset
(
"textures/ryfjallet/"
))
)
;
core
::
Context
::
current
().
skybox
()
->
reset
(
files
::
asset
(
"textures/ryfjallet/"
));
// Add a PlayerController to move around
core
::
Context
::
current
().
camera
()
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
...
...
src/executables/minimal_pathtracer/main.cpp
View file @
f79061d1
...
...
@@ -11,20 +11,20 @@ using namespace glare;
int
main
(
int
argc
,
char
*
argv
[])
{
// Initialize engine from settings xml
core
::
state
::
initialize
(
files
::
asset
(
"/preferences/default.xml"
));
core
::
Context
::
createAsCurrent
(
files
::
asset
(
"/preferences/default.xml"
));
// Load a scene and attach it to the constant root
core
::
state
::
graph_root
->
attach
(
core
::
global_resources
::
scenes
.
get
(
files
::
asset
(
"meshes/scenery/cbox.dae"
),
1.0
f
));
core
::
Context
::
current
().
graph
()
->
attach
(
core
::
global_resources
::
scenes
.
get
(
files
::
asset
(
"meshes/scenery/cbox.dae"
),
1.0
f
));
// Create a skybox
core
::
state
::
skybox
->
reset
(
core
::
Skybox
::
collectFilesFrom
(
files
::
asset
(
"textures/ryfjallet/"
))
)
;
core
::
Context
::
current
().
skybox
()
->
reset
(
files
::
asset
(
"textures/ryfjallet/"
));
// Add a PlayerController to move around
core
::
state
::
camera
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
core
::
Context
::
current
().
camera
()
->
owner
()
->
makeComponent
<
component
::
PlayerController
>
();
// Create a Pathtracer and all needed stuff for it from the graph
const
auto
pathtracer
=
std
::
make_unique
<
raytrace
::
Pathtracer
>
(
core
::
state
::
graph_root
);
const
auto
pathtracer
=
std
::
make_unique
<
raytrace
::
Pathtracer
>
(
core
::
Context
::
current
().
graph
()
);
// Render the scene with the pathtracer
core
::
state
::
mainL
oop
([
&
pathtracer
]()
{
pathtracer
->
draw
();
});
core
::
Context
::
current
().
l
oop
([
&
pathtracer
]()
{
pathtracer
->
draw
();
});
}
\ No newline at end of file
src/executables/test_exe/main.cpp
deleted
100644 → 0
View file @
ff3b77e8
#include
<iostream>
#include
<string>
#include
<cassert>
#include
<functional>
#include
<util/color.h>
#include
<core/state.h>
#include
<core/res/texture.h>
#include
"raytrace/data/local_collector.h"
template
<
typename
T
>
struct
Image
{
using
type
=
T
;
template
<
typename
TSource
,
typename
TTarget
>
struct
conversion
{
constexpr
static
float
value
=
1.
f
;
};
template
<
>
struct
conversion
<
float
,
uint8_t
>
{
constexpr
static
float
value
=
255.
f
;
};
template
<
>
struct
conversion
<
uint8_t
,
float
>
{
constexpr
static
float
value
=
1
/
255.
f
;
};
template
<
typename
TSource
,
typename
TTarget
>
constexpr
static
float
conversion_v
=
conversion
<
TSource
,
TTarget
>::
value
;
int
width
=
1
;
int
height
=
1
;
int
depth
=
1
;
int
components
=
0
;
//R, RG, RGB, RGBA
std
::
vector
<
T
>
data
;
template
<
typename
TOther
>
operator
Image
<
TOther
>
()
{
if
constexpr
(
std
::
is_same_v
<
T
,
TOther
>
)
{
return
*
this
;
}
else
if
constexpr
(
conversion_v
<
T
,
TOther
>
!=
1.
f
)
{
Image
<
TOther
>
other
;
other
.
width
=
width
;
other
.
height
=
height
;
other
.
depth
=
depth
;
other
.
components
=
components
;
other
.
data
.
resize
(
data
.
size
());
for
(
int
i
=
0
;
i
<
data
.
size
();
++
i
)
{
other
.
data
[
i
]
=
static_cast
<
TOther
>
(
data
[
i
]
*
conversion_v
<
T
,
TOther
>
);
}
return
other
;
}
else
{
static_assert
(
false
,
"The image template type is not supported!"
);
}
}
Image
()
{}
Image
(
int
width
,
int
components
,
std
::
vector
<
T
>
data
=
std
::
vector
<
T
>
())
:
width
(
width
),
components
(
components
),
data
(
std
::
move
(
data
))
{
assert
((
this
->
data
.
empty
()
||
this
->
data
.
size
()
==
width
*
components
)
&&
"Image data is not empty, but does not fit the given bounds."
);
}
Image
(
int
width
,
int
height
,
int
components
,
std
::
vector
<
T
>
data
=
std
::
vector
<
T
>
())
:
width
(
width
),
height
(
height
),
components
(
components
),
data
(
std
::
move
(
data
))
{
assert
((
this
->
data
.
empty
()
||
this
->
data
.
size
()
==
width
*
height
*
components
)
&&
"Image data is not empty, but does not fit the given bounds."
);
}
Image
(
int
width
,
int
height
,
int
depth
,
int
components
,
std
::
vector
<
T
>
data
=
std
::
vector
<
T
>
())
:
width
(
width
),
height
(
height
),
depth
(
depth
),
components
(
components
),
data
(
std
::
move
(
data
))
{
assert
((
this
->
data
.
empty
()
||
this
->
data
.
size
()
==
width
*
height
*
depth
*
components
)
&&
"Image data is not empty, but does not fit the given bounds."
);
}
explicit
Image
(
const
fs
::
path
&
path
)
{
depth
=
1
;
if
constexpr
(
std
::
is_same_v
<
T
,
uint8_t
>
)
{
uint8_t
*
raw_data
=
stb
::
stbi_load
(
path
.
string
().
c_str
(),
&
width
,
&
height
,
&
components
,
0
);
if
(
!
raw_data
)
{
Log_Error
<<
"Loading image failed!
\"
"
<<
path
<<
"
\"
not found."
;
width
=
0
;
height
=
0
;
components
=
0
;
return
;
}
data
=
std
::
vector
<
uint8_t
>
(
raw_data
,
raw_data
+
width
*
height
*
components
);
}
else
if
constexpr
(
std
::
is_same_v
<
T
,
float
>
)
{
float
*
raw_data
=
stb
::
stbi_loadf
(
path
.
string
().
c_str
(),
&
width
,
&
height
,
&
components
,
0
);
if
(
!
raw_data
)
{
Log_Error
<<
"Loading image failed!
\"
"
<<
path
<<
"
\"
not found."
;
width
=
0
;
height
=
0
;
components
=
0
;
return
;
}
data
=
std
::
vector
<
float
>
(
raw_data
,
raw_data
+
width
*
height
*
components
);
}
else
{
static_assert
(
false
,
"Loading images with the given template type is not supported!"
);
}
flip
();
}
private:
void
flip
()
{
images
::
flip
(
static_cast
<
unsigned
>
(
width
),
static_cast
<
unsigned
>
(
height
),
static_cast
<
int
>
(
components
),
data
.
data
());
}
};
struct
Texture
{
using
Format
=
gl
::
TextureInternalFormat
;
struct
Parameters
{
gl
::
TextureWrapMode
wrap_r
=
gl
::
TextureWrapMode
::
eRepeat
;
gl
::
TextureWrapMode
wrap_s
=
gl
::
TextureWrapMode
::
eRepeat
;
gl
::
TextureWrapMode
wrap_t
=
gl
::
TextureWrapMode
::
eRepeat
;
gl
::
TextureFilterMin
filter_min
=
gl
::
TextureFilterMin
::
eLinearMipmapLinear
;
gl
::
TextureFilterMag
filter_mag
=
gl
::
TextureFilterMag
::
eLinear
;
gl
::
TextureCompareMode
compare_mode
=
gl
::
TextureCompareMode
::
eRToTexture
;
gl
::
CompareFunc
compare_func
=
gl
::
CompareFunc
::
eLess
;
float
anisotropy
=
-
1.
f
;
};
void
setup
()
const
{
float
anisotropy
=
m_parameters
.
anisotropy
;
if
(
anisotropy
==
-
1.
f
)
gl
::
getFloatv
(
gl
::
GetParameter
::
eMaxTextureMaxAnisotropy
,
&
anisotropy
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eMaxAnisotropy
,
anisotropy
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eWrapR
,
m_parameters
.
wrap_r
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eWrapS
,
m_parameters
.
wrap_s
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eWrapT
,
m_parameters
.
wrap_t
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eMagFilter
,
m_parameters
.
filter_mag
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eMinFilter
,
m_parameters
.
filter_min
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eCompareMode
,
m_parameters
.
compare_mode
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eCompareFunc
,
m_parameters
.
compare_func
);
gl
::
generateTextureMipmap
(
m_handle
);
}
Texture
(
gl
::
TextureType
type
,
int
width
,
Format
format
,
Parameters
parameters
=
Parameters
(),
const
void
*
data
=
nullptr
)
:
Texture
(
type
,
width
,
1
,
1
,
format
,
1
,
std
::
move
(
parameters
),
data
)
{
}
Texture
(
gl
::
TextureType
type
,
int
width
,
int
height
,
Format
format
,
int
samples
,
Parameters
parameters
=
Parameters
(),
const
void
*
data
=
nullptr
)
:
Texture
(
type
,
width
,
height
,
1
,
format
,
samples
,
std
::
move
(
parameters
),
data
)
{
}
Texture
(
gl
::
TextureType
type
,
int
width
,
int
height
,
int
depth
,
Format
format
,
int
samples
,
Parameters
parameters
=
Parameters
(),
const
void
*
data
=
nullptr
)
:
m_handle
(
std
::
move
(
type
)),
m_type
(
type
)
{
m_parameters
=
std
::
move
(
parameters
);
m_format
=
format
;
m_width
=
width
;
m_height
=
height
;
m_depth
=
depth
;
m_samples
=
samples
;
}
template
<
typename
T
>
Texture
(
const
Image
<
T
>&
image
,
Parameters
parameters
=
Parameters
())
{
m_parameters
=
std
::
move
(
parameters
);
m_format
=
getFormat
(
image
);
m_width
=
image
.
width
;
m_height
=
image
.
height
;
m_depth
=
image
.
depth
;
gl
::
TextureFormat
texture_format
=
[](
int
components
)
{
switch
(
components
)
{
case
1
:
return
gl
::
TextureFormat
::
eRed
;
case
2
:
return
gl
::
TextureFormat
::
eRG
;
case
3
:
return
gl
::
TextureFormat
::
eRGB
;
case
4
:
return
gl
::
TextureFormat
::
eRGBA
;
default:
throw
std
::
invalid_argument
(
"Texture format not valid."
);
}
}(
image
.
components
);
if
(
image
.
height
==
1
)
{
//1d texture
assert
(
image
.
depth
==
1
&&
"Malformed image! Height is 1, but not depth."
);
m_type
=
gl
::
TextureType
::
e1D
;
m_handle
.
regenerate
(
gl
::
TextureType
::
e1D
);
gl
::
pixelStorei
(
gl
::
PixelStoreAlignment
::
ePack
,
1
);
gl
::
textureImage
(
m_handle
,
gl
::
ImageTarget
::
e1D
,
0
,
m_format
,
texture_format
,
{
image
.
width
},
image
.
data
.
empty
()
?
nullptr
:
image
.
data
.
data
());
}
else
if
(
image
.
depth
==
1
)
{
//2d texture
m_type
=
gl
::
TextureType
::
e2D
;
m_handle
.
regenerate
(
gl
::
TextureType
::
e2D
);
gl
::
pixelStorei
(
gl
::
PixelStoreAlignment
::
ePack
,
1
);
gl
::
textureImage
(
m_handle
,
gl
::
ImageTarget
::
e2D
,
0
,
m_format
,
texture_format
,
{
image
.
width
,
image
.
height
},
image
.
data
.
empty
()
?
nullptr
:
image
.
data
.
data
());
}
else
{
//3d texture
m_type
=
gl
::
TextureType
::
e3D
;
m_handle
.
regenerate
(
gl
::
TextureType
::
e3D
);
gl
::
pixelStorei
(
gl
::
PixelStoreAlignment
::
ePack
,
1
);
gl
::
textureImage
(
m_handle
,
gl
::
ImageTarget
::
e3D
,
0
,
m_format
,
texture_format
,
{
image
.
width
,
image
.
height
,
image
.
depth
},
image
.
data
.
empty
()
?
nullptr
:
image
.
data
.
data
());
}
setup
();
}
bool
textureResident
()
const
{
return
m_texture_address
!=
0
&&
gl
::
isTextureHandleResident
(
m_texture_address
);
}
uint64_t
residentTextureAddress
()
const
{
if
(
!
textureResident
())
{
m_texture_address
=
gl
::
getTextureHandle
(
m_handle
);
gl
::
makeTextureHandleResident
(
m_texture_address
);
}
assert
(
textureResident
());
return
m_texture_address
;
}
template
<
typename
T
>
static
gl
::
TextureInternalFormat
getFormat
(
const
Image
<
T
>&
image
)
{
switch
(
image
.
components
)
{
case
1
:
if
constexpr
(
std
::
is_same_v
<
T
,
float
>
)
return
gl
::
TextureInternalFormat
::
eR32Float
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint8_t
>
)
return
gl
::
TextureInternalFormat
::
eRed
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint16_t
>
)
return
gl
::
TextureInternalFormat
::
eR16UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint32_t
>
)
return
gl
::
TextureInternalFormat
::
eR32UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int8_t
>
)
return
gl
::
TextureInternalFormat
::
eR8Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int16_t
>
)
return
gl
::
TextureInternalFormat
::
eR16Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int32_t
>
)
return
gl
::
TextureInternalFormat
::
eR32Int
;
case
2
:
if
constexpr
(
std
::
is_same_v
<
T
,
float
>
)
return
gl
::
TextureInternalFormat
::
eRG32Float
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint8_t
>
)
return
gl
::
TextureInternalFormat
::
eRG
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint16_t
>
)
return
gl
::
TextureInternalFormat
::
eRG16UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint32_t
>
)
return
gl
::
TextureInternalFormat
::
eRG32UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int8_t
>
)
return
gl
::
TextureInternalFormat
::
eRG8Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int16_t
>
)
return
gl
::
TextureInternalFormat
::
eRG16Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int32_t
>
)
return
gl
::
TextureInternalFormat
::
eRG32Int
;
case
3
:
if
constexpr
(
std
::
is_same_v
<
T
,
float
>
)
return
gl
::
TextureInternalFormat
::
eRGB32Float
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint8_t
>
)
return
gl
::
TextureInternalFormat
::
eRGB
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint16_t
>
)
return
gl
::
TextureInternalFormat
::
eRGB16UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint32_t
>
)
return
gl
::
TextureInternalFormat
::
eRGB32UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int8_t
>
)
return
gl
::
TextureInternalFormat
::
eRGB8Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int16_t
>
)
return
gl
::
TextureInternalFormat
::
eRGB16Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int32_t
>
)
return
gl
::
TextureInternalFormat
::
eRGB32Int
;
case
4
:
if
constexpr
(
std
::
is_same_v
<
T
,
float
>
)
return
gl
::
TextureInternalFormat
::
eRGBA32Float
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint8_t
>
)
return
gl
::
TextureInternalFormat
::
eRGBA
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint16_t
>
)
return
gl
::
TextureInternalFormat
::
eRGBA16UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
uint32_t
>
)
return
gl
::
TextureInternalFormat
::
eRGBA32UInt
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int8_t
>
)
return
gl
::
TextureInternalFormat
::
eRGBA8Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int16_t
>
)
return
gl
::
TextureInternalFormat
::
eRGBA16Int
;
else
if
constexpr
(
std
::
is_same_v
<
T
,
int32_t
>
)
return
gl
::
TextureInternalFormat
::
eRGBA32Int
;
throw
std
::
invalid_argument
(
"Using images other than 32 bit float and integral types is not yet implemented"
);
default:
throw
std
::
invalid_argument
(
"Malformed image! Component count not in range 1 to 4."
);
}
}
private:
gl
::
handle
::
texture
m_handle
{
gl
::
TextureType
::
e1D
};
gl
::
TextureInternalFormat
m_format
;
gl
::
TextureType
m_type
;
int
m_width
=
1
;
int
m_height
=
1
;
int
m_depth
=
1
;
int
m_samples
=
1
;
Parameters
m_parameters
;
mutable
uint64_t
m_texture_address
=
0
;
};
int
main
()
{
Image
<
uint8_t
>
img
(
files
::
asset
(
"textures/bricky.png"
));
Image
<
uint16_t
>
image16
(
574
,
87
,
3
);
Image
<
float
>
imf
=
img
;
glare
::
core
::
Context
::
createAsCurrent
(
files
::
asset
(
"/preferences/default.xml"
));
Texture
texture
(
imf
);
auto
renderer
=
glare
::
core
::
DefaultTextureRenderers
::
makeSimple
();
glare
::
core
::
Context
::
current
().
loop
([
&
renderer
,
&
texture
]()
{
renderer
->
draw
(
texture
);
});
system
(
"pause"
);
return
0
;
}
\ No newline at end of file
src/executables/test_exe2/main.cpp
deleted
100644 → 0
View file @
ff3b77e8
This diff is collapsed.
Click to expand it.
src/libraries/core/base/texture.cpp
View file @
f79061d1
...
...
@@ -64,7 +64,21 @@ namespace glare::core
{
if
(
!
imageResident
())
{
m_image_address
=
gl
::
getImageHandle
(
m_handle
,
0
,
false
,
0
,
gl
::
ImageUnitFormat
(
m_format
));
gl
::
ImageUnitFormat
image_format
=
[
this
]()
{
switch
(
m_format
)
{
case
StoreFormat
::
eRGB32Float
:
return
gl
::
ImageUnitFormat
::
eRGBA32Float
;
case
StoreFormat
::
eRGB32UInt
:
return
gl
::
ImageUnitFormat
::
eRGBA32UInt
;
case
StoreFormat
::
eRGB32Int
:
return
gl
::
ImageUnitFormat
::
eRGBA32Int
;
default:
return
gl
::
ImageUnitFormat
(
m_format
);
}
}();