demotool/ui-texture.hh
2017-11-23 23:31:24 +01:00

119 lines
2.6 KiB
C++

#pragma once
#include "c-renderdefs.hh"
struct T_OutputDebugger;
/*----------------------------------------------------------------------------*/
struct T_Texture
{
friend struct T_OutputDebugger;
T_Texture( ) = delete;
T_Texture( T_Texture const& ) = delete;
T_Texture( T_Texture&& ) = delete;
T_Texture(
const uint32_t width ,
const uint32_t height ,
const E_TexType type ,
const uint32_t levels = 1 );
~T_Texture( );
T_Texture& samplingMode(
const E_TexSampling mode );
T_Texture& wrap(
const E_TexWrap mode );
GLuint id( ) const noexcept { return id_; }
uint32_t levels( ) const noexcept { return levels_; }
uint32_t width( ) const noexcept { return width_; }
uint32_t height( ) const noexcept { return height_; }
private:
GLuint id_;
uint32_t levels_ , width_ , height_;
int32_t debugIndex_;
};
struct T_TextureSampler
{
T_TextureSampler( T_TextureSampler const& ) = delete;
// --------------------------------------------------------------------
// Initialisation, destruction & move
T_TextureSampler( );
T_TextureSampler(
T_TextureSampler&& other ) noexcept;
T_TextureSampler& operator=(
T_TextureSampler&& other ) noexcept;
~T_TextureSampler( );
// --------------------------------------------------------------------
// Configuration
T_TextureSampler& sampling(
const E_TexSampling mode );
T_TextureSampler& noMipmap( );
T_TextureSampler& mipmap(
const E_TexSampling mode );
T_TextureSampler& wrap(
const E_TexWrap mode );
T_TextureSampler& lod(
const float min ,
const float max );
// --------------------------------------------------------------------
// Usage
GLuint id( ) const noexcept { return id_; }
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
{
static constexpr uint32_t MaxUnits = 8;
T_TextureManager( );
NO_COPY( T_TextureManager );
NO_MOVE( T_TextureManager );
void reset( );
T_TextureSampler const* sampler(
T_String const& name ) const;
T_TextureSampler const* sampler(
char const* name ) const
{ return sampler( T_String::Pooled( name ) ); }
void bind( const uint32_t unit ,
T_Texture const& texture );
void bind( const uint32_t unit ,
T_Texture const& texture ,
T_TextureSampler const& sampler );
private:
struct T_Binding_
{
GLuint texture = 0;
GLuint sampler = 0;
};
T_KeyValueTable< T_String , T_SharedPtr< T_TextureSampler > > samplers_;
T_Binding_ bindings_[ MaxUnits ];
};