@ -0,0 +1,53 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_BLEND_FACTOR_HPP | |||
#define ANTKEEPER_GL_BLEND_FACTOR_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Source and destination color and alpha blending factors. | |||
enum class blend_factor: std::uint8_t | |||
{ | |||
zero, | |||
one, | |||
src_color, | |||
one_minus_src_color, | |||
dst_color, | |||
one_minus_dst_color, | |||
src_alpha, | |||
one_minus_src_alpha, | |||
dst_alpha, | |||
one_minus_dst_alpha, | |||
constant_color, | |||
one_minus_constant_color, | |||
constant_alpha, | |||
one_minus_constant_alpha, | |||
src_alpha_saturate, | |||
src1_color, | |||
one_minus_src1_color, | |||
src1_alpha, | |||
one_minus_src1_alpha | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_BLEND_FACTOR_HPP |
@ -0,0 +1,42 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_CLEAR_BITS_HPP | |||
#define ANTKEEPER_GL_CLEAR_BITS_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Clear mask bits. | |||
enum: std::uint8_t | |||
{ | |||
/// Indicates the color buffer should be cleared. | |||
color_clear_bit = 0b001, | |||
/// Indicates the depth buffer should be cleared. | |||
depth_clear_bit = 0b010, | |||
/// Indicates the stencil buffer should be cleared. | |||
stencil_clear_bit = 0b100, | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_CLEAR_BITS_HPP |
@ -0,0 +1,46 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_CLEAR_VALUE_HPP | |||
#define ANTKEEPER_GL_CLEAR_VALUE_HPP | |||
#include <array> | |||
#include <cstdint> | |||
namespace gl { | |||
/** | |||
* Clear value. | |||
*/ | |||
struct clear_value | |||
{ | |||
/// Color clear values. | |||
std::array<float, 4> color{}; | |||
/// Depth clear value. | |||
float depth{}; | |||
/// Stencil clear value. | |||
std::uint32_t stencil{}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_CLEAR_VALUE_HPP |
@ -0,0 +1,52 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_COLOR_BLEND_EQUATION_HPP | |||
#define ANTKEEPER_GL_COLOR_BLEND_EQUATION_HPP | |||
#include <engine/gl/blend-factor.hpp> | |||
#include <engine/gl/blend-op.hpp> | |||
namespace gl { | |||
/// Color blend factors and operations. | |||
struct color_blend_equation | |||
{ | |||
/// Selects which blend factor is used to determine the RGB source factors. | |||
blend_factor src_color_blend_factor; | |||
/// Selects which blend factor is used to determine the RGB destination factors. | |||
blend_factor dst_color_blend_factor; | |||
/// Selects which blend operation is used to calculate the RGB values to write to the color attachment. | |||
blend_op color_blend_op; | |||
/// Selects which blend factor is used to determine the alpha source factor. | |||
blend_factor src_alpha_blend_factor; | |||
/// Selects which blend factor is used to determine the alpha destination factor. | |||
blend_factor dst_alpha_blend_factor; | |||
/// Selects which blend operation is used to calculate the alpha values to write to the color attachment. | |||
blend_op alpha_blend_op; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_COLOR_BLEND_EQUATION_HPP |
@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_COLOR_COMPONENT_BITS_HPP | |||
#define ANTKEEPER_GL_COLOR_COMPONENT_BITS_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Bits controlling which components are written to the framebuffer. | |||
enum: std::uint8_t | |||
{ | |||
/// Indicates that the R value is written to the color attachment for the appropriate sample. | |||
color_component_r_bit = 0b0001, | |||
/// Indicates that the G value is written to the color attachment for the appropriate sample. | |||
color_component_g_bit = 0b0010, | |||
/// Indicates that the B value is written to the color attachment for the appropriate sample. | |||
color_component_b_bit = 0b0100, | |||
/// Indicates that the A value is written to the color attachment for the appropriate sample. | |||
color_component_a_bit = 0b1000, | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_COLOR_COMPONENT_BITS_HPP |
@ -0,0 +1,57 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_COMPARE_OP_HPP | |||
#define ANTKEEPER_GL_COMPARE_OP_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Comparison operators. | |||
enum class compare_op: std::uint8_t | |||
{ | |||
/// Comparison always evaluates `false`. | |||
never, | |||
/// Comparison evaluates `reference` < `test`. | |||
less, | |||
/// Comparison evaluates `reference` == `test`. | |||
equal, | |||
/// Comparison evaluates `reference` <= `test`. | |||
less_or_equal, | |||
/// Comparison evaluates `reference` > `test`. | |||
greater, | |||
/// Comparison evaluates `reference` != `test`. | |||
not_equal, | |||
/// Comparison evaluates `reference` >= `test`. | |||
greater_or_equal, | |||
/// Comparison always evaluates `true`. | |||
always | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_COMPARE_OP_HPP |
@ -0,0 +1,77 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/cube-map.hpp> | |||
namespace gl { | |||
cube_map_layout infer_cube_map_layout(std::uint32_t width, std::uint32_t height) noexcept | |||
{ | |||
if (width == height / 6) | |||
{ | |||
return cube_map_layout::column; | |||
} | |||
else if (width == height * 6) | |||
{ | |||
return cube_map_layout::row; | |||
} | |||
else if (width == (height / 4) * 3) | |||
{ | |||
return cube_map_layout::vertical_cross; | |||
} | |||
else if (width == (height * 4) / 3) | |||
{ | |||
return cube_map_layout::horizontal_cross; | |||
} | |||
else if (width == height * 2) | |||
{ | |||
return cube_map_layout::equirectangular; | |||
} | |||
else if (width == height) | |||
{ | |||
return cube_map_layout::spherical; | |||
} | |||
return cube_map_layout::unknown; | |||
} | |||
std::uint32_t infer_cube_map_face_width(std::uint32_t width, std::uint32_t height, cube_map_layout layout) noexcept | |||
{ | |||
switch (layout) | |||
{ | |||
case cube_map_layout::column: | |||
case cube_map_layout::spherical: | |||
return width; | |||
case cube_map_layout::row: | |||
return height; | |||
case cube_map_layout::vertical_cross: | |||
return height / 4; | |||
case cube_map_layout::horizontal_cross: | |||
case cube_map_layout::equirectangular: | |||
return width / 4; | |||
default: | |||
return 0; | |||
} | |||
} | |||
} // namespace gl |
@ -0,0 +1,75 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_CUBE_MAP_HPP | |||
#define ANTKEEPER_GL_CUBE_MAP_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Cube map layouts. | |||
enum class cube_map_layout: std::uint8_t | |||
{ | |||
/// Unknown layout. | |||
unknown, | |||
/// Faces are stored consecutively in a single column. | |||
column, | |||
/// Faces are stored consecutively in a single row. | |||
row, | |||
/// Faces are stored in a vertical cross. | |||
vertical_cross, | |||
/// Faces are stored in a horizontal cross. | |||
horizontal_cross, | |||
/// Faces are stored in an equirectangular projection. | |||
equirectangular, | |||
/// Faces are stored in a spherical projection. | |||
spherical | |||
}; | |||
/** | |||
* Infers the layout of a cube map from its dimensions. | |||
* | |||
* @param width Cube map width. | |||
* @param height Cube map height. | |||
* | |||
* @return Inferred cube map layout. | |||
*/ | |||
[[nodiscard]] cube_map_layout infer_cube_map_layout(std::uint32_t width, std::uint32_t height) noexcept; | |||
/** | |||
* Infers the width of a cube map face from its dimensons and layout. | |||
* | |||
* @param width Cube map width. | |||
* @param height Cube map height. | |||
* @param layout Cube map layout. | |||
* | |||
* @return Inferred cube map face width. | |||
*/ | |||
[[nodiscard]] std::uint32_t infer_cube_map_face_width(std::uint32_t width, std::uint32_t height, cube_map_layout layout) noexcept; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_CUBE_MAP_HPP |
@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_CULL_MODE_HPP | |||
#define ANTKEEPER_GL_CULL_MODE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Triangle culling mode. | |||
enum class cull_mode: std::uint8_t | |||
{ | |||
/// No triangles are discarded. | |||
none, | |||
/// Front-facing triangles are discarded. | |||
front, | |||
/// Back-facing triangles are discarded. | |||
back, | |||
/// All triangles are discarded. | |||
front_and_back | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_CULL_MODE_HPP |
@ -0,0 +1,42 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_FILL_MODE_HPP | |||
#define ANTKEEPER_GL_FILL_MODE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Polygon rasterization mode. | |||
enum class fill_mode: std::uint8_t | |||
{ | |||
/// Polygons are filled. | |||
fill, | |||
/// Polygons edges are drawn as line segments. | |||
line, | |||
/// Polygons vertices are drawn as points. | |||
point | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_FILL_MODE_HPP |
@ -0,0 +1,219 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_FORMAT_HPP | |||
#define ANTKEEPER_GL_FORMAT_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Image and vertex formats. | |||
enum class format: std::uint32_t | |||
{ | |||
undefined, | |||
r4g4_unorm_pack8, | |||
r4g4b4a4_unorm_pack16, | |||
b4g4r4a4_unorm_pack16, | |||
r5g6b5_unorm_pack16, | |||
b5g6r5_unorm_pack16, | |||
r5g5b5a1_unorm_pack16, | |||
b5g5r5a1_unorm_pack16, | |||
a1r5g5b5_unorm_pack16, | |||
r8_unorm, | |||
r8_snorm, | |||
r8_uscaled, | |||
r8_sscaled, | |||
r8_uint, | |||
r8_sint, | |||
r8_srgb, | |||
r8g8_unorm, | |||
r8g8_snorm, | |||
r8g8_uscaled, | |||
r8g8_sscaled, | |||
r8g8_uint, | |||
r8g8_sint, | |||
r8g8_srgb, | |||
r8g8b8_unorm, | |||
r8g8b8_snorm, | |||
r8g8b8_uscaled, | |||
r8g8b8_sscaled, | |||
r8g8b8_uint, | |||
r8g8b8_sint, | |||
r8g8b8_srgb, | |||
b8g8r8_unorm, | |||
b8g8r8_snorm, | |||
b8g8r8_uscaled, | |||
b8g8r8_sscaled, | |||
b8g8r8_uint, | |||
b8g8r8_sint, | |||
b8g8r8_srgb, | |||
r8g8b8a8_unorm, | |||
r8g8b8a8_snorm, | |||
r8g8b8a8_uscaled, | |||
r8g8b8a8_sscaled, | |||
r8g8b8a8_uint, | |||
r8g8b8a8_sint, | |||
r8g8b8a8_srgb, | |||
b8g8r8a8_unorm, | |||
b8g8r8a8_snorm, | |||
b8g8r8a8_uscaled, | |||
b8g8r8a8_sscaled, | |||
b8g8r8a8_uint, | |||
b8g8r8a8_sint, | |||
b8g8r8a8_srgb, | |||
a8b8g8r8_unorm_pack32, | |||
a8b8g8r8_snorm_pack32, | |||
a8b8g8r8_uscaled_pack32, | |||
a8b8g8r8_sscaled_pack32, | |||
a8b8g8r8_uint_pack32, | |||
a8b8g8r8_sint_pack32, | |||
a8b8g8r8_srgb_pack32, | |||
a2r10g10b10_unorm_pack32, | |||
a2r10g10b10_snorm_pack32, | |||
a2r10g10b10_uscaled_pack32, | |||
a2r10g10b10_sscaled_pack32, | |||
a2r10g10b10_uint_pack32, | |||
a2r10g10b10_sint_pack32, | |||
a2b10g10r10_unorm_pack32, | |||
a2b10g10r10_snorm_pack32, | |||
a2b10g10r10_uscaled_pack32, | |||
a2b10g10r10_sscaled_pack32, | |||
a2b10g10r10_uint_pack32, | |||
a2b10g10r10_sint_pack32, | |||
r16_unorm, | |||
r16_snorm, | |||
r16_uscaled, | |||
r16_sscaled, | |||
r16_uint, | |||
r16_sint, | |||
r16_sfloat, | |||
r16g16_unorm, | |||
r16g16_snorm, | |||
r16g16_uscaled, | |||
r16g16_sscaled, | |||
r16g16_uint, | |||
r16g16_sint, | |||
r16g16_sfloat, | |||
r16g16b16_unorm, | |||
r16g16b16_snorm, | |||
r16g16b16_uscaled, | |||
r16g16b16_sscaled, | |||
r16g16b16_uint, | |||
r16g16b16_sint, | |||
r16g16b16_sfloat, | |||
r16g16b16a16_unorm, | |||
r16g16b16a16_snorm, | |||
r16g16b16a16_uscaled, | |||
r16g16b16a16_sscaled, | |||
r16g16b16a16_uint, | |||
r16g16b16a16_sint, | |||
r16g16b16a16_sfloat, | |||
r32_uint, | |||
r32_sint, | |||
r32_sfloat, | |||
r32g32_uint, | |||
r32g32_sint, | |||
r32g32_sfloat, | |||
r32g32b32_uint, | |||
r32g32b32_sint, | |||
r32g32b32_sfloat, | |||
r32g32b32a32_uint, | |||
r32g32b32a32_sint, | |||
r32g32b32a32_sfloat, | |||
r64_uint, | |||
r64_sint, | |||
r64_sfloat, | |||
r64g64_uint, | |||
r64g64_sint, | |||
r64g64_sfloat, | |||
r64g64b64_uint, | |||
r64g64b64_sint, | |||
r64g64b64_sfloat, | |||
r64g64b64a64_uint, | |||
r64g64b64a64_sint, | |||
r64g64b64a64_sfloat, | |||
b10g11r11_ufloat_pack32, | |||
e5b9g9r9_ufloat_pack32, | |||
d16_unorm, | |||
x8_d24_unorm_pack32, | |||
d32_sfloat, | |||
s8_uint, | |||
d16_unorm_s8_uint, | |||
d24_unorm_s8_uint, | |||
d32_sfloat_s8_uint, | |||
bc1_rgb_unorm_block, | |||
bc1_rgb_srgb_block, | |||
bc1_rgba_unorm_block, | |||
bc1_rgba_srgb_block, | |||
bc2_unorm_block, | |||
bc2_srgb_block, | |||
bc3_unorm_block, | |||
bc3_srgb_block, | |||
bc4_unorm_block, | |||
bc4_snorm_block, | |||
bc5_unorm_block, | |||
bc5_snorm_block, | |||
bc6h_ufloat_block, | |||
bc6h_sfloat_block, | |||
bc7_unorm_block, | |||
bc7_srgb_block, | |||
etc2_r8g8b8_unorm_block, | |||
etc2_r8g8b8_srgb_block, | |||
etc2_r8g8b8a1_unorm_block, | |||
etc2_r8g8b8a1_srgb_block, | |||
etc2_r8g8b8a8_unorm_block, | |||
etc2_r8g8b8a8_srgb_block, | |||
eac_r11_unorm_block, | |||
eac_r11_snorm_block, | |||
eac_r11g11_unorm_block, | |||
eac_r11g11_snorm_block, | |||
astc_4x4_unorm_block, | |||
astc_4x4_srgb_block, | |||
astc_5x4_unorm_block, | |||
astc_5x4_srgb_block, | |||
astc_5x5_unorm_block, | |||
astc_5x5_srgb_block, | |||
astc_6x5_unorm_block, | |||
astc_6x5_srgb_block, | |||
astc_6x6_unorm_block, | |||
astc_6x6_srgb_block, | |||
astc_8x5_unorm_block, | |||
astc_8x5_srgb_block, | |||
astc_8x6_unorm_block, | |||
astc_8x6_srgb_block, | |||
astc_8x8_unorm_block, | |||
astc_8x8_srgb_block, | |||
astc_10x5_unorm_block, | |||
astc_10x5_srgb_block, | |||
astc_10x6_unorm_block, | |||
astc_10x6_srgb_block, | |||
astc_10x8_unorm_block, | |||
astc_10x8_srgb_block, | |||
astc_10x10_unorm_block, | |||
astc_10x10_srgb_block, | |||
astc_12x10_unorm_block, | |||
astc_12x10_srgb_block, | |||
astc_12x12_unorm_block, | |||
astc_12x12_srgb_block | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_FORMAT_HPP |
@ -0,0 +1,44 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_FRAMEBUFFER_ATTACHMENT_HPP | |||
#define ANTKEEPER_GL_FRAMEBUFFER_ATTACHMENT_HPP | |||
#include <engine/gl/image-view.hpp> | |||
#include <cstdint> | |||
#include <memory> | |||
namespace gl { | |||
/// Framebuffer attachment. | |||
struct framebuffer_attachment | |||
{ | |||
/// Attachment usage bit mask. | |||
std::uint8_t usage_mask{}; | |||
/// Attached image view. | |||
std::shared_ptr<gl::image_view> image_view; | |||
/// Mip level of attached image view. | |||
std::uint32_t level{}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_FRAMEBUFFER_ATTACHMENT_HPP |
@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_FRAMEBUFFER_USAGE_BITS_HPP | |||
#define ANTKEEPER_GL_FRAMEBUFFER_USAGE_BITS_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Framebuffer attachment usage bits. | |||
enum: std::uint8_t | |||
{ | |||
/// Framebuffer color attachment. | |||
color_attachment_bit = 0b001, | |||
/// Framebuffer depth attachment. | |||
depth_attachment_bit = 0b010, | |||
/// Framebuffer stencil attachment. | |||
stencil_attachment_bit = 0b100, | |||
/// Framebuffer depth/stencil attachment. | |||
depth_stencil_attachment_bits = 0b110, | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_FRAMEBUFFER_USAGE_BITS_HPP |
@ -0,0 +1,298 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/image-view.hpp> | |||
#include <engine/gl/opengl/gl-format-lut.hpp> | |||
#include <stdexcept> | |||
#include <glad/gl.h> | |||
namespace gl { | |||
image_view::image_view | |||
( | |||
std::shared_ptr<gl::image> image, | |||
std::uint8_t dimensionality, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer, | |||
std::uint32_t array_layer_count, | |||
std::uint8_t flags | |||
) | |||
{ | |||
if (!image) | |||
{ | |||
throw std::invalid_argument("Image view has null image."); | |||
} | |||
if (format == gl::format::undefined) | |||
{ | |||
format = image->get_format(); | |||
} | |||
const auto format_index = std::to_underlying(format); | |||
const auto gl_internal_format = gl_format_lut[format_index][0]; | |||
if (!gl_internal_format) | |||
{ | |||
throw std::invalid_argument("Image view has unsupported format."); | |||
} | |||
if (!mip_level_count) | |||
{ | |||
throw std::invalid_argument("Image view has zero mip levels."); | |||
} | |||
if (first_mip_level + mip_level_count > image->get_mip_levels()) | |||
{ | |||
throw std::out_of_range("Image view mip range out of image mip range."); | |||
} | |||
if (!array_layer_count) | |||
{ | |||
throw std::invalid_argument("Image view has zero array layers."); | |||
} | |||
if (first_array_layer + array_layer_count > image->get_array_layers()) | |||
{ | |||
throw std::out_of_range("Image view array layer range out of image array layer range."); | |||
} | |||
if (dimensionality != image->get_dimensionality()) | |||
{ | |||
throw std::invalid_argument("Image view dimensionality must match image dimensionality."); | |||
} | |||
if (flags & std::to_underlying(image_view_flag::cube)) | |||
{ | |||
if (!image->is_cube_compatible()) | |||
{ | |||
throw std::invalid_argument("Cube image views must be constructed from cube-compatible images."); | |||
} | |||
if (array_layer_count % 6 != 0) | |||
{ | |||
throw std::invalid_argument("Cube image views array layer count must be a multiple of 6."); | |||
} | |||
} | |||
m_image = image; | |||
m_dimensionality = dimensionality; | |||
m_format = format; | |||
m_first_mip_level = first_mip_level; | |||
m_mip_level_count = mip_level_count; | |||
m_first_array_layer = first_array_layer; | |||
m_array_layer_count = array_layer_count; | |||
m_flags = flags; | |||
unsigned int gl_target = 0; | |||
switch (dimensionality) | |||
{ | |||
case 1: | |||
gl_target = is_array() ? GL_TEXTURE_1D_ARRAY : GL_TEXTURE_1D; | |||
break; | |||
case 2: | |||
if (is_cube()) | |||
{ | |||
gl_target = is_array() ? GL_TEXTURE_CUBE_MAP_ARRAY : GL_TEXTURE_CUBE_MAP; | |||
} | |||
else | |||
{ | |||
gl_target = is_array() ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D; | |||
} | |||
break; | |||
case 3: | |||
gl_target = GL_TEXTURE_3D; | |||
break; | |||
default: | |||
break; | |||
} | |||
glGenTextures(1, &m_gl_texture_name); | |||
glTextureView | |||
( | |||
m_gl_texture_name, | |||
gl_target, | |||
m_image->m_gl_texture_name, | |||
gl_internal_format, | |||
m_first_mip_level, | |||
m_mip_level_count, | |||
m_first_array_layer, | |||
m_array_layer_count | |||
); | |||
} | |||
image_view::~image_view() | |||
{ | |||
glDeleteTextures(1, &m_gl_texture_name); | |||
} | |||
image_view_1d::image_view_1d | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer | |||
): | |||
image_view | |||
( | |||
image, | |||
1, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
first_array_layer, | |||
1, | |||
0 | |||
) | |||
{} | |||
image_view_1d_array::image_view_1d_array | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer, | |||
std::uint32_t array_layer_count | |||
): | |||
image_view | |||
( | |||
image, | |||
1, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
first_array_layer, | |||
array_layer_count, | |||
std::to_underlying(image_view_flag::array) | |||
) | |||
{} | |||
image_view_2d::image_view_2d | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer | |||
): | |||
image_view | |||
( | |||
image, | |||
2, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
first_array_layer, | |||
1, | |||
0 | |||
) | |||
{} | |||
image_view_2d_array::image_view_2d_array | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer, | |||
std::uint32_t array_layer_count | |||
): | |||
image_view | |||
( | |||
image, | |||
2, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
first_array_layer, | |||
array_layer_count, | |||
std::to_underlying(image_view_flag::array) | |||
) | |||
{} | |||
image_view_3d::image_view_3d | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count | |||
): | |||
image_view | |||
( | |||
image, | |||
3, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
0, | |||
1, | |||
0 | |||
) | |||
{} | |||
image_view_cube::image_view_cube | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer | |||
): | |||
image_view | |||
( | |||
image, | |||
2, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
first_array_layer, | |||
6, | |||
std::to_underlying(image_view_flag::cube) | |||
) | |||
{} | |||
image_view_cube_array::image_view_cube_array | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer, | |||
std::uint32_t array_layer_count | |||
): | |||
image_view | |||
( | |||
image, | |||
2, | |||
format, | |||
first_mip_level, | |||
mip_level_count, | |||
first_array_layer, | |||
array_layer_count, | |||
std::to_underlying(image_view_flag::array) | std::to_underlying(image_view_flag::cube) | |||
) | |||
{} | |||
} // namespace gl |
@ -0,0 +1,292 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_IMAGE_VIEW_HPP | |||
#define ANTKEEPER_GL_IMAGE_VIEW_HPP | |||
#include <engine/gl/image.hpp> | |||
#include <engine/gl/image-view-flag.hpp> | |||
#include <cstdint> | |||
#include <memory> | |||
namespace gl { | |||
/** | |||
* Image view. | |||
*/ | |||
class image_view | |||
{ | |||
public: | |||
/// Destructs an image view. | |||
virtual ~image_view() = 0; | |||
image_view(const image_view&) = delete; | |||
image_view(image_view&&) = delete; | |||
image_view& operator=(const image_view&) = delete; | |||
image_view& operator=(image_view&&) = delete; | |||
/// Returns the image on which the view was created. | |||
[[nodiscard]] inline constexpr const std::shared_ptr<image>& get_image() const noexcept | |||
{ | |||
return m_image; | |||
} | |||
/// Returns the format and type used to interpret texel blocks of the image. | |||
[[nodiscard]] inline constexpr format get_format() const noexcept | |||
{ | |||
return m_format; | |||
} | |||
/// Returns the first mipmap level accessible to the view. | |||
[[nodiscard]] inline constexpr std::uint32_t get_first_mip_level() const noexcept | |||
{ | |||
return m_first_mip_level; | |||
} | |||
/// Returns the number of mipmap levels accessible to the view. | |||
[[nodiscard]] inline constexpr std::uint32_t get_mip_level_count() const noexcept | |||
{ | |||
return m_mip_level_count; | |||
} | |||
/// Returns the first array layer accessible to the view. | |||
[[nodiscard]] inline constexpr std::uint32_t get_first_array_layer() const noexcept | |||
{ | |||
return m_first_array_layer; | |||
} | |||
/// Returns the number of array layers accessible to the view. | |||
[[nodiscard]] inline constexpr std::uint32_t get_array_layer_count() const noexcept | |||
{ | |||
return m_array_layer_count; | |||
} | |||
/// Returns the dimensionality of the image view. | |||
[[nodiscard]] inline constexpr std::uint8_t get_dimensionality() const noexcept | |||
{ | |||
return m_dimensionality; | |||
} | |||
/// Returns `true` if the image view is 1D, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_1d() const noexcept | |||
{ | |||
return m_dimensionality == 1; | |||
} | |||
/// Returns `true` if the image view is 2D, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_2d() const noexcept | |||
{ | |||
return m_dimensionality == 2; | |||
} | |||
/// Returns `true` if the image view is 3D, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_3d() const noexcept | |||
{ | |||
return m_dimensionality == 3; | |||
} | |||
/// Returns `true` if the image view is an array view, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_array() const noexcept | |||
{ | |||
return m_flags & std::to_underlying(image_view_flag::array); | |||
} | |||
/// Returns `true` if the image view is a cube map view, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_cube() const noexcept | |||
{ | |||
return m_flags & std::to_underlying(image_view_flag::cube); | |||
} | |||
protected: | |||
/** | |||
* Constructs an image view from an image. | |||
* | |||
* @param image Image on which the view will be created. | |||
* @param dimensionality Image view dimensionality, on `[1, 3]`. | |||
* @param format Format and type used to interpret texel blocks of the image. If gl::format::undefined, the format will be set to the format of the image. | |||
* @param first_mip_level First mipmap level accessible to the view. | |||
* @param mip_level_count Number of mipmap levels accessible to the view. | |||
* @param first_array_layer First array layer accessible to the view. | |||
* @param array_layer Number of array layers accessible to the view. | |||
* @param flags Image view flags. | |||
* | |||
* @except std::invalid_argument Image view has null image. | |||
* @except std::invalid_argument Image view has unsupported format. | |||
* @except std::invalid_argument Image view has zero mip levels. | |||
* @except std::out_of_range Image view mip range out of image mip range. | |||
* @except std::invalid_argument Image view has zero array layers. | |||
* @except std::out_of_range Image view array layer range out of image array layer range. | |||
* @except std::invalid_argument Image view dimensionality must match image dimensionality. | |||
* @except std::invalid_argument Cube image views must be constructed from cube-compatible images. | |||
* @except std::invalid_argument Cube image views array layer count must be a multiple of 6. | |||
*/ | |||
image_view | |||
( | |||
std::shared_ptr<gl::image> image, | |||
std::uint8_t dimensionality, | |||
gl::format format, | |||
std::uint32_t first_mip_level, | |||
std::uint32_t mip_level_count, | |||
std::uint32_t first_array_layer, | |||
std::uint32_t array_layer_count, | |||
std::uint8_t flags | |||
); | |||
private: | |||
friend class framebuffer; | |||
friend class gl_shader_texture_1d; | |||
friend class gl_shader_texture_2d; | |||
friend class gl_shader_texture_3d; | |||
friend class gl_shader_texture_cube; | |||
unsigned int m_gl_texture_name{0}; | |||
std::shared_ptr<image> m_image; | |||
std::uint8_t m_dimensionality{0}; | |||
format m_format{format::undefined}; | |||
std::uint32_t m_first_mip_level{0}; | |||
std::uint32_t m_mip_level_count{0}; | |||
std::uint32_t m_first_array_layer{0}; | |||
std::uint32_t m_array_layer_count{0}; | |||
std::uint8_t m_flags{0}; | |||
}; | |||
/** | |||
* 1D image view. | |||
*/ | |||
class image_view_1d: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_1d | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1, | |||
std::uint32_t first_array_layer = 0 | |||
); | |||
}; | |||
/** | |||
* 1D image array view. | |||
*/ | |||
class image_view_1d_array: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_1d_array | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1, | |||
std::uint32_t first_array_layer = 0, | |||
std::uint32_t array_layer_count = 1 | |||
); | |||
}; | |||
/** | |||
* 2D image view. | |||
*/ | |||
class image_view_2d: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_2d | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1, | |||
std::uint32_t first_array_layer = 0 | |||
); | |||
}; | |||
/** | |||
* 2D image array view. | |||
*/ | |||
class image_view_2d_array: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_2d_array | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1, | |||
std::uint32_t first_array_layer = 0, | |||
std::uint32_t array_layer_count = 1 | |||
); | |||
}; | |||
/** | |||
* 3D image view. | |||
*/ | |||
class image_view_3d: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_3d | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1 | |||
); | |||
}; | |||
/** | |||
* Cube image view. | |||
*/ | |||
class image_view_cube: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_cube | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1, | |||
std::uint32_t first_array_layer = 0 | |||
); | |||
}; | |||
/** | |||
* Cube image array view. | |||
*/ | |||
class image_view_cube_array: public image_view | |||
{ | |||
public: | |||
/// @copydoc image_view::image_view | |||
image_view_cube_array | |||
( | |||
std::shared_ptr<gl::image> image, | |||
gl::format format = gl::format::undefined, | |||
std::uint32_t first_mip_level = 0, | |||
std::uint32_t mip_level_count = 1, | |||
std::uint32_t first_array_layer = 0, | |||
std::uint32_t array_layer_count = 6 | |||
); | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_IMAGE_VIEW_HPP |
@ -0,0 +1,324 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_IMAGE_HPP | |||
#define ANTKEEPER_GL_IMAGE_HPP | |||
#include <engine/gl/format.hpp> | |||
#include <engine/gl/image-flag.hpp> | |||
#include <array> | |||
#include <cstddef> | |||
#include <cstdint> | |||
#include <limits> | |||
#include <span> | |||
namespace gl { | |||
/** | |||
* | |||
*/ | |||
class image | |||
{ | |||
public: | |||
/// Destructs an image. | |||
virtual ~image() = 0; | |||
image(const image&) = delete; | |||
image(image&&) = delete; | |||
image& operator=(const image&) = delete; | |||
image& operator=(image&&) = delete; | |||
/** | |||
* Reads pixel data from the image. | |||
* | |||
* @param mip_level Level-of-detail number. Level `0` is the base image level. Level `n` is the nth mipmap reduction image. | |||
* @param offset_x Texel offset in the X-direction. | |||
* @param offset_y Texel offset in the Y-direction. | |||
* @param offset_z Texel offset in the Z-direction. | |||
* @param width Width of the subimage. | |||
* @param height Height of the subimage. | |||
* @param depth Depth of the subimage. | |||
* @param format Format of the image data. | |||
* @param data Buffer into which image data will be read. | |||
* | |||
* @except std::out_of_range Image read operation mip level out of range. | |||
* @except std::invalid_argument Image read operation used unsupported format. | |||
*/ | |||
void read | |||
( | |||
std::uint32_t mip_level, | |||
std::uint32_t offset_x, | |||
std::uint32_t offset_y, | |||
std::uint32_t offset_z, | |||
std::uint32_t width, | |||
std::uint32_t height, | |||
std::uint32_t depth, | |||
gl::format format, | |||
std::span<std::byte> data | |||
) const; | |||
/** | |||
* Writes pixel data to the image. | |||
* | |||
* @param mip_level Level-of-detail number. Level `0` is the base image level. Level `n` is the nth mipmap reduction image. | |||
* @param offset_x Texel offset in the X-direction. | |||
* @param offset_y Texel offset in the Y-direction. | |||
* @param offset_z Texel offset in the Z-direction. | |||
* @param width Width of the subimage. | |||
* @param height Height of the subimage. | |||
* @param depth Depth of the subimage. | |||
* @param format Format of the image data. | |||
* @param data Image data to write. | |||
* | |||
* @except std::out_of_range Image write operation mip level out of range. | |||
* @except std::invalid_argument Image write operation used unsupported format. | |||
* @except std::out_of_range Image write operation exceeded image bounds. | |||
*/ | |||
void write | |||
( | |||
std::uint32_t mip_level, | |||
std::uint32_t offset_x, | |||
std::uint32_t offset_y, | |||
std::uint32_t offset_z, | |||
std::uint32_t width, | |||
std::uint32_t height, | |||
std::uint32_t depth, | |||
gl::format format, | |||
std::span<const std::byte> data | |||
); | |||
/** | |||
* Copies pixel data from this image into another the image. | |||
* | |||
* @param src_mip_level Source image level-of-detail number. Level `0` is the base image level. Level `n` is the nth mipmap reduction image. | |||
* @param src_x Source image texel offset in the X-direction. | |||
* @param src_y Source image texel offset in the Y-direction. | |||
* @param src_z Source image texel offset in the Z-direction. | |||
* @param dst_image Destination image. | |||
* @param dst_mip_level Destination image level-of-detail number. Level `0` is the base image level. Level `n` is the nth mipmap reduction image. | |||
* @param dst_x Destination image texel offset in the X-direction. | |||
* @param dst_y Destination image texel offset in the Y-direction. | |||
* @param dst_z Destination image texel offset in the Z-direction. | |||
* @param width Width of the subimage to copy. | |||
* @param height Height of the subimage to copy. | |||
* @param depth Depth of the subimage to copy. | |||
*/ | |||
void copy | |||
( | |||
std::uint32_t src_mip_level, | |||
std::uint32_t src_x, | |||
std::uint32_t src_y, | |||
std::uint32_t src_z, | |||
image& dst_image, | |||
std::uint32_t dst_mip_level, | |||
std::uint32_t dst_x, | |||
std::uint32_t dst_y, | |||
std::uint32_t dst_z, | |||
std::uint32_t width, | |||
std::uint32_t height, | |||
std::uint32_t depth | |||
) const; | |||
/** | |||
* Generates mip subimages. | |||
*/ | |||
void generate_mipmaps(); | |||
/// Returns the dimensionality of the image. | |||
[[nodiscard]] inline constexpr std::uint8_t get_dimensionality() const noexcept | |||
{ | |||
return m_dimensionality; | |||
} | |||
/// Returns `true` if the image is 1D, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_1d() const noexcept | |||
{ | |||
return m_dimensionality == 1; | |||
} | |||
/// Returns `true` if the image is 2D, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_2d() const noexcept | |||
{ | |||
return m_dimensionality == 2; | |||
} | |||
/// Returns `true` if the image is 3D, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_3d() const noexcept | |||
{ | |||
return m_dimensionality == 3; | |||
} | |||
/// Returns the format and type of the texel blocks contained in the image. | |||
[[nodiscard]] inline constexpr format get_format() const noexcept | |||
{ | |||
return m_format; | |||
} | |||
/// Returns the dimensions of the image. | |||
[[nodiscard]] inline constexpr const std::array<std::uint32_t, 3>& get_dimensions() const noexcept | |||
{ | |||
return m_dimensions; | |||
} | |||
/// Returns the number of levels of detail available for minified sampling of the image. | |||
[[nodiscard]] inline constexpr std::uint32_t get_mip_levels() const noexcept | |||
{ | |||
return m_mip_levels; | |||
} | |||
/// Returns the number of layers in the image. | |||
[[nodiscard]] inline constexpr std::uint32_t get_array_layers() const noexcept | |||
{ | |||
return m_array_layers; | |||
} | |||
/// Returns the image flags. | |||
[[nodiscard]] inline constexpr std::uint8_t get_flags() const noexcept | |||
{ | |||
return m_flags; | |||
} | |||
/// Returns `true` if the image is cube map compatible, `false` otherwise. | |||
[[nodiscard]] inline constexpr bool is_cube_compatible() const noexcept | |||
{ | |||
return m_flags & std::to_underlying(image_flag::cube_compatible); | |||
} | |||
protected: | |||
/** | |||
* Constructs an image. | |||
* | |||
* @param dimensionality Image dimensionality, on `[1, 3]`. | |||
* @param format Format and type of the texel blocks that will be contained in the image. | |||
* @param width Width of the image. | |||
* @param height Height of the image. | |||
* @param depth Depth of the image. | |||
* @param mip_levels Number of levels of detail available for minified sampling of the image. | |||
* @param array_layers Number of layers in the image. | |||
* @param flags Image flags. | |||
* | |||
* @except std::invalid_argument Image constructed with unsupported format. | |||
* @except std::invalid_argument Image dimensions must be nonzero. | |||
* @except std::invalid_argument Image mip levels must be nonzero. | |||
* @except std::out_of_range Image mip levels exceed `1 + log2(max(width, height, depth))`. | |||
* @except std::invalid_argument Image array layers must be nonzero. | |||
* @except std::invalid_argument 1D image must have a height and depth of `1`. | |||
* @except std::invalid_argument 2D image must have a depth of `1`. | |||
* @except std::invalid_argument 3D image arrays not supported. | |||
* @except std::invalid_argument Cube compatible image must be 2D. | |||
* @except std::invalid_argument Cube compatible image width and height must be equal. | |||
* @except std::invalid_argument Cube compatible image array layers must be a multiple of 6. | |||
*/ | |||
image | |||
( | |||
std::uint8_t dimensionality, | |||
gl::format format, | |||
std::uint32_t width, | |||
std::uint32_t height, | |||
std::uint32_t depth, | |||
std::uint32_t mip_levels, | |||
std::uint32_t array_layers, | |||
std::uint32_t flags | |||
); | |||
private: | |||
unsigned int m_gl_texture_target{0}; | |||
unsigned int m_gl_texture_name{0}; | |||
std::uint8_t m_dimensionality{0}; | |||
format m_format{format::undefined}; | |||
std::array<std::uint32_t, 3> m_dimensions{0, 0, 0}; | |||
std::uint32_t m_mip_levels{0}; | |||
std::uint32_t m_array_layers{0}; | |||
std::uint8_t m_flags{0}; | |||
friend class image_view; | |||
}; | |||
/** | |||
* 1D image. | |||
*/ | |||
class image_1d: public image | |||
{ | |||
public: | |||
/// @copydoc image::image | |||
image_1d | |||
( | |||
gl::format format, | |||
std::uint32_t width, | |||
std::uint32_t mip_levels = 1, | |||
std::uint32_t array_layers = 1, | |||
std::uint32_t flags = 0 | |||
); | |||
}; | |||
/** | |||
* 2D image. | |||
*/ | |||
class image_2d: public image | |||
{ | |||
public: | |||
/// @copydoc image::image | |||
image_2d | |||
( | |||
gl::format format, | |||
std::uint32_t width, | |||
std::uint32_t height, | |||
std::uint32_t mip_levels = 1, | |||
std::uint32_t array_layers = 1, | |||
std::uint32_t flags = 0 | |||
); | |||
}; | |||
/** | |||
* 3D image. | |||
*/ | |||
class image_3d: public image | |||
{ | |||
public: | |||
/// @copydoc image::image | |||
image_3d | |||
( | |||
gl::format format, | |||
std::uint32_t width, | |||
std::uint32_t height, | |||
std::uint32_t depth, | |||
std::uint32_t mip_levels = 1, | |||
std::uint32_t flags = 0 | |||
); | |||
}; | |||
/** | |||
* Cube-compatible 2D image. | |||
*/ | |||
class image_cube: public image_2d | |||
{ | |||
public: | |||
/// @copydoc image_2d::image_2d | |||
image_cube | |||
( | |||
gl::format format, | |||
std::uint32_t width, | |||
std::uint32_t mip_levels = 1, | |||
std::uint32_t array_layers = 6 | |||
); | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_IMAGE_HPP |
@ -0,0 +1,42 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_INDEX_TYPE_HPP | |||
#define ANTKEEPER_GL_INDEX_TYPE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Index types for index buffers. | |||
enum class index_type: std::uint8_t | |||
{ | |||
/// 8-bit unsigned integer values. | |||
uint8, | |||
/// 16-bit unsigned integer values. | |||
uint16, | |||
/// 32-bit unsigned integer values. | |||
uint32 | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_INDEX_TYPE_HPP |
@ -0,0 +1,50 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_LOGIC_OP_HPP | |||
#define ANTKEEPER_GL_LOGIC_OP_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Framebuffer logical operations. | |||
enum class logic_op: std::uint8_t | |||
{ | |||
bitwise_clear, | |||
bitwise_and, | |||
bitwise_and_reverse, | |||
bitwise_copy, | |||
bitwise_and_inverted, | |||
bitwise_no_op, | |||
bitwise_xor, | |||
bitwise_or, | |||
bitwise_nor, | |||
bitwise_equivalent, | |||
bitwise_invert, | |||
bitwise_or_reverse, | |||
bitwise_copy_inverted, | |||
bitwise_or_inverted, | |||
bitwise_nand, | |||
bitwise_set, | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_LOGIC_OP_HPP |
@ -0,0 +1,219 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_GL_FORMAT_LUT_HPP | |||
#define ANTKEEPER_GL_GL_FORMAT_LUT_HPP | |||
#include <glad/gl.h> | |||
namespace gl { | |||
/// Maps gl::format to OpenGL internal format, base format, and pixel type. | |||
constexpr GLenum gl_format_lut[][3] = | |||
{ | |||
{0 , 0 , 0 }, // undefined | |||
{0 , GL_RG , 0 }, // r4g4_unorm_pack8 | |||
{GL_RGBA4 , GL_RGBA , GL_UNSIGNED_SHORT_4_4_4_4 }, // r4g4b4a4_unorm_pack16 | |||
{GL_RGBA4 , GL_BGRA , GL_UNSIGNED_SHORT_4_4_4_4 }, // b4g4r4a4_unorm_pack16 | |||
{GL_RGB565 , GL_RGB , GL_UNSIGNED_SHORT_5_6_5 }, // r5g6b5_unorm_pack16 | |||
{GL_RGB565 , GL_BGR , GL_UNSIGNED_SHORT_5_6_5 }, // b5g6r5_unorm_pack16 | |||
{GL_RGB5_A1 , GL_RGBA , GL_UNSIGNED_SHORT_5_5_5_1 }, // r5g5b5a1_unorm_pack16 | |||
{GL_RGB5_A1 , GL_BGRA , GL_UNSIGNED_SHORT_5_5_5_1 }, // b5g5r5a1_unorm_pack16 | |||
{GL_RGB5_A1 , GL_BGRA , GL_UNSIGNED_SHORT_1_5_5_5_REV }, // a1r5g5b5_unorm_pack16 | |||
{GL_R8 , GL_RED , GL_UNSIGNED_BYTE }, // r8_unorm | |||
{GL_R8_SNORM , GL_RED , GL_BYTE }, // r8_snorm | |||
{0 , GL_RED , GL_UNSIGNED_BYTE }, // r8_uscaled | |||
{0 , GL_RED , GL_BYTE }, // r8_sscaled | |||
{GL_R8UI , GL_RED_INTEGER , GL_UNSIGNED_BYTE }, // r8_uint | |||
{GL_R8I , GL_RED_INTEGER , GL_BYTE }, // r8_sint | |||
{0 , GL_RED , GL_UNSIGNED_BYTE }, // r8_srgb | |||
{GL_RG8 , GL_RG , GL_UNSIGNED_BYTE }, // r8g8_unorm | |||
{GL_RG8_SNORM , GL_RG , GL_BYTE }, // r8g8_snorm | |||
{0 , GL_RED , GL_UNSIGNED_BYTE }, // r8g8_uscaled | |||
{0 , GL_RED , GL_BYTE }, // r8g8_sscaled | |||
{GL_RG8UI , GL_RG_INTEGER , GL_UNSIGNED_BYTE }, // r8g8_uint | |||
{GL_RG8I , GL_RG_INTEGER , GL_BYTE }, // r8g8_sint | |||
{0 , GL_RG , GL_UNSIGNED_BYTE }, // r8g8_srgb | |||
{GL_RGB8 , GL_RGB , GL_UNSIGNED_BYTE }, // r8g8b8_unorm | |||
{GL_RGB8_SNORM , GL_RGB , GL_BYTE }, // r8g8b8_snorm | |||
{0 , GL_RED , GL_UNSIGNED_BYTE }, // r8g8b8_uscaled | |||
{0 , GL_RED , GL_BYTE }, // r8g8b8_sscaled | |||
{GL_RGB8UI , GL_RGB_INTEGER , GL_UNSIGNED_BYTE }, // r8g8b8_uint | |||
{GL_RGB8I , GL_RGB_INTEGER , GL_BYTE }, // r8g8b8_sint | |||
{GL_SRGB8 , GL_RGB , GL_UNSIGNED_BYTE }, // r8g8b8_srgb | |||
{GL_RGB8 , GL_BGR , GL_UNSIGNED_BYTE }, // b8g8r8_unorm | |||
{GL_RGB8_SNORM , GL_BGR , GL_BYTE }, // b8g8r8_snorm | |||
{0 , GL_BGR , GL_UNSIGNED_BYTE }, // b8g8r8_uscaled | |||
{0 , GL_BGR , GL_BYTE }, // b8g8r8_sscaled | |||
{GL_RGB8UI , GL_BGR_INTEGER , GL_UNSIGNED_BYTE }, // b8g8r8_uint | |||
{GL_RGB8I , GL_BGR_INTEGER , GL_BYTE }, // b8g8r8_sint | |||
{GL_SRGB8 , GL_BGR , GL_UNSIGNED_BYTE }, // b8g8r8_srgb | |||
{GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE }, // r8g8b8a8_unorm | |||
{GL_RGBA8_SNORM , GL_RGBA , GL_BYTE }, // r8g8b8a8_snorm | |||
{0 , GL_RGBA , GL_UNSIGNED_BYTE }, // r8g8b8a8_uscaled | |||
{0 , GL_RGBA , GL_BYTE }, // r8g8b8a8_sscaled | |||
{GL_RGBA8UI , GL_RGBA_INTEGER , GL_UNSIGNED_BYTE }, // r8g8b8a8_uint | |||
{GL_RGBA8I , GL_RGBA_INTEGER , GL_BYTE }, // r8g8b8a8_sint | |||
{GL_SRGB8_ALPHA8 , GL_RGBA , GL_UNSIGNED_BYTE }, // r8g8b8a8_srgb | |||
{GL_RGBA8 , GL_BGRA , GL_UNSIGNED_BYTE }, // b8g8r8a8_unorm | |||
{GL_RGBA8_SNORM , GL_BGRA , GL_BYTE }, // b8g8r8a8_snorm | |||
{0 , GL_BGRA , GL_UNSIGNED_BYTE }, // b8g8r8a8_uscaled | |||
{0 , GL_BGRA , GL_BYTE }, // b8g8r8a8_sscaled | |||
{GL_RGBA8UI , GL_BGRA_INTEGER , GL_UNSIGNED_BYTE }, // b8g8r8a8_uint | |||
{GL_RGBA8I , GL_BGRA_INTEGER , GL_BYTE }, // b8g8r8a8_sint | |||
{GL_SRGB8_ALPHA8 , GL_BGRA , GL_UNSIGNED_BYTE }, // b8g8r8a8_srgb | |||
{GL_RGBA8 , GL_RGBA , GL_UNSIGNED_INT_8_8_8_8_REV }, // a8b8g8r8_unorm_pack32 | |||
{GL_RGBA8_SNORM , GL_RGBA , 0 }, // a8b8g8r8_snorm_pack32 | |||
{0 , GL_RGBA , GL_UNSIGNED_INT_8_8_8_8_REV }, // a8b8g8r8_uscaled_pack32 | |||
{0 , GL_RGBA , 0 }, // a8b8g8r8_sscaled_pack32 | |||
{GL_RGBA8UI , GL_RGBA_INTEGER , GL_UNSIGNED_INT_8_8_8_8_REV }, // a8b8g8r8_uint_pack32 | |||
{GL_RGBA8I , GL_RGBA_INTEGER , 0 }, // a8b8g8r8_sint_pack32 | |||
{GL_SRGB8_ALPHA8 , GL_RGBA , GL_UNSIGNED_INT_8_8_8_8_REV }, // a8b8g8r8_srgb_pack32 | |||
{GL_RGB10_A2 , GL_BGRA , GL_UNSIGNED_INT_2_10_10_10_REV }, // a2r10g10b10_unorm_pack32 | |||
{0 , GL_BGRA , 0 }, // a2r10g10b10_snorm_pack32 | |||
{0 , GL_BGRA , GL_UNSIGNED_INT_2_10_10_10_REV }, // a2r10g10b10_uscaled_pack32 | |||
{0 , GL_BGRA , 0 }, // a2r10g10b10_sscaled_pack32 | |||
{GL_RGB10_A2UI , GL_BGRA_INTEGER , GL_UNSIGNED_INT_2_10_10_10_REV }, // a2r10g10b10_uint_pack32 | |||
{0 , GL_BGRA_INTEGER , 0 }, // a2r10g10b10_sint_pack32 | |||
{GL_RGB10_A2 , GL_RGBA , GL_UNSIGNED_INT_2_10_10_10_REV }, // a2b10g10r10_unorm_pack32 | |||
{0 , GL_RGBA , 0 }, // a2b10g10r10_snorm_pack32 | |||
{0 , GL_RGBA , GL_UNSIGNED_INT_2_10_10_10_REV }, // a2b10g10r10_uscaled_pack32 | |||
{0 , GL_RGBA , 0 }, // a2b10g10r10_sscaled_pack32 | |||
{GL_RGB10_A2UI , GL_RGBA_INTEGER , GL_UNSIGNED_INT_2_10_10_10_REV }, // a2b10g10r10_uint_pack32 | |||
{0 , GL_RGBA_INTEGER , 0 }, // a2b10g10r10_sint_pack32 | |||
{GL_R16 , GL_RED , GL_UNSIGNED_SHORT }, // r16_unorm | |||
{GL_R16_SNORM , GL_RED , GL_SHORT }, // r16_snorm | |||
{0 , GL_RED , GL_UNSIGNED_SHORT }, // r16_uscaled | |||
{0 , GL_RED , GL_SHORT }, // r16_sscaled | |||
{GL_R16UI , GL_RED_INTEGER , GL_UNSIGNED_SHORT }, // r16_uint | |||
{GL_R16I , GL_RED_INTEGER , GL_SHORT }, // r16_sint | |||
{GL_R16F , GL_RED , GL_HALF_FLOAT }, // r16_sfloat | |||
{GL_RG16 , GL_RG , GL_UNSIGNED_SHORT }, // r16g16_unorm | |||
{GL_RG16_SNORM , GL_RG , GL_SHORT }, // r16g16_snorm | |||
{0 , GL_RG , GL_UNSIGNED_SHORT }, // r16g16_uscaled | |||
{0 , GL_RG , GL_SHORT }, // r16g16_sscaled | |||
{GL_RG16UI , GL_RG_INTEGER , GL_UNSIGNED_SHORT }, // r16g16_uint | |||
{GL_RG16I , GL_RG_INTEGER , GL_SHORT }, // r16g16_sint | |||
{GL_RG16F , GL_RG , GL_HALF_FLOAT }, // r16g16_sfloat | |||
{GL_RGB16 , GL_RGB , GL_UNSIGNED_SHORT }, // r16g16b16_unorm | |||
{GL_RGB16_SNORM , GL_RGB , GL_SHORT }, // r16g16b16_snorm | |||
{0 , GL_RGB , GL_UNSIGNED_SHORT }, // r16g16b16_uscaled | |||
{0 , GL_RGB , GL_SHORT }, // r16g16b16_sscaled | |||
{GL_RGB16UI , GL_RGB_INTEGER , GL_UNSIGNED_SHORT }, // r16g16b16_uint | |||
{GL_RGB16I , GL_RGB_INTEGER , GL_SHORT }, // r16g16b16_sint | |||
{GL_RGB16F , GL_RGB , GL_HALF_FLOAT }, // r16g16b16_sfloat | |||
{GL_RGBA16 , GL_RGBA , GL_UNSIGNED_SHORT }, // r16g16b16a16_unorm | |||
{GL_RGBA16_SNORM , GL_RGBA , GL_SHORT }, // r16g16b16a16_snorm | |||
{0 , GL_RGBA , GL_UNSIGNED_SHORT }, // r16g16b16a16_uscaled | |||
{0 , GL_RGBA , GL_SHORT }, // r16g16b16a16_sscaled | |||
{GL_RGBA16UI , GL_RGBA_INTEGER , GL_UNSIGNED_SHORT }, // r16g16b16a16_uint | |||
{GL_RGBA16I , GL_RGBA_INTEGER , GL_SHORT }, // r16g16b16a16_sint | |||
{GL_RGBA16F , GL_RGBA , GL_HALF_FLOAT }, // r16g16b16a16_sfloat | |||
{GL_R32UI , GL_RED_INTEGER , GL_UNSIGNED_INT }, // r32_uint | |||
{GL_R32I , GL_RED_INTEGER , GL_INT }, // r32_sint | |||
{GL_R32F , GL_RED , GL_FLOAT }, // r32_sfloat | |||
{GL_RG32UI , GL_RG_INTEGER , GL_UNSIGNED_INT }, // r32g32_uint | |||
{GL_RG32I , GL_RG_INTEGER , GL_INT }, // r32g32_sint | |||
{GL_RG32F , GL_RG , GL_FLOAT }, // r32g32_sfloat | |||
{GL_RGB32UI , GL_RGB_INTEGER , GL_UNSIGNED_INT }, // r32g32b32_uint | |||
{GL_RGB32I , GL_RGB_INTEGER , GL_INT }, // r32g32b32_sint | |||
{GL_RGB32F , GL_RGB , GL_FLOAT }, // r32g32b32_sfloat | |||
{GL_RGBA32UI , GL_RGBA_INTEGER , GL_UNSIGNED_INT }, // r32g32b32a32_uint | |||
{GL_RGBA32I , GL_RGBA_INTEGER , GL_INT }, // r32g32b32a32_sint | |||
{GL_RGBA32F , GL_RGBA , GL_FLOAT }, // r32g32b32a32_sfloat | |||
{0 , GL_RED_INTEGER , 0 }, // r64_uint | |||
{0 , GL_RED_INTEGER , 0 }, // r64_sint | |||
{0 , GL_RED , GL_DOUBLE }, // r64_sfloat | |||
{0 , GL_RG_INTEGER , 0 }, // r64g64_uint | |||
{0 , GL_RG_INTEGER , 0 }, // r64g64_sint | |||
{0 , GL_RG , GL_DOUBLE }, // r64g64_sfloat | |||
{0 , GL_RGB_INTEGER , 0 }, // r64g64b64_uint | |||
{0 , GL_RGB_INTEGER , 0 }, // r64g64b64_sint | |||
{0 , GL_RGB , GL_DOUBLE }, // r64g64b64_sfloat | |||
{0 , GL_RGBA_INTEGER , 0 }, // r64g64b64a64_uint | |||
{0 , GL_RGBA_INTEGER , 0 }, // r64g64b64a64_sint | |||
{0 , GL_RGBA , GL_DOUBLE }, // r64g64b64a64_sfloat | |||
{GL_R11F_G11F_B10F , GL_BGR , GL_UNSIGNED_INT_10F_11F_11F_REV }, // b10g11r11_ufloat_pack32 | |||
{GL_RGB9_E5 , GL_BGR , GL_UNSIGNED_INT_5_9_9_9_REV }, // e5b9g9r9_ufloat_pack32 | |||
{GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT }, // d16_unorm | |||
{GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, // x8_d24_unorm_pack32 | |||
{GL_DEPTH_COMPONENT32F , GL_DEPTH_COMPONENT, GL_FLOAT }, // d32_sfloat | |||
{GL_STENCIL_INDEX8 , GL_STENCIL_INDEX , GL_UNSIGNED_BYTE }, // s8_uint | |||
{0 , GL_DEPTH_STENCIL , 0 }, // d16_unorm_s8_uint | |||
{GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8 }, // d24_unorm_s8_uint | |||
{GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL , GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, // d32_sfloat_s8_uint | |||
{0 , GL_RGB , 0 }, // bc1_rgb_unorm_block, | |||
{0 , GL_RGB , 0 }, // bc1_rgb_srgb_block, | |||
{0 , GL_RGBA , 0 }, // bc1_rgba_unorm_block, | |||
{0 , GL_RGBA , 0 }, // bc1_rgba_srgb_block, | |||
{0 , GL_RGBA , 0 }, // bc2_unorm_block, | |||
{0 , GL_RGBA , 0 }, // bc2_srgb_block, | |||
{0 , GL_RGBA , 0 }, // bc3_unorm_block, | |||
{0 , GL_RGBA , 0 }, // bc3_srgb_block, | |||
{GL_COMPRESSED_RED_RGTC1 , GL_RED , 0 }, // bc4_unorm_block, | |||
{GL_COMPRESSED_SIGNED_RED_RGTC1 , GL_RED , 0 }, // bc4_snorm_block, | |||
{GL_COMPRESSED_RG_RGTC2 , GL_RG , 0 }, // bc5_unorm_block, | |||
{GL_COMPRESSED_SIGNED_RG_RGTC2 , GL_RG , 0 }, // bc5_snorm_block, | |||
{GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT , GL_RGB , 0 }, // bc6h_ufloat_block, | |||
{GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT , GL_RGB , 0 }, // bc6h_sfloat_block, | |||
{GL_COMPRESSED_RGBA_BPTC_UNORM , GL_RGBA , 0 }, // bc7_unorm_block, | |||
{GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM , GL_RGBA , 0 }, // bc7_srgb_block, | |||
{GL_COMPRESSED_RGB8_ETC2 , GL_RGB , 0 }, // etc2_r8g8b8_unorm_block, | |||
{GL_COMPRESSED_SRGB8_ETC2 , GL_RGB , 0 }, // etc2_r8g8b8_srgb_block, | |||
{GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 , GL_RGBA , 0 }, // etc2_r8g8b8a1_unorm_block, | |||
{GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_RGBA , 0 }, // etc2_r8g8b8a1_srgb_block, | |||
{GL_COMPRESSED_RGBA8_ETC2_EAC , GL_RGBA , 0 }, // etc2_r8g8b8a8_unorm_block, | |||
{GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC , GL_RGBA , 0 }, // etc2_r8g8b8a8_srgb_block, | |||
{GL_COMPRESSED_R11_EAC , GL_RED , 0 }, // eac_r11_unorm_block, | |||
{GL_COMPRESSED_SIGNED_R11_EAC , GL_RED , 0 }, // eac_r11_snorm_block, | |||
{GL_COMPRESSED_RG11_EAC , GL_RG , 0 }, // eac_r11g11_unorm_block, | |||
{GL_COMPRESSED_SIGNED_RG11_EAC , GL_RG , 0 }, // eac_r11g11_snorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_4x4_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_4x4_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_5x4_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_5x4_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_5x5_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_5x5_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_6x5_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_6x5_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_6x6_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_6x6_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_8x5_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_8x5_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_8x6_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_8x6_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_8x8_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_8x8_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x5_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x5_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x6_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x6_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x8_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x8_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x10_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_10x10_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_12x10_unorm_block, | |||
{0 , GL_RGBA , 0 }, // astc_12x10_srgb_block, | |||
{0 , GL_RGBA , 0 }, // astc_12x12_unorm_block, | |||
{0 , GL_RGBA , 0 } // astc_12x12_srgb_block | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_GL_FORMAT_LUT_HPP |
@ -0,0 +1,62 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_COLOR_BLEND_STATE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_COLOR_BLEND_STATE_HPP | |||
#include <engine/gl/logic-op.hpp> | |||
#include <engine/gl/color-blend-equation.hpp> | |||
#include <array> | |||
#include <cstdlib> | |||
namespace gl { | |||
/// Pipeline color blend state. | |||
struct pipeline_color_blend_state | |||
{ | |||
/// Controls whether to apply logical operations. | |||
bool logic_op_enabled{false}; | |||
/// Selects which logical operation to apply. | |||
gl::logic_op logic_op{gl::logic_op::bitwise_copy}; | |||
/// Controls whether blending is enabled for the corresponding color attachment. | |||
bool blend_enabled{false}; | |||
/// Color blend factors and operations. | |||
gl::color_blend_equation color_blend_equation | |||
{ | |||
blend_factor::one, | |||
blend_factor::zero, | |||
blend_op::add, | |||
blend_factor::one, | |||
blend_factor::zero, | |||
blend_op::add | |||
}; | |||
/// Bitmask indicating which of the RGBA components are enabled for writing. | |||
std::uint8_t color_write_mask{0b1111}; | |||
/// RGBA components of the blend constant that are used in blending, depending on the blend factor. | |||
std::array<float, 4> blend_constants{0.0f, 0.0f, 0.0f, 0.0f}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_COLOR_BLEND_STATE_HPP |
@ -0,0 +1,57 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_DEPTH_STENCIL_STATE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_DEPTH_STENCIL_STATE_HPP | |||
#include <engine/gl/compare-op.hpp> | |||
#include <engine/gl/stencil-op-state.hpp> | |||
#include <cstdlib> | |||
namespace gl { | |||
/// Pipeline depth/stencil state. | |||
struct pipeline_depth_stencil_state | |||
{ | |||
/// `true` if depth testing is enabled, `false` otherwise. | |||
bool depth_test_enabled{true}; | |||
/** | |||
* `true` if depth writes are enabled when depth testing is enabled, `false` otherwise. | |||
* | |||
* @note Depth writes are always disabled when depth testing is disabled. | |||
*/ | |||
bool depth_write_enabled{true}; | |||
/// Comparison operator to use in the depth comparison step of the depth test. | |||
compare_op depth_compare_op{compare_op::less}; | |||
/// `true` if stencil testing is enabled, `false` otherwise. | |||
bool stencil_test_enabled{false}; | |||
/// Stencil testing parameters for front faces. | |||
stencil_op_state stencil_front; | |||
/// Stencil testing parameters for back faces. | |||
stencil_op_state stencil_back; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_DEPTH_STENCIL_STATE_HPP |
@ -0,0 +1,40 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_INPUT_ASSEMBLY_STATE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_INPUT_ASSEMBLY_STATE_HPP | |||
#include <engine/gl/primitive-topology.hpp> | |||
#include <cstdlib> | |||
namespace gl { | |||
/// Pipeline input assembly state. | |||
struct pipeline_input_assembly_state | |||
{ | |||
/// Primitive topology. | |||
primitive_topology topology{primitive_topology::triangle_list}; | |||
/// Controls whether a special vertex index value is treated as restarting the assembly of primitives. | |||
bool primitive_restart_enabled{false}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_INPUT_ASSEMBLY_STATE_HPP |
@ -0,0 +1,73 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_RASTERIZATION_STATE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_RASTERIZATION_STATE_HPP | |||
#include <engine/gl/front-face.hpp> | |||
#include <engine/gl/cull-mode.hpp> | |||
#include <engine/gl/fill-mode.hpp> | |||
#include <engine/gl/provoking-vertex-mode.hpp> | |||
#include <cstdlib> | |||
namespace gl { | |||
/// Pipeline rasterization state. | |||
struct pipeline_rasterization_state | |||
{ | |||
/// `true` if rasterizer discard should be enabled, `false` otherwise. | |||
bool rasterizer_discard_enabled{false}; | |||
/// Polygon rasterization mode. | |||
gl::fill_mode fill_mode{gl::fill_mode::fill}; | |||
/// Triangle culling mode. | |||
gl::cull_mode cull_mode{gl::cull_mode::back}; | |||
/// Polygon front-facing orientation. | |||
gl::front_face front_face{gl::front_face::counter_clockwise}; | |||
/// `true` if depth bias should be enabled, `false` otherwise. | |||
bool depth_bias_enabled{false}; | |||
/// Depth bias constant factor. | |||
float depth_bias_constant_factor{0.0f}; | |||
/// Depth bias slope factor. | |||
float depth_bias_slope_factor{0.0f}; | |||
/// `true` if depth clamp should be enabled, `false` otherwise. | |||
bool depth_clamp_enabled{false}; | |||
/// `true` if scissor testing should be enabled, `false` otherwise. | |||
bool scissor_test_enabled{false}; | |||
/// Vertex to be used as the source of data for flat-shaded varyings. | |||
gl::provoking_vertex_mode provoking_vertex_mode{gl::provoking_vertex_mode::last}; | |||
/// Diameter of rasterized points. | |||
float point_size{1.0f}; | |||
/// Width of rasterized line segments. | |||
float line_width{1.0f}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_RASTERIZATION_STATE_HPP |
@ -0,0 +1,41 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_VERTEX_INPUT_STATE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_VERTEX_INPUT_STATE_HPP | |||
#include <engine/gl/vertex-input-attribute.hpp> | |||
#include <engine/gl/vertex-input-binding.hpp> | |||
#include <vector> | |||
namespace gl { | |||
/// Pipeline input assembly state. | |||
struct pipeline_vertex_input_state | |||
{ | |||
/// Vertex bindings. | |||
std::vector<vertex_input_binding> vertex_bindings; | |||
/// Vertex attributes. | |||
std::vector<vertex_input_attribute> vertex_attributes; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_VERTEX_INPUT_STATE_HPP |
@ -0,0 +1,41 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_VIEWPORT_STATE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_VIEWPORT_STATE_HPP | |||
#include <engine/gl/viewport.hpp> | |||
#include <engine/gl/scissor-region.hpp> | |||
#include <vector> | |||
namespace gl { | |||
/// Pipeline viewport state. | |||
struct pipeline_viewport_state | |||
{ | |||
/// Active viewports. | |||
std::vector<viewport> viewports; | |||
/// Active scissor regions. | |||
std::vector<scissor_region> scissors; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_VIEWPORT_STATE_HPP |
@ -0,0 +1,435 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PIPELINE_HPP | |||
#define ANTKEEPER_GL_PIPELINE_HPP | |||
#include <engine/gl/pipeline-viewport-state.hpp> | |||
#include <engine/gl/pipeline-rasterization-state.hpp> | |||
#include <engine/gl/pipeline-depth-stencil-state.hpp> | |||
#include <engine/gl/pipeline-input-assembly-state.hpp> | |||
#include <engine/gl/pipeline-vertex-input-state.hpp> | |||
#include <engine/gl/pipeline-color-blend-state.hpp> | |||
#include <engine/gl/vertex-array.hpp> | |||
#include <engine/gl/vertex-buffer.hpp> | |||
#include <engine/gl/clear-value.hpp> | |||
#include <engine/gl/framebuffer.hpp> | |||
#include <engine/gl/shader-program.hpp> | |||
#include <engine/gl/clear-bits.hpp> | |||
#include <engine/gl/stencil-face-bits.hpp> | |||
#include <array> | |||
#include <cstdint> | |||
#include <span> | |||
namespace app { class sdl_window_manager; } | |||
namespace gl { | |||
/** | |||
* Graphics pipeline interface. | |||
*/ | |||
class pipeline | |||
{ | |||
public: | |||
/** | |||
* Constructs a pipeline. | |||
*/ | |||
pipeline(); | |||
/// @name Vertex input state | |||
/// @{ | |||
/** | |||
* Sets the vertex input. | |||
* | |||
* @param vertex_bindings Vertex bindings. | |||
* @param vertex_attributes Vertex attributes. | |||
*/ | |||
// void set_vertex_input(std::span<const vertex_input_binding> vertex_bindings, std::span<const vertex_input_attribute> vertex_attributes); | |||
void bind_framebuffer(const gl::framebuffer* framebuffer); | |||
void bind_shader_program(const gl::shader_program* shader_program); | |||
/** | |||
* Binds a vertex array. | |||
* | |||
* @param array Vertex array to bind. | |||
*/ | |||
void bind_vertex_array(const vertex_array* array); | |||
/** | |||
* Binds vertex buffers. | |||
* | |||
* @param first_binding Index of the first vertex input binding. | |||
* @param buffers Sequence of buffers to bind. | |||
* @param offsets Sequence of byte offsets into each buffer. | |||
* @param strides Sequence of byte strides between consecutive elements within each buffer. | |||
*/ | |||
void bind_vertex_buffers(std::uint32_t first_binding, std::span<const vertex_buffer* const> buffers, std::span<const std::size_t> offsets, std::span<const std::size_t> strides); | |||
/// @} | |||
/// @name Input assembly state | |||
/// @{ | |||
/** | |||
* Sets the primitive topology to use for drawing. | |||
* | |||
* @param topology Primitive topology to use for drawing. | |||
*/ | |||
void set_primitive_topology(primitive_topology topology); | |||
/** | |||
* Controls whether a special vertex index value is treated as restarting the assembly of primitives. | |||
* | |||
* @param enabled `true` if a special vertex index value should restart the assembly of primitives, `false` otherwise. | |||
*/ | |||
void set_primitive_restart_enabled(bool enabled); | |||
/// @} | |||
/// @name Viewport state | |||
/// @{ | |||
/** | |||
* Sets one or more viewports. | |||
* | |||
* @param first_viewport Index of the first viewport to set. | |||
* @param viewports Sequence of viewports. | |||
* | |||
* @except std::out_of_range Viewport index out of range. | |||
* | |||
* @warning Currently only a single viewport is supported. | |||
*/ | |||
void set_viewport(std::uint32_t first_viewport, std::span<const viewport> viewports); | |||
/** | |||
* Sets one or more scissor regions. | |||
* | |||
* @param first_scissor Index of the first scissor region to set. | |||
* @param scissors Sequence of scissor regions. | |||
* | |||
* @except std::out_of_range Scissor region index out of range. | |||
* | |||
* @warning Currently only a single scissor region is supported. | |||
*/ | |||
void set_scissor(std::uint32_t first_scissor, std::span<const scissor_region> scissors); | |||
/// @} | |||
/// @name Rasterizer state | |||
/// @{ | |||
/** | |||
* Controls whether primitives are discarded before the rasterization stage. | |||
* | |||
* @param enabled `true` if primitives should be discarded before the rasterization stage, `false` otherwise. | |||
*/ | |||
void set_rasterizer_discard_enabled(bool enabled); | |||
/** | |||
* Sets the polygon rasterization mode. | |||
* | |||
* @param mode Polygon rasterization mode. | |||
*/ | |||
void set_fill_mode(fill_mode mode); | |||
/** | |||
* Sets the triangle culling mode. | |||
* | |||
* @param mode Triangle culling mode. | |||
*/ | |||
void set_cull_mode(cull_mode mode); | |||
/** | |||
* Sets the front-facing triangle orientation. | |||
* | |||
* @param face Front-facing triangle orientation. | |||
*/ | |||
void set_front_face(front_face face); | |||
/** | |||
* Controls whether to bias fragment depth values. | |||
* | |||
* @param enabled `true` if fragment depth values should be biased, `false` otherwise. | |||
*/ | |||
void set_depth_bias_enabled(bool enabled); | |||
/** | |||
* Sets depth bias factors. | |||
* | |||
* @param constant_factor Scalar factor controlling the constant depth value added to each fragment. | |||
* @param slope_factor Scalar factor applied to a fragment's slope in depth bias calculations. | |||
*/ | |||
void set_depth_bias_factors(float constant_factor, float slope_factor); | |||
/** | |||
* Controls whether depth clamping is enabled. | |||
* | |||
* @param enabled `true` if depth clamping should be enabled, `false` otherwise. | |||
*/ | |||
void set_depth_clamp_enabled(bool enabled); | |||
/** | |||
* Enables or disables scissor testing. | |||
* | |||
* @param enabled `true` if scissor testing should be enabled, `false` otherwise. | |||
*/ | |||
void set_scissor_test_enabled(bool enabled); | |||
/** | |||
* Sets the vertex to be used as the source of data for flat-shaded varyings. | |||
* | |||
* @param mode Provoking vertex mode. | |||
*/ | |||
void set_provoking_vertex_mode(provoking_vertex_mode mode); | |||
/** | |||
* Sets the the diameter of rasterized points. | |||
* | |||
* @param size Point size. | |||
*/ | |||
void set_point_size(float size); | |||
/** | |||
* Sets the width of rasterized lines. | |||
* | |||
* @param width Width of rasterized line segments. | |||
*/ | |||
void set_line_width(float width); | |||
/// @} | |||
/// @name Depth/stencil state | |||
/// @{ | |||
/** | |||
* Controls whether depth testing is enabled. | |||
* | |||
* @param enabled `true` if depth testing should be enabled, `false` otherwise. | |||
*/ | |||
void set_depth_test_enabled(bool enabled); | |||
/** | |||
* Controls whether depth writes are enabled. | |||
* | |||
* @param enabled `true` if depth writes should be enabled when depth testing is enabled, `false` otherwise. | |||
* | |||
* @note Depth writes are always disabled when depth testing is disabled. | |||
*/ | |||
void set_depth_write_enabled(bool enabled); | |||
/** | |||
* Sets the depth comparison operator. | |||
* | |||
* @param compare_op Comparison operator to use in the depth comparison step of the depth test. | |||
*/ | |||
void set_depth_compare_op(gl::compare_op compare_op); | |||
/** | |||
* Controls whether stencil testing is enabled. | |||
* | |||
* @param enabled `true` if stencil testing should be enabled, `false` otherwise. | |||
*/ | |||
void set_stencil_test_enabled(bool enabled); | |||
/** | |||
* Sets the stencil operations. | |||
* | |||
* @param face_mask Bit mask specifying the set of stencil states for which to update the stencil operation. | |||
* @param fail_op Action performed on samples that fail the stencil test. | |||
* @param pass_op Action performed on samples that pass both the depth and stencil tests. | |||
* @param depth_fail_op Action performed on samples that pass the stencil test and fail the depth test. | |||
* @param compare_op Comparison operator used in the stencil test. | |||
*/ | |||
void set_stencil_op(std::uint8_t face_mask, stencil_op fail_op, stencil_op pass_op, stencil_op depth_fail_op, gl::compare_op compare_op); | |||
/** | |||
* Sets the stencil compare mask. | |||
* | |||
* @param face_mask Bit mask specifying the set of stencil states for which to update the compare mask. | |||
* @param compare_mask New value to use as the stencil compare mask. | |||
*/ | |||
void set_stencil_compare_mask(std::uint8_t face_mask, std::uint32_t compare_mask); | |||
/** | |||
* Sets the stencil reference value. | |||
* | |||
* @param face_mask Bit mask specifying the set of stencil states for which to update the reference value. | |||
* @param reference New value to use as the stencil reference value. | |||
*/ | |||
void set_stencil_reference(std::uint8_t face_mask, std::uint32_t reference); | |||
/** | |||
* Sets the stencil write mask. | |||
* | |||
* @param face_mask Bit mask specifying the set of stencil states for which to update the write mask. | |||
* @param write_mask New value to use as the stencil write mask. | |||
*/ | |||
void set_stencil_write_mask(std::uint8_t face_mask, std::uint32_t write_mask); | |||
/// @} | |||
/// @name Color blend state | |||
/// @{ | |||
/** | |||
* Controls whether whether logical operations are enabled. | |||
* | |||
* @param enabled `true` if logical operations should be enabled, `false` otherwise. | |||
*/ | |||
void set_logic_op_enabled(bool enabled); | |||
/** | |||
* Selects which logical operation to apply. | |||
* | |||
* @param logic_op Logical operation to apply. | |||
*/ | |||
void set_logic_op(gl::logic_op logic_op); | |||
/** | |||
* Controls whether blending is enabled for the corresponding color attachment. | |||
* | |||
* @param enabled `true` if color blending should be enabled, `false` otherwise. | |||
*/ | |||
void set_color_blend_enabled(bool enabled); | |||
/** | |||
* Sets the color blend factors and operations. | |||
* | |||
* @param equation Color blend factors and operations. | |||
*/ | |||
void set_color_blend_equation(const color_blend_equation& equation); | |||
/** | |||
* Sets the color write mask. | |||
* | |||
* @param mask Bitmask indicating which of the RGBA components are enabled for writing. | |||
*/ | |||
void set_color_write_mask(std::uint8_t mask); | |||
/** | |||
* Sets the values of the blend constants. | |||
* | |||
* @param blend_constants RGBA components of the blend constant that are used in blending, depending on the blend factor. | |||
*/ | |||
void set_blend_constants(const std::array<float, 4>& blend_constants); | |||
/// @} | |||
/// @name Drawing | |||
/// @{ | |||
/** | |||
* Draws primitives. | |||
* | |||
* @param vertex_count Number of vertices to draw. | |||
* @param instance_count Number of instances to draw. | |||
* @param first_vertex Index of the first vertex to draw. | |||
* @param first_instance Instance ID of the first instance to draw. (WARNING: not currently supported) | |||
* | |||
* @warning @p first_instance currently not supported. | |||
*/ | |||
void draw(std::uint32_t vertex_count, std::uint32_t instance_count, std::uint32_t first_vertex, std::uint32_t first_instance); | |||
/** | |||
* Draws primitives with indexed vertices. | |||
* | |||
* @param index_count Number of vertices to draw. | |||
* @param instance_count Number of instances to draw. | |||
* @param first_index Base index within the index buffer. | |||
* @param vertex_offset Value added to the vertex index before indexing into the vertex buffer. | |||
* @param first_instance Instance ID of the first instance to draw. (WARNING: not currently supported) | |||
* | |||
* @warning @p first_instance currently not supported. | |||
*/ | |||
void draw_indexed(std::uint32_t index_count, std::uint32_t instance_count, std::uint32_t first_index, std::int32_t vertex_offset, std::uint32_t first_instance); | |||
/// @} | |||
/// @name Clear | |||
/// @{ | |||
/** | |||
* Clears the color, depth, or stencil buffers of current attachments. | |||
* | |||
* @param mask Bit mask indicating which buffers should be cleared. | |||
* @param value Color, depth, and stencil values with which to fill the cleared attachments. | |||
*/ | |||
void clear_attachments(std::uint8_t mask, const clear_value& value); | |||
/// @} | |||
/// @name Limitations | |||
/// @{ | |||
/// Returns the dimensions of the default framebuffer. | |||
[[nodiscard]] inline constexpr const std::array<std::uint32_t, 2>& get_default_framebuffer_dimensions() const noexcept | |||
{ | |||
return m_default_framebuffer_dimensions; | |||
} | |||
/// Returns the maximum number of supported viewports. | |||
[[nodiscard]] inline constexpr std::uint32_t get_max_viewports() const noexcept | |||
{ | |||
return m_max_viewports; | |||
} | |||
/// Returns the maximum supported degree of sampler anisotropy. | |||
[[nodiscard]] inline constexpr float get_max_sampler_anisotropy() const noexcept | |||
{ | |||
return m_max_sampler_anisotropy; | |||
} | |||
/// @} | |||
private: | |||
friend class app::sdl_window_manager; | |||
/// Changes the reported dimensions of the default framebuffer. | |||
void defaut_framebuffer_resized(std::uint32_t width, std::uint32_t height) noexcept; | |||
void fetch_vertex_input_state(); | |||
void fetch_input_assembly_state(); | |||
void fetch_viewport_state(); | |||
void fetch_rasterization_state(); | |||
void fetch_depth_stencil_state(); | |||
void fetch_color_blend_state(); | |||
void fetch_clear_value(); | |||
std::uint32_t m_max_viewports{1}; | |||
float m_max_sampler_anisotropy{0.0f}; | |||
std::array<std::uint32_t, 2> m_default_framebuffer_dimensions{0, 0}; | |||
pipeline_vertex_input_state m_vertex_input_state; | |||
pipeline_input_assembly_state m_input_assembly_state; | |||
pipeline_viewport_state m_viewport_state; | |||
pipeline_rasterization_state m_rasterization_state; | |||
pipeline_depth_stencil_state m_depth_stencil_state; | |||
pipeline_color_blend_state m_color_blend_state; | |||
clear_value m_clear_value; | |||
const framebuffer* m_framebuffer{}; | |||
const shader_program* m_shader_program{}; | |||
const vertex_array* m_vertex_array{}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PIPELINE_HPP |
@ -0,0 +1,66 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PRIMITIVE_TOPOLOGY_HPP | |||
#define ANTKEEPER_GL_PRIMITIVE_TOPOLOGY_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Primitive topologies. | |||
enum class primitive_topology: std::uint8_t | |||
{ | |||
/// Separate point primitives. | |||
point_list, | |||
/// Separate line primitives. | |||
line_list, | |||
/// Connected line primitives with consecutive lines sharing a vertex. | |||
line_strip, | |||
/// Separate triangle primitives. | |||
triangle_list, | |||
/// Connected triangle primitives with consecutive triangles sharing an edge. | |||
triangle_strip, | |||
/// Connected triangle primitives with all triangles sharing a common vertex. | |||
triangle_fan, | |||
/// Separate line primitives with adjacency. | |||
line_list_with_adjacency, | |||
/// Connected line primitives with adjacency, with consecutive primitives sharing three vertices. | |||
line_strip_with_adjacency, | |||
/// Separate triangle primitives with adjacency. | |||
triangle_list_with_adjacency, | |||
/// Connected triangle primitives with adjacency, with consecutive triangles sharing an edge. | |||
triangle_strip_with_adjacency, | |||
/// Separate patch primitives. | |||
patch_list | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PRIMITIVE_TOPOLOGY_HPP |
@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_PROVOKING_VERTEX_MODE_HPP | |||
#define ANTKEEPER_GL_PROVOKING_VERTEX_MODE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Vertex to be used as the source of data for flat-shaded varyings. | |||
enum class provoking_vertex_mode: std::uint8_t | |||
{ | |||
/// Provoking vertex is the first non-adjacency vertex. | |||
first, | |||
/// Provoking vertex is the last non-adjacency vertex. | |||
last | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_PROVOKING_VERTEX_MODE_HPP |
@ -1,220 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/rasterizer.hpp> | |||
#include <engine/gl/framebuffer.hpp> | |||
#include <engine/gl/shader-program.hpp> | |||
#include <engine/gl/vertex-array.hpp> | |||
#include <glad/glad.h> | |||
#include <engine/debug/log.hpp> | |||
#include <stdexcept> | |||
namespace gl { | |||
static constexpr GLenum drawing_mode_lut[] = | |||
{ | |||
GL_POINTS, | |||
GL_LINE_STRIP, | |||
GL_LINE_LOOP, | |||
GL_LINES, | |||
GL_LINE_STRIP_ADJACENCY, | |||
GL_LINES_ADJACENCY, | |||
GL_TRIANGLE_STRIP, | |||
GL_TRIANGLE_FAN, | |||
GL_TRIANGLES, | |||
GL_TRIANGLE_STRIP_ADJACENCY, | |||
GL_TRIANGLES_ADJACENCY | |||
}; | |||
static constexpr GLenum element_array_type_lut[] = | |||
{ | |||
GL_UNSIGNED_BYTE, | |||
GL_UNSIGNED_SHORT, | |||
GL_UNSIGNED_INT | |||
}; | |||
rasterizer::rasterizer(): | |||
bound_vao(nullptr), | |||
bound_shader_program(nullptr) | |||
{ | |||
// Determine dimensions of default framebuffer | |||
GLint scissor_box[4] = {0, 0, 0, 0}; | |||
glGetIntegerv(GL_SCISSOR_BOX, scissor_box); | |||
// Setup default framebuffer | |||
default_framebuffer = std::make_unique<framebuffer>(); | |||
default_framebuffer->m_gl_framebuffer_id = 0; | |||
default_framebuffer->m_dimensions = {scissor_box[2], scissor_box[3]}; | |||
// Bind default framebuffer | |||
bound_framebuffer = default_framebuffer.get(); | |||
// Enable seamless filtering across cubemap faces | |||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); | |||
if (GLAD_GL_ARB_clip_control) | |||
{ | |||
// Improve depth buffer precision by setting depth range to `[0, 1]`. | |||
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); | |||
} | |||
else | |||
{ | |||
debug::log::error("glClipControl not supported"); | |||
throw std::runtime_error("glClipControl not supported"); | |||
} | |||
// glClipControl alternative for OpenGL < v4.5 (need to adjust shadow scale-bias matrix too) | |||
// glDepthRange(-1.0f, 1.0f); | |||
// Set clear depth to `0` for reversed depth | |||
glClearDepth(0.0f); | |||
glDisable(GL_MULTISAMPLE); | |||
dummy_vao = std::make_unique<gl::vertex_array>(); | |||
} | |||
rasterizer::~rasterizer() | |||
{} | |||
void rasterizer::context_resized(int width, int height) | |||
{ | |||
default_framebuffer->m_dimensions = {width, height}; | |||
} | |||
void rasterizer::use_framebuffer(const gl::framebuffer& framebuffer) | |||
{ | |||
if (bound_framebuffer != &framebuffer) | |||
{ | |||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.m_gl_framebuffer_id); | |||
bound_framebuffer = &framebuffer; | |||
} | |||
} | |||
void rasterizer::set_clear_color(float r, float g, float b, float a) | |||
{ | |||
glClearColor(r, g, b, a); | |||
} | |||
void rasterizer::set_clear_depth(float depth) | |||
{ | |||
glClearDepth(depth); | |||
} | |||
void rasterizer::set_clear_stencil(int s) | |||
{ | |||
glClearStencil(s); | |||
} | |||
void rasterizer::clear_framebuffer(bool color, bool depth, bool stencil) | |||
{ | |||
GLbitfield mask = 0; | |||
if (color) | |||
mask |= GL_COLOR_BUFFER_BIT; | |||
if (depth) | |||
mask |= GL_DEPTH_BUFFER_BIT; | |||
if (stencil) | |||
mask |= GL_STENCIL_BUFFER_BIT; | |||
glClear(mask); | |||
} | |||
void rasterizer::set_viewport(int x, int y, int width, int height) | |||
{ | |||
glViewport(x, y, static_cast<GLsizei>(width), static_cast<GLsizei>(height)); | |||
} | |||
void rasterizer::use_program(const shader_program& program) | |||
{ | |||
if (bound_shader_program != &program) | |||
{ | |||
glUseProgram(program.gl_program_id); | |||
bound_shader_program = &program; | |||
} | |||
} | |||
void rasterizer::draw_arrays(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count) | |||
{ | |||
GLenum gl_mode = drawing_mode_lut[static_cast<std::size_t>(mode)]; | |||
if (bound_vao != &vao) | |||
{ | |||
glBindVertexArray(vao.gl_array_id); | |||
bound_vao = &vao; | |||
} | |||
glDrawArrays(gl_mode, static_cast<GLint>(offset), static_cast<GLsizei>(count)); | |||
} | |||
void rasterizer::draw_arrays(drawing_mode mode, std::size_t offset, std::size_t count) | |||
{ | |||
GLenum gl_mode = drawing_mode_lut[static_cast<std::size_t>(mode)]; | |||
if (bound_vao != dummy_vao.get()) | |||
{ | |||
glBindVertexArray(dummy_vao->gl_array_id); | |||
bound_vao = dummy_vao.get(); | |||
} | |||
glDrawArrays(gl_mode, static_cast<GLint>(offset), static_cast<GLsizei>(count)); | |||
} | |||
void rasterizer::draw_arrays_instanced(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count, std::size_t instance_count) | |||
{ | |||
GLenum gl_mode = drawing_mode_lut[static_cast<std::size_t>(mode)]; | |||
if (bound_vao != &vao) | |||
{ | |||
glBindVertexArray(vao.gl_array_id); | |||
bound_vao = &vao; | |||
} | |||
glDrawArraysInstanced(gl_mode, static_cast<GLint>(offset), static_cast<GLsizei>(count), static_cast<GLsizei>(instance_count)); | |||
} | |||
void rasterizer::draw_elements(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count, element_array_type type) | |||
{ | |||
GLenum gl_mode = drawing_mode_lut[static_cast<std::size_t>(mode)]; | |||
GLenum gl_type = element_array_type_lut[static_cast<std::size_t>(type)]; | |||
if (bound_vao != &vao) | |||
{ | |||
glBindVertexArray(vao.gl_array_id); | |||
bound_vao = &vao; | |||
} | |||
glDrawElements(gl_mode, static_cast<GLsizei>(count), gl_type, reinterpret_cast<const GLvoid*>(offset)); | |||
} | |||
void rasterizer::draw_elements(drawing_mode mode, std::size_t offset, std::size_t count, element_array_type type) | |||
{ | |||
GLenum gl_mode = drawing_mode_lut[static_cast<std::size_t>(mode)]; | |||
GLenum gl_type = element_array_type_lut[static_cast<std::size_t>(type)]; | |||
if (bound_vao != dummy_vao.get()) | |||
{ | |||
glBindVertexArray(dummy_vao->gl_array_id); | |||
bound_vao = dummy_vao.get(); | |||
} | |||
glDrawElements(gl_mode, static_cast<GLsizei>(count), gl_type, reinterpret_cast<const GLvoid*>(offset)); | |||
} | |||
} // namespace gl |
@ -1,142 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_RASTERIZER_HPP | |||
#define ANTKEEPER_GL_RASTERIZER_HPP | |||
#include <engine/gl/drawing-mode.hpp> | |||
#include <engine/gl/element-array-type.hpp> | |||
#include <cstddef> | |||
#include <memory> | |||
namespace gl { | |||
class framebuffer; | |||
class vertex_array; | |||
class shader_program; | |||
/** | |||
* Interface to the OpenGL state and drawing functions. | |||
*/ | |||
class rasterizer | |||
{ | |||
public: | |||
/** | |||
* Creates a rasterizer. Warning: This must be called after an OpenGL context has been created. | |||
*/ | |||
rasterizer(); | |||
/// Destroys a rasterizer. | |||
~rasterizer(); | |||
/** | |||
* This should be called when the window associated with the OpenGL context is resized, and will effectively changed the reported dimensions of the default framebuffer. | |||
*/ | |||
void context_resized(int width, int height); | |||
/** | |||
* Sets the active framebuffer. | |||
* | |||
* @param framebuffer Framebuffer to use. | |||
*/ | |||
void use_framebuffer(const framebuffer& framebuffer); | |||
/** | |||
* Sets the color to be used when the color buffer of a framebuffer is cleared. | |||
* | |||
* @param r Red color component. | |||
* @param g Green color component. | |||
* @param b Blue color component. | |||
* @param a Alpha color component. | |||
*/ | |||
void set_clear_color(float r, float g, float b, float a); | |||
/** | |||
* Sets the depth value to be used when the depth buffer of a framebuffer is cleared. | |||
* | |||
* @param depth Depth value. | |||
*/ | |||
void set_clear_depth(float depth); | |||
/** | |||
* Sets the stencil value to be used when the stencil buffer of a framebuffer is cleared. | |||
* | |||
* @param s Stencil value. | |||
*/ | |||
void set_clear_stencil(int s); | |||
/** | |||
* Clears the buffers attached to a framebuffer. | |||
* | |||
* @param color Specifies whether the color buffer should be cleared. | |||
* @param depth Specifies whether the depth buffer should be cleared. | |||
* @param stencil Specifies whether the stencil buffer should be cleared. | |||
*/ | |||
void clear_framebuffer(bool color, bool depth, bool stencil); | |||
/** | |||
* Sets the active viewport. | |||
* | |||
* @param x X-coordinate of the viewport. | |||
* @param y Y-coordinate of the viewport. | |||
* @param width Width of the viewport. | |||
* @param height Height of the viewport. | |||
*/ | |||
void set_viewport(int x, int y, int width, int height); | |||
/** | |||
* Binds a shader program. | |||
* | |||
* @param program Shader program to bind. | |||
*/ | |||
void use_program(const shader_program& program); | |||
/** | |||
* | |||
*/ | |||
void draw_arrays(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count); | |||
void draw_arrays(drawing_mode mode, std::size_t offset, std::size_t count); | |||
void draw_arrays_instanced(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count, std::size_t instance_count); | |||
/** | |||
* | |||
*/ | |||
void draw_elements(const vertex_array& vao, drawing_mode mode, std::size_t offset, std::size_t count, element_array_type type); | |||
void draw_elements(drawing_mode mode, std::size_t offset, std::size_t count, element_array_type type); | |||
/** | |||
* Returns the default framebuffer associated with the OpenGL context of a window. | |||
*/ | |||
[[nodiscard]] inline const framebuffer& get_default_framebuffer() const noexcept | |||
{ | |||
return *default_framebuffer; | |||
} | |||
private: | |||
std::unique_ptr<framebuffer> default_framebuffer; | |||
std::unique_ptr<vertex_array> dummy_vao; | |||
const framebuffer* bound_framebuffer{nullptr}; | |||
const vertex_array* bound_vao{nullptr}; | |||
const shader_program* bound_shader_program{nullptr}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_RASTERIZER_HPP |
@ -0,0 +1,48 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_SAMPLER_ADDRESS_MODE_HPP | |||
#define ANTKEEPER_GL_SAMPLER_ADDRESS_MODE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Behaviors of sampling with texture coordinates outside an image. | |||
enum class sampler_address_mode: std::uint8_t | |||
{ | |||
/// Repeat wrap mode. | |||
repeat, | |||
/// Mirrored repeat wrap mode. | |||
mirrored_repeat, | |||
/// Clamp to edge wrap mode. | |||
clamp_to_edge, | |||
/// Clamp to border wrap mode. | |||
clamp_to_border, | |||
/// Mirror clamp to edge wrap mode. | |||
mirror_clamp_to_edge | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_SAMPLER_ADDRESS_MODE_HPP |
@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_SAMPLER_MIPMAP_MODE_HPP | |||
#define ANTKEEPER_GL_SAMPLER_MIPMAP_MODE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Mipmap modes used for texture lookups. | |||
enum class sampler_mipmap_mode: std::uint8_t | |||
{ | |||
/// Nearest filtering. | |||
nearest, | |||
/// Linear filtering. | |||
linear | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_SAMPLER_MIPMAP_MODE_HPP |
@ -0,0 +1,230 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/sampler.hpp> | |||
#include <glad/gl.h> | |||
namespace gl { | |||
namespace | |||
{ | |||
static constexpr GLenum mag_filter_lut[] = | |||
{ | |||
GL_NEAREST, // sampler_filter::nearest | |||
GL_LINEAR // sampler_filter::linear | |||
}; | |||
static constexpr GLenum min_filter_lut[][2] = | |||
{ | |||
{ | |||
GL_NEAREST_MIPMAP_NEAREST, // sampler_filter::nearest, sampler_mipmap_mode::nearest | |||
GL_NEAREST_MIPMAP_LINEAR // sampler_filter::nearest, sampler_mipmap_mode::linear | |||
}, | |||
{ | |||
GL_LINEAR_MIPMAP_NEAREST, // sampler_filter::linear, sampler_mipmap_mode::nearest | |||
GL_LINEAR_MIPMAP_LINEAR // sampler_filter::linear, sampler_mipmap_mode::linear | |||
}, | |||
}; | |||
static constexpr GLenum wrap_lut[] = | |||
{ | |||
GL_REPEAT, // sampler_address_mode::repeat | |||
GL_MIRRORED_REPEAT, // sampler_address_mode::mirrored_repeat | |||
GL_CLAMP_TO_EDGE, // sampler_address_mode::clamp_to_edge | |||
GL_CLAMP_TO_BORDER, // sampler_address_mode::clamp_to_border | |||
GL_MIRROR_CLAMP_TO_EDGE // sampler_address_mode::mirror_clamp_to_edge | |||
}; | |||
static constexpr GLenum compare_func_lut[] = | |||
{ | |||
GL_NEVER, // compare_op::never | |||
GL_LESS, // compare_op::less | |||
GL_EQUAL, // compare_op::equal | |||
GL_LEQUAL, // compare_op::less_or_equal | |||
GL_GREATER, // compare_op::greater | |||
GL_NOTEQUAL, // compare_op::not_equal | |||
GL_GEQUAL, // compare_op::greater_or_equal | |||
GL_ALWAYS // compare_op::always | |||
}; | |||
} | |||
sampler::sampler | |||
( | |||
sampler_filter mag_filter, | |||
sampler_filter min_filter, | |||
sampler_mipmap_mode mipmap_mode, | |||
sampler_address_mode address_mode_u, | |||
sampler_address_mode address_mode_v, | |||
sampler_address_mode address_mode_w, | |||
float mip_lod_bias, | |||
float max_anisotropy, | |||
bool compare_enabled, | |||
gl::compare_op compare_op, | |||
float min_lod, | |||
float max_lod, | |||
const std::array<float, 4>& border_color | |||
) | |||
{ | |||
glCreateSamplers(1, &m_gl_named_sampler); | |||
set_mag_filter(mag_filter); | |||
set_min_filter(min_filter); | |||
set_mipmap_mode(mipmap_mode); | |||
set_address_mode_u(address_mode_u); | |||
set_address_mode_v(address_mode_v); | |||
set_address_mode_w(address_mode_w); | |||
set_mip_lod_bias(mip_lod_bias); | |||
set_max_anisotropy(max_anisotropy); | |||
set_compare_enabled(compare_enabled); | |||
set_compare_op(compare_op); | |||
set_min_lod(min_lod); | |||
set_max_lod(max_lod); | |||
set_border_color(border_color); | |||
} | |||
sampler::~sampler() | |||
{ | |||
glDeleteSamplers(1, &m_gl_named_sampler); | |||
} | |||
void sampler::set_mag_filter(sampler_filter filter) | |||
{ | |||
if (m_mag_filter != filter) | |||
{ | |||
m_mag_filter = filter; | |||
const auto gl_mag_filter = mag_filter_lut[std::to_underlying(m_mag_filter)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_MAG_FILTER, gl_mag_filter); | |||
} | |||
} | |||
void sampler::set_min_filter(sampler_filter filter) | |||
{ | |||
if (m_min_filter != filter) | |||
{ | |||
m_min_filter = filter; | |||
const auto gl_min_filter = min_filter_lut[std::to_underlying(m_min_filter)][std::to_underlying(m_mipmap_mode)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_MIN_FILTER, gl_min_filter); | |||
} | |||
} | |||
void sampler::set_mipmap_mode(sampler_mipmap_mode mode) | |||
{ | |||
if (m_mipmap_mode != mode) | |||
{ | |||
m_mipmap_mode = mode; | |||
const auto gl_min_filter = min_filter_lut[std::to_underlying(m_min_filter)][std::to_underlying(m_mipmap_mode)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_MIN_FILTER, gl_min_filter); | |||
} | |||
} | |||
void sampler::set_address_mode_u(sampler_address_mode mode) | |||
{ | |||
if (m_address_mode_u != mode) | |||
{ | |||
m_address_mode_u = mode; | |||
const auto gl_wrap_s = wrap_lut[std::to_underlying(m_address_mode_u)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_WRAP_S, gl_wrap_s); | |||
} | |||
} | |||
void sampler::set_address_mode_v(sampler_address_mode mode) | |||
{ | |||
if (m_address_mode_v != mode) | |||
{ | |||
m_address_mode_v = mode; | |||
const auto gl_wrap_t = wrap_lut[std::to_underlying(m_address_mode_v)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_WRAP_T, gl_wrap_t); | |||
} | |||
} | |||
void sampler::set_address_mode_w(sampler_address_mode mode) | |||
{ | |||
if (m_address_mode_w != mode) | |||
{ | |||
m_address_mode_w = mode; | |||
const auto gl_wrap_r = wrap_lut[std::to_underlying(m_address_mode_w)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_WRAP_R, gl_wrap_r); | |||
} | |||
} | |||
void sampler::set_mip_lod_bias(float bias) | |||
{ | |||
if (m_mip_lod_bias != bias) | |||
{ | |||
m_mip_lod_bias = bias; | |||
glSamplerParameterf(m_gl_named_sampler, GL_TEXTURE_LOD_BIAS, m_mip_lod_bias); | |||
} | |||
} | |||
void sampler::set_max_anisotropy(float anisotropy) | |||
{ | |||
if (m_max_anisotropy != anisotropy) | |||
{ | |||
m_max_anisotropy = anisotropy; | |||
glSamplerParameterf(m_gl_named_sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_max_anisotropy); | |||
} | |||
} | |||
void sampler::set_compare_enabled(bool enabled) | |||
{ | |||
if (m_compare_enabled != enabled) | |||
{ | |||
m_compare_enabled = enabled; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_COMPARE_MODE, (m_compare_enabled) ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE); | |||
} | |||
} | |||
void sampler::set_compare_op(gl::compare_op op) | |||
{ | |||
if (m_compare_op != op) | |||
{ | |||
m_compare_op = op; | |||
const auto gl_compare_func = compare_func_lut[std::to_underlying(m_compare_op)]; | |||
glSamplerParameteri(m_gl_named_sampler, GL_TEXTURE_COMPARE_FUNC, gl_compare_func); | |||
} | |||
} | |||
void sampler::set_min_lod(float lod) | |||
{ | |||
if (m_min_lod != lod) | |||
{ | |||
m_min_lod = lod; | |||
glSamplerParameterf(m_gl_named_sampler, GL_TEXTURE_MIN_LOD, m_min_lod); | |||
} | |||
} | |||
void sampler::set_max_lod(float lod) | |||
{ | |||
if (m_max_lod != lod) | |||
{ | |||
m_max_lod = lod; | |||
glSamplerParameterf(m_gl_named_sampler, GL_TEXTURE_MAX_LOD, m_max_lod); | |||
} | |||
} | |||
void sampler::set_border_color(const std::array<float, 4>& color) | |||
{ | |||
if (m_border_color != color) | |||
{ | |||
m_border_color = color; | |||
glSamplerParameterfv(m_gl_named_sampler, GL_TEXTURE_BORDER_COLOR, m_border_color.data()); | |||
} | |||
} | |||
} // namespace gl |
@ -0,0 +1,274 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_SAMPLER_HPP | |||
#define ANTKEEPER_GL_SAMPLER_HPP | |||
#include <engine/gl/sampler-filter.hpp> | |||
#include <engine/gl/sampler-mipmap-mode.hpp> | |||
#include <engine/gl/sampler-address-mode.hpp> | |||
#include <engine/gl/compare-op.hpp> | |||
#include <array> | |||
namespace gl { | |||
/** | |||
* Sampler object. | |||
*/ | |||
class sampler | |||
{ | |||
public: | |||
/** | |||
* Constructs a sampler object. | |||
* | |||
* @param mag_filter Magnification filter to apply to lookups. | |||
* @param min_filter Minification filter to apply to lookups. | |||
* @param mipmap_mode Mipmap filter to apply to lookups. | |||
* @param address_mode_u Addressing mode for U-coordinates outside `[0, 1)`. | |||
* @param address_mode_v Addressing mode for V-coordinates outside `[0, 1)`. | |||
* @param address_mode_w Addressing mode for W-coordinates outside `[0, 1)`. | |||
* @param mip_lod_bias Bias to be added to mipmap LOD calculation. | |||
* @param max_anisotropy Anisotropy clamp value. | |||
* @param compare_enabled `true` to enable comparison against a reference value during lookups, `false` otherwise. | |||
* @param compare_op Comparison operator to apply to fetched data, if compare is enabled. | |||
* @param min_lod Minimum clamp value of the computed LOD. | |||
* @param max_lod Maximum clamp value of the computed LOD. | |||
* @param border_color Border color used for texture lookups. | |||
*/ | |||
explicit sampler | |||
( | |||
sampler_filter mag_filter = sampler_filter::linear, | |||
sampler_filter min_filter = sampler_filter::nearest, | |||
sampler_mipmap_mode mipmap_mode = sampler_mipmap_mode::linear, | |||
sampler_address_mode address_mode_u = sampler_address_mode::repeat, | |||
sampler_address_mode address_mode_v = sampler_address_mode::repeat, | |||
sampler_address_mode address_mode_w = sampler_address_mode::repeat, | |||
float mip_lod_bias = 0.0f, | |||
float max_anisotropy = 0.0f, | |||
bool compare_enabled = false, | |||
gl::compare_op compare_op = gl::compare_op::less, | |||
float min_lod = -1000.0f, | |||
float max_lod = 1000.0f, | |||
const std::array<float, 4>& border_color = {0.0f, 0.0f, 0.0f, 0.0f} | |||
); | |||
/// Destroys a sampler object. | |||
~sampler(); | |||
sampler(const sampler&) = delete; | |||
sampler(sampler&&) = delete; | |||
sampler& operator=(const sampler&) = delete; | |||
sampler& operator=(sampler&&) = delete; | |||
/** | |||
* Sets the magnification filter to apply to lookups. | |||
* | |||
* @param filter Magnification filter to apply to lookups. | |||
*/ | |||
void set_mag_filter(sampler_filter filter); | |||
/** | |||
* Sets the minification filter to apply to lookups. | |||
* | |||
* @param filter Minification filter to apply to lookups. | |||
*/ | |||
void set_min_filter(sampler_filter filter); | |||
/** | |||
* Sets the mipmap filter to apply to lookups. | |||
* | |||
* @param mode Mipmap filter to apply to lookups. | |||
*/ | |||
void set_mipmap_mode(sampler_mipmap_mode mode); | |||
/** | |||
* Sets the addressing mode for U-coordinates outside `[0, 1)`. | |||
* | |||
* @param Addressing mode for U-coordinates outside `[0, 1)`. | |||
*/ | |||
void set_address_mode_u(sampler_address_mode mode); | |||
/** | |||
* Sets the addressing mode for V-coordinates outside `[0, 1)`. | |||
* | |||
* @param Addressing mode for V-coordinates outside `[0, 1)`. | |||
*/ | |||
void set_address_mode_v(sampler_address_mode mode); | |||
/** | |||
* Sets the addressing mode for W-coordinates outside `[0, 1)`. | |||
* | |||
* @param Addressing mode for W-coordinates outside `[0, 1)`. | |||
*/ | |||
void set_address_mode_w(sampler_address_mode mode); | |||
/** | |||
* Sets the bias to be added to mipmap LOD calculation. | |||
* | |||
* @param bias Bias to be added to mipmap LOD calculation. | |||
*/ | |||
void set_mip_lod_bias(float bias); | |||
/** | |||
* Sets the anisotropy clamp value. | |||
* | |||
* @param anisotropy Anisotropy clamp value. | |||
*/ | |||
void set_max_anisotropy(float anisotropy); | |||
/** | |||
* Enables or disables a comparison against a reference value during lookups. | |||
* | |||
* @param enabled `true` to enable comparison against a reference value during lookups, `false` otherwise. | |||
*/ | |||
void set_compare_enabled(bool enabled); | |||
/** | |||
* Sets the comparison operator to apply to fetched data, if compare is enabled. | |||
* | |||
* @param op Comparison operator to apply to fetched data, if compare is enabled. | |||
*/ | |||
void set_compare_op(gl::compare_op op); | |||
/** | |||
* Sets the minimum clamp value of the computed LOD. | |||
* | |||
* @param lod Minimum clamp value of the computed LOD. | |||
*/ | |||
void set_min_lod(float lod); | |||
/** | |||
* Sets the maximum clamp value of the computed LOD. | |||
* | |||
* @param lod Maximum clamp value of the computed LOD. | |||
*/ | |||
void set_max_lod(float lod); | |||
/** | |||
* Sets the border color used for texture lookups. | |||
* | |||
* @param color Border color used for texture lookups. | |||
*/ | |||
void set_border_color(const std::array<float, 4>& color); | |||
/// Returns the magnification filter to apply to lookups. | |||
[[nodiscard]] inline constexpr sampler_filter get_mag_filter() const noexcept | |||
{ | |||
return m_mag_filter; | |||
} | |||
/// Returns the minification filter to apply to lookups. | |||
[[nodiscard]] inline constexpr sampler_filter get_min_filter() const noexcept | |||
{ | |||
return m_min_filter; | |||
} | |||
/// Returns the mipmap filter to apply to lookups. | |||
[[nodiscard]] inline constexpr sampler_mipmap_mode get_mipmap_mode() const noexcept | |||
{ | |||
return m_mipmap_mode; | |||
} | |||
/// Returns the addressing mode for U-coordinates outside `[0, 1)`. | |||
[[nodiscard]] inline constexpr sampler_address_mode get_address_mode_u() const noexcept | |||
{ | |||
return m_address_mode_u; | |||
} | |||
/// Returns the addressing mode for V-coordinates outside `[0, 1)`. | |||
[[nodiscard]] inline constexpr sampler_address_mode get_address_mode_v() const noexcept | |||
{ | |||
return m_address_mode_v; | |||
} | |||
/// Returns the addressing mode for W-coordinates outside `[0, 1)`. | |||
[[nodiscard]] inline constexpr sampler_address_mode get_address_mode_w() const noexcept | |||
{ | |||
return m_address_mode_w; | |||
} | |||
/// Returns the bias to be added to mipmap LOD calculation. | |||
[[nodiscard]] inline constexpr float get_mip_lod_bias() const noexcept | |||
{ | |||
return m_mip_lod_bias; | |||
} | |||
/// Returns the anisotropy clamp value. | |||
[[nodiscard]] inline constexpr float get_max_anisotropy() const noexcept | |||
{ | |||
return m_max_anisotropy; | |||
} | |||
/// Returns `true` if comparison against a reference value during lookups is enabled, `false` otherwise. | |||
[[nodiscard]] inline constexpr float get_compare_enabled() const noexcept | |||
{ | |||
return m_compare_enabled; | |||
} | |||
/// Returns the comparison operator to apply to fetched data, if compare is enabled. | |||
[[nodiscard]] inline constexpr compare_op get_compare_op() const noexcept | |||
{ | |||
return m_compare_op; | |||
} | |||
/// Returns the minimum clamp value of the computed LOD. | |||
[[nodiscard]] inline constexpr float get_min_lod() const noexcept | |||
{ | |||
return m_min_lod; | |||
} | |||
/// Returns the maximum clamp value of the computed LOD. | |||
[[nodiscard]] inline constexpr float get_max_lod() const noexcept | |||
{ | |||
return m_max_lod; | |||
} | |||
/// Returns the border color used for texture lookups. | |||
[[nodiscard]] inline constexpr const std::array<float, 4>& get_border_color() const noexcept | |||
{ | |||
return m_border_color; | |||
} | |||
private: | |||
friend class pipeline; | |||
friend class gl_shader_texture_1d; | |||
friend class gl_shader_texture_2d; | |||
friend class gl_shader_texture_3d; | |||
friend class gl_shader_texture_cube; | |||
unsigned int m_gl_named_sampler{0}; | |||
sampler_filter m_mag_filter{sampler_filter::linear}; | |||
sampler_filter m_min_filter{sampler_filter::nearest}; | |||
sampler_mipmap_mode m_mipmap_mode{sampler_mipmap_mode::linear}; | |||
sampler_address_mode m_address_mode_u{sampler_address_mode::repeat}; | |||
sampler_address_mode m_address_mode_v{sampler_address_mode::repeat}; | |||
sampler_address_mode m_address_mode_w{sampler_address_mode::repeat}; | |||
float m_mip_lod_bias{0.0f}; | |||
float m_max_anisotropy{0.0f}; | |||
bool m_compare_enabled{false}; | |||
gl::compare_op m_compare_op{gl::compare_op::less}; | |||
float m_min_lod{-1000.0f}; | |||
float m_max_lod{1000.0f}; | |||
std::array<float, 4> m_border_color{0.0f, 0.0f, 0.0f, 0.0f}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_SAMPLER_HPP |
@ -0,0 +1,42 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_STENCIL_FACE_BITS_HPP | |||
#define ANTKEEPER_GL_STENCIL_FACE_BITS_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Stencil face mask bits specifying which stencil state(s) to update. | |||
enum: std::uint8_t | |||
{ | |||
/// Only the front set of stencil state is updated. | |||
stencil_face_front_bit = 0b01, | |||
/// Only the back set of stencil state is updated. | |||
stencil_face_back_bit = 0b10, | |||
/// Both sets of stencil state are updated. | |||
stencil_face_front_and_back = 0b11, | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_STENCIL_FACE_BITS_HPP |
@ -0,0 +1,56 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_STENCIL_OP_STATE_HPP | |||
#define ANTKEEPER_GL_STENCIL_OP_STATE_HPP | |||
#include <engine/gl/compare-op.hpp> | |||
#include <engine/gl/stencil-op.hpp> | |||
#include <cstdint> | |||
namespace gl { | |||
/// Stencil operation state. | |||
struct stencil_op_state | |||
{ | |||
/// Action performed on samples that fail the stencil test. | |||
stencil_op fail_op{stencil_op::keep}; | |||
/// Action performed on samples that pass both the depth and stencil tests. | |||
stencil_op pass_op{stencil_op::keep}; | |||
/// Action performed on samples that pass the stencil test and fail the depth test. | |||
stencil_op depth_fail_op{stencil_op::keep}; | |||
/// Comparison operator used in the stencil test. | |||
gl::compare_op compare_op{gl::compare_op::always}; | |||
/// Bits of the unsigned integer stencil values participating in the stencil test. | |||
std::uint32_t compare_mask{0xffffffff}; | |||
/// Bits of the unsigned integer stencil values updated by the stencil test in the stencil framebuffer attachment. | |||
std::uint32_t write_mask{0xffffffff}; | |||
/// Stencil reference value that is used in the unsigned stencil comparison. | |||
std::uint32_t reference{0}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_STENCIL_OP_STATE_HPP |
@ -0,0 +1,57 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_STENCIL_OP_HPP | |||
#define ANTKEEPER_GL_STENCIL_OP_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Stencil comparison functions. | |||
enum class stencil_op: std::uint8_t | |||
{ | |||
/// Keeps the current value. | |||
keep, | |||
/// Sets the value to `0`. | |||
zero, | |||
/// Sets the value to `reference`. | |||
replace, | |||
/// Increments the current value and clamps to the maximum representable unsigned value. | |||
increment_and_clamp, | |||
/// Decrements the current value and clamps to `0`. | |||
decrement_and_clamp, | |||
/// Bitwise-inverts the current value. | |||
invert, | |||
/// Increments the current value and wraps to `0` when the maximum value would have been exceeded. | |||
increment_and_wrap, | |||
/// Decrements the current value and wraps to the maximum possible value when the value would go below `0`. | |||
decrement_and_wrap | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_STENCIL_OP_HPP |
@ -1,38 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/texture-1d.hpp> | |||
namespace gl { | |||
texture_1d::texture_1d(std::uint16_t width, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data): | |||
texture(width, false, type, format, transfer_function, data) | |||
{} | |||
void texture_1d::resize(std::uint16_t width, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) | |||
{ | |||
texture::resize(width, type, format, transfer_function, data); | |||
} | |||
void texture_1d::set_wrapping(gl::texture_wrapping wrap_s) | |||
{ | |||
texture::set_wrapping(wrap_s); | |||
} | |||
} // namespace gl |
@ -1,49 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_TEXTURE_1D_HPP | |||
#define ANTKEEPER_GL_TEXTURE_1D_HPP | |||
#include <engine/gl/texture.hpp> | |||
namespace gl { | |||
/** | |||
* A 1D texture which can be uploaded to shaders via shader inputs. | |||
*/ | |||
class texture_1d: public texture | |||
{ | |||
public: | |||
explicit texture_1d(std::uint16_t width, gl::pixel_type type = gl::pixel_type::uint_8, gl::pixel_format format = gl::pixel_format::rgba, gl::transfer_function transfer_function = gl::transfer_function::linear, const std::byte* data = nullptr); | |||
[[nodiscard]] inline constexpr texture_type get_texture_type() const noexcept override | |||
{ | |||
return texture_type::one_dimensional; | |||
} | |||
/// @copydoc texture::resize(std::uint16_t, gl::pixel_type, gl::pixel_format, gl::transfer_function, const std::byte*) | |||
virtual void resize(std::uint16_t width, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data); | |||
/// @copydoc texture::set_wrapping(gl::texture_wrapping) | |||
virtual void set_wrapping(gl::texture_wrapping wrap_s); | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_TEXTURE_1D_HPP |
@ -1,43 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/texture-2d.hpp> | |||
namespace gl { | |||
texture_2d::texture_2d(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data): | |||
texture(width, height, false, type, format, transfer_function, data) | |||
{} | |||
void texture_2d::resize(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) | |||
{ | |||
texture::resize(width, height, type, format, transfer_function, data); | |||
} | |||
void texture_2d::resize(std::uint16_t width, std::uint16_t height, const std::byte* data) | |||
{ | |||
texture::resize(width, height, get_pixel_type(), get_pixel_format(), get_transfer_function(), data); | |||
} | |||
void texture_2d::set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t) | |||
{ | |||
texture::set_wrapping(wrap_s, wrap_t); | |||
} | |||
} // namespace gl |
@ -1,58 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_TEXTURE_2D_HPP | |||
#define ANTKEEPER_GL_TEXTURE_2D_HPP | |||
#include <engine/gl/texture.hpp> | |||
namespace gl { | |||
/** | |||
* A 2D texture which can be uploaded to shaders via shader inputs. | |||
*/ | |||
class texture_2d: public texture | |||
{ | |||
public: | |||
texture_2d(std::uint16_t width, std::uint16_t height, gl::pixel_type type = gl::pixel_type::uint_8, gl::pixel_format format = gl::pixel_format::rgba, gl::transfer_function transfer_function = gl::transfer_function::linear, const std::byte* data = nullptr); | |||
[[nodiscard]] inline constexpr texture_type get_texture_type() const noexcept override | |||
{ | |||
return texture_type::two_dimensional; | |||
} | |||
/// @copydoc texture::resize(std::uint16_t, std::uint16_t, gl::pixel_type, gl::pixel_format, gl::transfer_function, const std::byte*) | |||
void resize(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) override; | |||
/** | |||
* Resizes the texture. | |||
* | |||
* @param width Texture width, in pixels. | |||
* @param height Texture height, in pixels. | |||
* @param data Pointer to pixel data. | |||
*/ | |||
void resize(std::uint16_t width, std::uint16_t height, const std::byte* data); | |||
/// @copydoc texture::set_wrapping(gl::texture_wrapping, gl::texture_wrapping) | |||
void set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t) override; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_TEXTURE_2D_HPP |
@ -1,38 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/texture-3d.hpp> | |||
namespace gl { | |||
texture_3d::texture_3d(std::uint16_t width, std::uint16_t height, std::uint16_t depth, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data): | |||
texture(width, height, depth, false, type, format, transfer_function, data) | |||
{} | |||
void texture_3d::resize(std::uint16_t width, std::uint16_t height, std::uint16_t depth, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) | |||
{ | |||
texture::resize(width, height, depth, type, format, transfer_function, data); | |||
} | |||
void texture_3d::set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t, texture_wrapping wrap_r) | |||
{ | |||
texture::set_wrapping(wrap_s, wrap_t, wrap_r); | |||
} | |||
} // namespace gl |
@ -1,49 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_TEXTURE_3D_HPP | |||
#define ANTKEEPER_GL_TEXTURE_3D_HPP | |||
#include <engine/gl/texture.hpp> | |||
namespace gl { | |||
/** | |||
* A 3D texture which can be uploaded to shaders via shader inputs. | |||
*/ | |||
class texture_3d: public texture | |||
{ | |||
public: | |||
texture_3d(std::uint16_t width, std::uint16_t height, std::uint16_t depth, gl::pixel_type type = gl::pixel_type::uint_8, gl::pixel_format format = gl::pixel_format::rgba, gl::transfer_function transfer_function = gl::transfer_function::linear, const std::byte* data = nullptr); | |||
[[nodiscard]] inline constexpr texture_type get_texture_type() const noexcept override | |||
{ | |||
return texture_type::three_dimensional; | |||
} | |||
/// @copydoc texture::resize(std::uint16_t, std::uint16_t, std::uint16_t, gl::pixel_type, gl::pixel_format, gl::transfer_function, const std::byte*) | |||
virtual void resize(std::uint16_t width, std::uint16_t height, std::uint16_t depth, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data); | |||
/// @copydoc texture::set_wrapping(gl::texture_wrapping, gl::texture_wrapping, gl::texture_wrapping) | |||
virtual void set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t, texture_wrapping wrap_r); | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_TEXTURE_3D_HPP |
@ -1,110 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include <engine/gl/texture-cube.hpp> | |||
#include <cmath> | |||
namespace gl { | |||
cube_map_layout texture_cube::infer_cube_map_layout(std::uint16_t w, std::uint16_t h) noexcept | |||
{ | |||
if (h == w * 6) | |||
{ | |||
return cube_map_layout::column; | |||
} | |||
else if (w == h * 6) | |||
{ | |||
return cube_map_layout::row; | |||
} | |||
else if (w == (h / 4) * 3) | |||
{ | |||
return cube_map_layout::vertical_cross; | |||
} | |||
else if (h == (w / 4) * 3) | |||
{ | |||
return cube_map_layout::horizontal_cross; | |||
} | |||
else if (w == h * 2) | |||
{ | |||
return cube_map_layout::equirectangular; | |||
} | |||
else if (w == h) | |||
{ | |||
return cube_map_layout::spherical; | |||
} | |||
return {}; | |||
} | |||
std::uint16_t texture_cube::infer_cube_map_face_size(cube_map_layout layout, std::uint16_t w, std::uint16_t h) noexcept | |||
{ | |||
switch (layout) | |||
{ | |||
case cube_map_layout::column: | |||
case cube_map_layout::spherical: | |||
return w; | |||
case cube_map_layout::row: | |||
return h; | |||
case cube_map_layout::vertical_cross: | |||
return h / 4; | |||
case cube_map_layout::horizontal_cross: | |||
case cube_map_layout::equirectangular: | |||
return w / 4; | |||
default: | |||
return 0; | |||
} | |||
} | |||
texture_cube::texture_cube(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data): | |||
texture(width, height, true, type, format, transfer_function, data) | |||
{ | |||
resized(); | |||
} | |||
void texture_cube::resize(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) | |||
{ | |||
texture::resize(width, height, type, format, transfer_function, data); | |||
resized(); | |||
} | |||
void texture_cube::resize(std::uint16_t width, std::uint16_t height, const std::byte* data) | |||
{ | |||
texture::resize(width, height, get_pixel_type(), get_pixel_format(), get_transfer_function(), data); | |||
resized(); | |||
} | |||
void texture_cube::set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t, texture_wrapping wrap_r) | |||
{ | |||
texture::set_wrapping(wrap_s, wrap_t, wrap_r); | |||
} | |||
void texture_cube::resized() | |||
{ | |||
const auto w = get_width(); | |||
const auto h = get_height(); | |||
const auto layout = infer_cube_map_layout(w, h); | |||
m_face_size = infer_cube_map_face_size(layout, w, h); | |||
m_mip_count = 1 + static_cast<std::uint16_t>(std::log2(m_face_size)); | |||
} | |||
} // namespace gl |
@ -1,92 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_TEXTURE_CUBE_HPP | |||
#define ANTKEEPER_GL_TEXTURE_CUBE_HPP | |||
#include <engine/gl/texture.hpp> | |||
#include <engine/gl/cube-map-layout.hpp> | |||
namespace gl { | |||
/** | |||
* A cube texture which can be uploaded to shaders via shader inputs. | |||
*/ | |||
class texture_cube: public texture | |||
{ | |||
public: | |||
/** | |||
* Infers the layout of a cube map from its aspect ratio. | |||
* | |||
* @param w Width of the cube map, in pixels. | |||
* @param h Height of the cube map, in pixels. | |||
* | |||
* @return Inferred cube map layout. | |||
*/ | |||
[[nodiscard]] static cube_map_layout infer_cube_map_layout(std::uint16_t w, std::uint16_t h) noexcept; | |||
/** | |||
* Infers the edge length of a cube map face from its layout and resolution. | |||
* | |||
* @param layout Layout of the cube map. | |||
* @param w Width of the cube map, in pixels. | |||
* @param h Height of the cube map, in pixels. | |||
* | |||
* @return Edge length of the cube map faces, in pixels. | |||
*/ | |||
[[nodiscard]] static std::uint16_t infer_cube_map_face_size(cube_map_layout layout, std::uint16_t w, std::uint16_t h) noexcept; | |||
/// Constructs a cube texture. | |||
texture_cube(std::uint16_t width, std::uint16_t height, gl::pixel_type type = gl::pixel_type::uint_8, gl::pixel_format format = gl::pixel_format::rgba, gl::transfer_function transfer_function = gl::transfer_function::linear, const std::byte* data = nullptr); | |||
[[nodiscard]] inline constexpr texture_type get_texture_type() const noexcept override | |||
{ | |||
return texture_type::cube; | |||
} | |||
/// @copydoc texture::resize(std::uint16_t, std::uint16_t, gl::pixel_type, gl::pixel_format, gl::transfer_function, const std::byte*) | |||
void resize(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) override; | |||
/** | |||
* Resizes the texture. | |||
* | |||
* @param width Texture width, in pixels. | |||
* @param height Texture height, in pixels. | |||
* @param data Pointer to pixel data. | |||
*/ | |||
void resize(std::uint16_t width, std::uint16_t height, const std::byte* data); | |||
/// @copydoc texture::set_wrapping(gl::texture_wrapping, gl::texture_wrapping, gl::texture_wrapping) | |||
virtual void set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t, texture_wrapping wrap_r); | |||
/// Returns the edge length of the cube texture faces, in pixels. | |||
[[nodiscard]] inline std::uint16_t get_face_size() const noexcept | |||
{ | |||
return m_face_size; | |||
} | |||
private: | |||
void resized(); | |||
std::uint16_t m_face_size{}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_TEXTURE_CUBE_HPP |
@ -1,72 +0,0 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_VERTEX_ATTRIBUTE_HPP | |||
#define ANTKEEPER_GL_VERTEX_ATTRIBUTE_HPP | |||
#include <cstddef> | |||
#include <cstdint> | |||
namespace gl { | |||
class vertex_buffer; | |||
enum class vertex_attribute_type: std::uint8_t | |||
{ | |||
int_8, | |||
uint_8, | |||
int_16, | |||
uint_16, | |||
int_32, | |||
uint_32, | |||
float_16, | |||
float_32, | |||
float_64 | |||
}; | |||
/** | |||
* Describes a vertex attribute within a vertex buffer. | |||
* | |||
* @see gl::vertex_buffer | |||
* @see gl::vertex_array | |||
*/ | |||
struct vertex_attribute | |||
{ | |||
/// Pointer to the vertex buffer containing vertex attribute data. | |||
const vertex_buffer* buffer{nullptr}; | |||
/// Offset to the first component of the first instance of this attribute in the vertex buffer, in bytes. | |||
std::size_t offset{0}; | |||
/// Number of bytes between consecutive instances of this attribute in the vertex buffer. A value of `0` indicates attribute instances are tightly packed. | |||
std::size_t stride{0}; | |||
/// Data type of each component in the attribute. | |||
vertex_attribute_type type{0}; | |||
/// Number of components per attribute instance. Supported values are `1`, `2`, `3`, and `4`. | |||
std::uint8_t components{0}; | |||
/// `true` if fixed point data should be normalized, `false` otherwise. | |||
bool normalized{}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_VERTEX_ATTRIBUTE_HPP |
@ -0,0 +1,43 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_VERTEX_INPUT_BINDING_HPP | |||
#define ANTKEEPER_GL_VERTEX_INPUT_BINDING_HPP | |||
#include <engine/gl/vertex-input-rate.hpp> | |||
#include <cstdint> | |||
namespace gl { | |||
/// Vertex input binding. | |||
struct vertex_input_binding | |||
{ | |||
/// Binding number that this structure describes. | |||
std::uint32_t binding{0}; | |||
/// Byte stride between consecutive elements within the buffer. | |||
std::uint32_t stride{0}; | |||
/// Specifies whether vertex attribute addressing is a function of the vertex index or of the instance index. | |||
vertex_input_rate input_rate{vertex_input_rate::vertex}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_VERTEX_INPUT_BINDING_HPP |
@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_VERTEX_INPUT_RATE_HPP | |||
#define ANTKEEPER_GL_VERTEX_INPUT_RATE_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/// Rate at which vertex attributes are pulled from buffers. | |||
enum class vertex_input_rate: std::uint8_t | |||
{ | |||
/// Vertex attribute addressing is a function of the vertex index. | |||
vertex, | |||
/// Vertex attribute addressing is a function of the instance index. | |||
instance | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_VERTEX_INPUT_RATE_HPP |
@ -0,0 +1,53 @@ | |||
/* | |||
* Copyright (C) 2023 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GL_VIEWPORT_HPP | |||
#define ANTKEEPER_GL_VIEWPORT_HPP | |||
#include <cstdint> | |||
namespace gl { | |||
/** | |||
* Viewport position, dimensions, and depth range. | |||
*/ | |||
struct viewport | |||
{ | |||
/// X-coordinate of the viewport's lower left corner. | |||
float x{0.0f}; | |||
/// Y-coordinate of the viewport's lower left corner. | |||
float y{0.0f}; | |||
/// Width of the viewport. | |||
float width{0.0f}; | |||
/// Height of the viewport. | |||
float height{0.0f}; | |||
/// Minimum depth range of the viewport. | |||
float min_depth{0.0f}; | |||
/// Maximum depth range of the viewport. | |||
float max_depth{1.0f}; | |||
}; | |||
} // namespace gl | |||
#endif // ANTKEEPER_GL_VIEWPORT_HPP |