2017-09-30 12:59:04 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef REAL_BUILD
|
|
|
|
# include "externals.hh"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-10-06 14:29:01 +02:00
|
|
|
struct T_OutputDebugger;
|
|
|
|
|
|
|
|
|
2017-09-30 17:58:48 +02:00
|
|
|
enum class E_TexType {
|
2017-09-30 12:59:04 +02:00
|
|
|
RGBA8 ,
|
|
|
|
RGBA16F ,
|
2017-09-30 17:58:48 +02:00
|
|
|
RGB8 ,
|
|
|
|
RGB16F ,
|
2017-09-30 12:59:04 +02:00
|
|
|
R8 ,
|
|
|
|
R16F ,
|
|
|
|
};
|
|
|
|
|
2017-09-30 17:58:48 +02:00
|
|
|
enum class E_TexSampling {
|
|
|
|
NEAREST ,
|
|
|
|
LINEAR ,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class E_TexWrap {
|
|
|
|
REPEAT ,
|
|
|
|
CLAMP_EDGE ,
|
|
|
|
CLAMP_BORDER
|
|
|
|
};
|
|
|
|
|
2017-10-06 14:29:01 +02:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-09-30 12:59:04 +02:00
|
|
|
struct T_Texture
|
|
|
|
{
|
2017-10-06 14:29:01 +02:00
|
|
|
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( );
|
|
|
|
|
2017-09-30 17:58:48 +02:00
|
|
|
T_Texture& samplingMode(
|
2017-11-03 09:08:19 +01:00
|
|
|
const E_TexSampling mode );
|
2017-09-30 17:58:48 +02:00
|
|
|
T_Texture& wrap(
|
2017-11-03 09:08:19 +01:00
|
|
|
const E_TexWrap mode );
|
2017-09-30 17:58:48 +02:00
|
|
|
|
2017-09-30 12:59:04 +02:00
|
|
|
GLuint id( ) const noexcept { return id_; }
|
2017-09-30 17:58:48 +02:00
|
|
|
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_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
GLuint id_;
|
2017-09-30 17:58:48 +02:00
|
|
|
uint32_t levels_ , width_ , height_;
|
2017-10-06 14:29:01 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
struct T_TextureManager
|
2017-10-02 10:57:51 +02:00
|
|
|
{
|
|
|
|
static constexpr uint32_t MaxUnits = 8;
|
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
T_TextureManager( );
|
2017-10-02 14:48:16 +02:00
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
NO_COPY( T_TextureManager );
|
|
|
|
NO_MOVE( T_TextureManager );
|
2017-10-02 14:48:16 +02:00
|
|
|
|
|
|
|
void reset( );
|
2017-11-03 09:08:19 +01:00
|
|
|
|
|
|
|
T_TextureSampler const* sampler(
|
|
|
|
T_String const& name ) const;
|
2017-10-02 14:48:16 +02:00
|
|
|
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_
|
|
|
|
{
|
2017-10-02 14:48:16 +02:00
|
|
|
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 ];
|
|
|
|
};
|