demotool/ui-texture.hh

125 lines
2.8 KiB
C++
Raw Normal View History

2017-09-30 12:59:04 +02:00
#pragma once
#include "c-renderdefs.hh"
2017-09-30 12:59:04 +02:00
struct T_OutputDebugger;
/*----------------------------------------------------------------------------*/
2017-09-30 12:59:04 +02:00
struct T_Texture
{
friend struct T_OutputDebugger;
2017-09-30 12:59:04 +02:00
T_Texture( ) = delete;
T_Texture( T_Texture const& ) = delete;
T_Texture( T_Texture&& ) = delete;
T_Texture(
2017-11-03 09:08:19 +01:00
const uint32_t width ,
const uint32_t height ,
const E_TexType type ,
const uint32_t levels = 1 );
2017-09-30 12:59:04 +02:00
~T_Texture( );
T_Texture& samplingMode(
2017-11-03 09:08:19 +01:00
const E_TexSampling mode );
T_Texture& wrap(
2017-11-03 09:08:19 +01:00
const E_TexWrap mode );
2017-09-30 12:59:04 +02:00
GLuint id( ) const noexcept { return id_; }
uint32_t levels( ) const noexcept { return levels_; }
2017-09-30 12:59:04 +02:00
uint32_t width( ) const noexcept { return width_; }
uint32_t height( ) const noexcept { return height_; }
2017-12-24 11:10:38 +01:00
uint32_t format( ) const noexcept { return fmt_; }
uint32_t internalFormat( ) const noexcept { return ifmt_; }
uint32_t dataType_( ) const noexcept { return dt_; }
2017-09-30 12:59:04 +02:00
private:
GLuint id_;
2017-12-24 11:10:38 +01:00
uint32_t fmt_ , ifmt_ , dt_;
uint32_t levels_ , width_ , height_;
int32_t debugIndex_;
2017-09-30 12:59:04 +02:00
};
2017-10-02 10:42:06 +02:00
struct T_TextureSampler
{
T_TextureSampler( T_TextureSampler const& ) = delete;
// --------------------------------------------------------------------
// Initialisation, destruction & move
T_TextureSampler( );
T_TextureSampler(
2017-11-03 09:08:19 +01:00
T_TextureSampler&& other ) noexcept;
2017-10-02 10:42:06 +02:00
T_TextureSampler& operator=(
2017-11-03 09:08:19 +01:00
T_TextureSampler&& other ) noexcept;
2017-10-02 10:42:06 +02:00
~T_TextureSampler( );
// --------------------------------------------------------------------
// Configuration
T_TextureSampler& sampling(
2017-11-03 09:08:19 +01:00
const E_TexSampling mode );
2017-10-02 10:42:06 +02:00
T_TextureSampler& noMipmap( );
T_TextureSampler& mipmap(
2017-11-03 09:08:19 +01:00
const E_TexSampling mode );
2017-10-02 10:42:06 +02:00
T_TextureSampler& wrap(
2017-11-03 09:08:19 +01:00
const E_TexWrap mode );
2017-10-02 10:42:06 +02:00
T_TextureSampler& lod(
2017-11-03 09:08:19 +01:00
const float min ,
const float max );
2017-10-02 10:42:06 +02:00
// --------------------------------------------------------------------
// Usage
2017-10-02 10:57:51 +02:00
GLuint id( ) const noexcept { return id_; }
2017-10-02 10:42:06 +02:00
private:
void setSamplingMode( ) const;
GLuint id_ = 0;
E_TexSampling sampling_ = E_TexSampling::NEAREST;
E_TexSampling lodSampling_ = E_TexSampling::NEAREST;
bool hasLOD_ = false;
};
struct T_TextureManager
2017-10-02 10:57:51 +02:00
{
static constexpr uint32_t MaxUnits = 8;
T_TextureManager( );
NO_COPY( T_TextureManager );
NO_MOVE( T_TextureManager );
void reset( );
2017-11-03 09:08:19 +01:00
T_TextureSampler const* sampler(
T_String const& name ) const;
T_TextureSampler const* sampler(
2017-11-03 09:08:19 +01:00
char const* name ) const
{ return sampler( T_String::Pooled( name ) ); }
2017-10-02 10:57:51 +02:00
2017-11-03 09:08:19 +01:00
void bind( const uint32_t unit ,
T_Texture const& texture );
void bind( const uint32_t unit ,
T_Texture const& texture ,
T_TextureSampler const& sampler );
2017-10-02 10:57:51 +02:00
private:
struct T_Binding_
{
GLuint texture = 0;
GLuint sampler = 0;
2017-10-02 10:57:51 +02:00
};
2017-11-03 09:08:19 +01:00
T_KeyValueTable< T_String , T_SharedPtr< T_TextureSampler > > samplers_;
2017-10-02 10:57:51 +02:00
T_Binding_ bindings_[ MaxUnits ];
};