Euphoria
texture.h
Go to the documentation of this file.
1#pragma once
2
3#include "base/size.h"
4
6
7#include <cstdint>
8
9namespace eu::render
10{
11
16enum class TextureEdge
17{
18 clamp,
19 repeat
20};
21
22
24{
25 pixel,
26 mipmap,
27 linear
28};
29
30
31enum class Transparency
32{
33 include,
35};
36
37enum class ColorData
38{
41
42 // todo(Gustav): should this be more specific so we could define better default colors if the load fails?
45
48};
49
50// todo(Gustav): move to colors.h?
53enum class SingleColor : std::uint32_t {};
54
62 return static_cast<SingleColor>((static_cast<uint32_t>(a) << 24) |
63 (static_cast<uint32_t>(b) << 16) |
64 (static_cast<uint32_t>(g) << 8) |
65 (static_cast<uint32_t>(r)));
66}
67
68// todo(Gustav): this doesn't do anything except allow code reuse, remove?
71{
72 unsigned int id;
73
76
77 BaseTexture(const BaseTexture&) = delete;
78 void operator=(const BaseTexture&) = delete;
79
82
84 void unload();
85};
86
95
97
98// todo(Gustav): turn into an enum?
100constexpr std::size_t cubemap_size = 6;
101
105{
106 TextureCubemap() = delete;
107
108 TextureCubemap(DEBUG_LABEL_ARG_MANY const std::array<void*, cubemap_size>& pixel_data, int width, int height, ColorData cd);
109};
110
112
113
114
118{
121 FrameBuffer(unsigned int f, const Size& s);
123
124 FrameBuffer(const FrameBuffer&) = delete;
126 void operator=(const FrameBuffer&) = delete;
127 void operator=(FrameBuffer&&) = delete;
128
130
131 unsigned int fbo = 0;
132 unsigned int rbo = 0;
133
134 bool debug_is_msaa = false;
135};
136
138enum class DepthBits
139{
140 use_none,
142};
143
146{
147 use_depth,
149};
150
151
161std::shared_ptr<FrameBuffer> build_simple_framebuffer(DEBUG_LABEL_ARG_MANY const Size& size);
162
163
176
177
187
188
196std::shared_ptr<FrameBuffer> build_shadow_framebuffer(DEBUG_LABEL_ARG_MANY const Size& size);
197
198
201{
202 std::shared_ptr<FrameBuffer> fbo;
203
204 BoundFbo(const BoundFbo&) = delete;
205 BoundFbo(BoundFbo&&) = delete;
206 void operator=(const BoundFbo&) = delete;
207 void operator=(BoundFbo&&) = delete;
208
209 explicit BoundFbo(std::shared_ptr<FrameBuffer> f);
211};
212
214
219}
#define DEBUG_LABEL_ARG_MANY
first debug label argument of many
std::shared_ptr< FrameBuffer > build_msaa_framebuffer(DEBUG_LABEL_ARG_MANY const Size &size, int msaa_samples, ColorBitsPerPixel bits_per_pixel)
Builds a multisample anti-aliasing (MSAA) framebuffer for high-quality rendering.
std::shared_ptr< FrameBuffer > build_simple_framebuffer(DEBUG_LABEL_ARG_MANY const Size &size)
Build a simple LDR frame buffer.
void resolve_multisampled_buffer(const FrameBuffer &src, FrameBuffer *dst)
SingleColor
A single color in a format to load directly into open gl texture(ABGR on little endian).
Definition texture.h:53
std::shared_ptr< FrameBuffer > build_hdr_floating_framebuffer(DEBUG_LABEL_ARG_MANY const Size &size, ColorBitsPerPixel bits_per_pixel)
Build a HDR frame buffer.
ColorBitsPerPixel
The number of bits/pixel to use for the color buffer.
Definition texture.h:146
std::shared_ptr< FrameBuffer > build_shadow_framebuffer(DEBUG_LABEL_ARG_MANY const Size &size)
Create a depth-only framebuffer for shadow rendering.
TextureCubemap load_cubemap_from_color(DEBUG_LABEL_ARG_MANY SingleColor pixel, ColorData cd)
DepthBits
The number of bits to use for the depth buffer.
Definition texture.h:139
constexpr std::size_t cubemap_size
0=right(x+), 1=left(x-), 2=top(y+), 3=bottom(y-), 4=front(z+), 5=back(z-)
Definition texture.h:100
TextureRenderStyle
Definition texture.h:24
constexpr SingleColor color_from_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Constructs a SingleColor value from individual red, green, blue, and alpha components.
Definition texture.h:61
Texture2d load_image_from_color(DEBUG_LABEL_ARG_MANY SingleColor pixel, TextureEdge te, TextureRenderStyle trs, Transparency t, ColorData cd)
@ non_color_data
Don't apply transformations to the color data. Texture is a normal/roughness/ao/specular map or simil...
@ color_data
Apply transformations to the color data. Texture is a diffuse/albedo map, created with human eyes on ...
@ dont_care
Explicitly don't care about the color data but same as non_color_data.
A (inclusive) range between two values.
Definition range.h:19
a size
Definition size.h:11
Base class for all textures, but only exist due to code reuse and can easily be inlined.
Definition texture.h:71
BaseTexture(const BaseTexture &)=delete
unsigned int id
Definition texture.h:72
BaseTexture(BaseTexture &&) noexcept
void operator=(const BaseTexture &)=delete
void unload()
clears the loaded texture to a invalid texture
raii class to render to a FrameBuffer
Definition texture.h:201
BoundFbo(const BoundFbo &)=delete
BoundFbo(BoundFbo &&)=delete
void operator=(BoundFbo &&)=delete
std::shared_ptr< FrameBuffer > fbo
Definition texture.h:202
void operator=(const BoundFbo &)=delete
BoundFbo(std::shared_ptr< FrameBuffer > f)
"render to texture" feature
Definition texture.h:118
FrameBuffer(const FrameBuffer &)=delete
FrameBuffer(unsigned int f, const Size &s)
FrameBuffer(FrameBuffer &&)=delete
void operator=(FrameBuffer &&)=delete
void operator=(const FrameBuffer &)=delete
A 2d image texture.
Definition texture.h:89
Texture2d(DEBUG_LABEL_ARG_MANY const void *pixel_data, unsigned int pixel_format, int w, int h, TextureEdge te, TextureRenderStyle trs, Transparency t, ColorData cd)
"internal"
A cubemap texture.
Definition texture.h:105
TextureCubemap(DEBUG_LABEL_ARG_MANY const std::array< void *, cubemap_size > &pixel_data, int width, int height, ColorData cd)