Skip to content

Commit 628fb5a

Browse files
committed
textures: more texture port kinds (cubemap etc.)
1 parent 2a51aef commit 628fb5a

1 file changed

Lines changed: 126 additions & 3 deletions

File tree

include/halp/texture.hpp

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,90 @@ template <static_string lit>
202202
using rgb_texture_output = texture_output<lit, rgb_texture>;
203203

204204

205+
enum class texture_kind : std::uint8_t
206+
{
207+
texture_2d = 0,
208+
texture_array,
209+
cubemap,
210+
texture_3d,
211+
};
212+
213+
template <typename F>
214+
constexpr texture_kind texture_kind_of() noexcept
215+
{
216+
if constexpr(requires { F::texture_target(); })
217+
return F::texture_target();
218+
else
219+
return texture_kind::texture_2d;
220+
}
221+
222+
// Opt-in for the upstream's depth attachment to surface on this
223+
// input's `texture.depth_handle`. Reads halp_meta(samplable_depth, true).
224+
template <typename F>
225+
constexpr bool samplable_depth_of() noexcept
226+
{
227+
if constexpr(requires { F::samplable_depth(); })
228+
return F::samplable_depth();
229+
else
230+
return false;
231+
}
232+
205233
struct gpu_texture
206234
{
207235
enum format_t
208236
{
209237
RGBA8,
210-
RGBA16F,
211-
RGBA32F,
238+
BGRA8,
212239
R8,
240+
RG8,
241+
213242
R16,
243+
RG16,
244+
245+
RGBA16F,
246+
RGBA32F,
214247
R16F,
215-
R32F
248+
R32F,
249+
250+
RGB10A2,
251+
252+
R8UI,
253+
R32UI,
254+
RG32UI,
255+
RGBA32UI,
256+
257+
R8SI,
258+
R32SI,
259+
RG32SI,
260+
RGBA32SI
216261
} format{RGBA8};
217262
void* handle{};
218263

264+
// Optional companion depth attachment.
265+
enum class depth_format_t : std::uint8_t
266+
{
267+
D16,
268+
D24,
269+
D24S8,
270+
D32F
271+
} depth_format{depth_format_t::D32F};
272+
void* depth_handle{};
273+
219274
// Used when in render target output ports, to
220275
// know the size of the destination render target.
221276
// TODO maybe split it ?
222277
int width{};
223278
int height{};
279+
280+
// Producers that allocate non-2D textures (cube, array, 3D) should set this so
281+
// consumers which don't care about the specific port type can still route correctly.
282+
texture_kind kind{texture_kind::texture_2d};
283+
284+
// For arrays / 3D / cube the depth-or-layer count. Cube == 6
285+
int layers_or_depth{1};
286+
287+
// Optional backend-owned sampler handle to pair with this texture.
288+
void* sampler_handle{};
224289
};
225290

226291
template <static_string lit>
@@ -245,6 +310,64 @@ struct gpu_texture_output
245310
halp::gpu_texture texture{};
246311
};
247312

313+
template <static_string lit>
314+
struct gpu_cubemap_input : gpu_texture_input<lit>
315+
{
316+
halp_meta(texture_target, halp::texture_kind::cubemap)
317+
};
318+
319+
template <static_string lit>
320+
struct gpu_sampleable_depth_input : gpu_texture_input<lit>
321+
{
322+
halp_meta(samplable_depth, true)
323+
};
324+
325+
template <static_string lit>
326+
struct gpu_cubemap_output : gpu_texture_output<lit>
327+
{
328+
halp_meta(texture_target, halp::texture_kind::cubemap)
329+
330+
gpu_cubemap_output() noexcept
331+
{
332+
this->texture.kind = halp::texture_kind::cubemap;
333+
this->texture.layers_or_depth = 6;
334+
}
335+
};
336+
337+
template <static_string lit>
338+
struct gpu_texture_array_input : gpu_texture_input<lit>
339+
{
340+
halp_meta(texture_target, halp::texture_kind::texture_array)
341+
};
342+
343+
template <static_string lit>
344+
struct gpu_texture_array_output : gpu_texture_output<lit>
345+
{
346+
halp_meta(texture_target, halp::texture_kind::texture_array)
347+
348+
gpu_texture_array_output() noexcept
349+
{
350+
this->texture.kind = halp::texture_kind::texture_array;
351+
}
352+
};
353+
354+
template <static_string lit>
355+
struct gpu_texture_3d_input : gpu_texture_input<lit>
356+
{
357+
halp_meta(texture_target, halp::texture_kind::texture_3d)
358+
};
359+
360+
template <static_string lit>
361+
struct gpu_texture_3d_output : gpu_texture_output<lit>
362+
{
363+
halp_meta(texture_target, halp::texture_kind::texture_3d)
364+
365+
gpu_texture_3d_output() noexcept
366+
{
367+
this->texture.kind = halp::texture_kind::texture_3d;
368+
}
369+
};
370+
248371
template <static_string lit>
249372
struct gpu_render_target_output
250373
{

0 commit comments

Comments
 (0)