Add cubemap textures
This commit is contained in:
parent
d88799f308
commit
6b6d7687a9
2 changed files with 79 additions and 1 deletions
|
|
@ -66,7 +66,7 @@ namespace psemek::gfx
|
||||||
void repeat();
|
void repeat();
|
||||||
void clamp();
|
void clamp();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
GLuint id_;
|
GLuint id_;
|
||||||
geom::vector<std::size_t, D> size_;
|
geom::vector<std::size_t, D> size_;
|
||||||
|
|
||||||
|
|
@ -85,6 +85,64 @@ namespace psemek::gfx
|
||||||
extern template struct basic_texture<3, gl::TEXTURE_2D_ARRAY>;
|
extern template struct basic_texture<3, gl::TEXTURE_2D_ARRAY>;
|
||||||
extern template struct basic_texture<3, gl::TEXTURE_3D>;
|
extern template struct basic_texture<3, gl::TEXTURE_3D>;
|
||||||
|
|
||||||
|
extern template struct basic_texture<2, gl::TEXTURE_CUBE_MAP>;
|
||||||
|
|
||||||
|
struct texture_cubemap
|
||||||
|
: basic_texture<2, gl::TEXTURE_CUBE_MAP>
|
||||||
|
{
|
||||||
|
texture_cubemap() = default;
|
||||||
|
texture_cubemap(texture_cubemap &&) = default;
|
||||||
|
texture_cubemap & operator = (texture_cubemap &&) = default;
|
||||||
|
~texture_cubemap() = default;
|
||||||
|
|
||||||
|
texture_cubemap(texture_cubemap const &) = delete;
|
||||||
|
texture_cubemap & operator = (texture_cubemap const &) = delete;
|
||||||
|
|
||||||
|
static texture_cubemap null()
|
||||||
|
{
|
||||||
|
return basic_texture<2, gl::TEXTURE_CUBE_MAP>::null();
|
||||||
|
}
|
||||||
|
|
||||||
|
static GLenum face_to_gl(int f);
|
||||||
|
|
||||||
|
void load(int f, GLint internal_format, geom::vector<std::size_t, 2> const & size, GLenum format, GLenum type, const void * data);
|
||||||
|
|
||||||
|
template <typename Pixel>
|
||||||
|
void load(int f, geom::vector<std::size_t, 2> const & size, Pixel const * data = nullptr)
|
||||||
|
{
|
||||||
|
using traits = pixel_traits<Pixel>;
|
||||||
|
load(f, traits::internal_format, size, traits::format, traits::type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Pixel>
|
||||||
|
void load(int f, util::array<Pixel, 2> const & p)
|
||||||
|
{
|
||||||
|
geom::vector<std::size_t, 2> size;
|
||||||
|
for (std::size_t i = 0; i < 2; ++i) size[i] = p.dim(i);
|
||||||
|
load(f, size, p.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void pixels(int f, GLenum format, GLenum type, void * data) const;
|
||||||
|
|
||||||
|
template <typename Pixmap>
|
||||||
|
Pixmap pixels(int f) const
|
||||||
|
{
|
||||||
|
using traits = pixel_traits<typename Pixmap::value_type>;
|
||||||
|
|
||||||
|
std::array<std::size_t, 2> size;
|
||||||
|
for (std::size_t i = 0; i < 2; ++i) size[i] = size_[i];
|
||||||
|
|
||||||
|
Pixmap p(size);
|
||||||
|
pixels(f, traits::format, traits::type, p.data());
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
texture_cubemap(basic_texture<2, gl::TEXTURE_CUBE_MAP> t)
|
||||||
|
: basic_texture<2, gl::TEXTURE_CUBE_MAP>(std::move(t))
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
std::optional<float> max_anisotropy();
|
std::optional<float> max_anisotropy();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ namespace psemek::gfx
|
||||||
template struct basic_texture<3, gl::TEXTURE_2D_ARRAY>;
|
template struct basic_texture<3, gl::TEXTURE_2D_ARRAY>;
|
||||||
template struct basic_texture<3, gl::TEXTURE_3D>;
|
template struct basic_texture<3, gl::TEXTURE_3D>;
|
||||||
|
|
||||||
|
template struct basic_texture<2, gl::TEXTURE_CUBE_MAP>;
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -31,4 +33,22 @@ namespace psemek::gfx
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void texture_cubemap::load(int f, GLint internal_format, geom::vector<std::size_t, 2> const & size, GLenum format, GLenum type, const void * data)
|
||||||
|
{
|
||||||
|
bind();
|
||||||
|
gl::TexImage2D(face_to_gl(f), 0, internal_format, size[0], size[1], 0, format, type, data);
|
||||||
|
size_ = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void texture_cubemap::pixels(int f, GLenum format, GLenum type, void * data) const
|
||||||
|
{
|
||||||
|
bind();
|
||||||
|
gl::GetTexImage(face_to_gl(f), 0, format, type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLenum texture_cubemap::face_to_gl(int f)
|
||||||
|
{
|
||||||
|
return gl::TEXTURE_CUBE_MAP_POSITIVE_X + f;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue