Beatmup
Beatmup::GL::TextureHandler Class Referenceabstract

#include <texture_handler.h>

Inheritance diagram for Beatmup::GL::TextureHandler:
Beatmup::Object Beatmup::AbstractBitmap Beatmup::GL::Vector Beatmup::NNets::Storage::TextureHandler Beatmup::GL::LinearMapping::Matrix Beatmup::Android::Bitmap Beatmup::Android::ExternalBitmap Beatmup::GDIBitmap Beatmup::InternalBitmap Beatmup::Python::Bitmap

Public Types

enum  TextureFormat {
  Rx8 , RGBx8 , RGBAx8 , Rx32f ,
  RGBx32f , RGBAx32f , OES_Ext
}
 Texture format, specifies how the texture should be interpreted on the shader side. More...
 

Public Member Functions

 ~TextureHandler ()
 
virtual const int getWidth () const =0
 Width of the texture in pixels. More...
 
virtual const int getHeight () const =0
 Height of the texture in pixels. More...
 
virtual const int getDepth () const =0
 Depth of the texture in pixels. More...
 
float getAspectRatio () const
 Aspect ratio of the texture. More...
 
float getInvAspectRatio () const
 Inverse of the aspect ratio of the texture. More...
 
virtual const TextureFormat getTextureFormat () const =0
 Returns the texture format specifying how the shader must interpret the data. More...
 
const bool isFloatingPoint () const
 
const int getNumberOfChannels () const
 Returns number of channels containing in the texture. More...
 
bool hasValidHandle () const
 Returns true if the texture handle points to a valid texture. More...
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Static Public Member Functions

static const char * textureFormatToString (const TextureFormat &)
 

Static Public Attributes

static const int TEXTURE_FORMAT_BYTES_PER_PIXEL []
 size of a texel in bytes for different texture formats More...
 

Protected Member Functions

 TextureHandler ()
 
virtual void prepare (GraphicPipeline &gpu)
 Prepares (eventually uploads) texture data on GPU. More...
 
void invalidate (RecycleBin &)
 Forces disposing the texture data, e.g. More...
 

Protected Attributes

handle_t textureHandle
 

Friends

class ::Beatmup::GraphicPipeline
 

Detailed Description

Definition at line 37 of file texture_handler.h.

Member Enumeration Documentation

◆ TextureFormat

Texture format, specifies how the texture should be interpreted on the shader side.

Enumerator
Rx8 
RGBx8 
RGBAx8 
Rx32f 
RGBx32f 
RGBAx32f 
OES_Ext 

external EGL image

Definition at line 44 of file texture_handler.h.

Constructor & Destructor Documentation

◆ TextureHandler()

TextureHandler::TextureHandler ( )
protected

Definition at line 58 of file texture_handler.cpp.

58  :
59  textureHandle(0)
60 {}

◆ ~TextureHandler()

TextureHandler::~TextureHandler ( )

Definition at line 63 of file texture_handler.cpp.

63  {
64  if (hasValidHandle())
65  BEATMUP_DEBUG_E("Destroying texture handler still having a valid handle");
66 }
bool hasValidHandle() const
Returns true if the texture handle points to a valid texture.
#define BEATMUP_DEBUG_E(...)
Definition: debug.h:34

Member Function Documentation

◆ textureFormatToString()

const char * TextureHandler::textureFormatToString ( const TextureFormat format)
static

Definition at line 35 of file texture_handler.cpp.

35  {
36  switch (format) {
37  case GL::TextureHandler::TextureFormat::Rx8:
38  return "Rx8";
39  case GL::TextureHandler::TextureFormat::RGBx8:
40  return "RGBx8";
41  case GL::TextureHandler::TextureFormat::RGBAx8:
42  return "RGBAx8";
43 
44  case GL::TextureHandler::TextureFormat::Rx32f:
45  return "Rx32f";
46  case GL::TextureHandler::TextureFormat::RGBx32f:
47  return "RGBx32f";
48  case GL::TextureHandler::TextureFormat::RGBAx32f:
49  return "RGBAx32f";
50 
51  case OES_Ext:
52  return "OES extension";
53  }
54  return "invalid format";
55 }
JNIEnv jobject jint format

◆ prepare()

void TextureHandler::prepare ( GraphicPipeline gpu)
protectedvirtual

Prepares (eventually uploads) texture data on GPU.

Called only by the context managing thread.

Parameters
[in]gpuGraphic pipeline instance

Reimplemented in Beatmup::Android::ExternalBitmap, Beatmup::NNets::Storage::TextureHandler, Beatmup::GL::Vector, and Beatmup::AbstractBitmap.

Definition at line 69 of file texture_handler.cpp.

69  {
70  if (!hasValidHandle())
71  glGenTextures(1, &textureHandle);
72 }

◆ invalidate()

void TextureHandler::invalidate ( GL::RecycleBin bin)
protected

Forces disposing the texture data, e.g.

when it is not used any more

Definition at line 96 of file texture_handler.cpp.

96  {
97  if (hasValidHandle()) {
98  class Deleter : public GL::RecycleBin::Item {
100  public:
101  Deleter(handle_t handle) : handle(handle) {}
102  ~Deleter() {
103  glDeleteTextures(1, &handle);
104  }
105  };
106  bin.put(new Deleter(textureHandle));
107 
108  textureHandle = 0;
109  }
110 }
A wrapper for a GPU resource.
Definition: recycle_bin.h:39
void put(Item *item)
Puts an item into the recycle bin.
Definition: recycle_bin.cpp:73
unsigned int handle_t
A reference to a GPU resource.
Definition: basic_types.h:61
JNIEnv jobject jlong handle

◆ getWidth()

virtual const int Beatmup::GL::TextureHandler::getWidth ( ) const
pure virtual

◆ getHeight()

virtual const int Beatmup::GL::TextureHandler::getHeight ( ) const
pure virtual

◆ getDepth()

virtual const int Beatmup::GL::TextureHandler::getDepth ( ) const
pure virtual

◆ getAspectRatio()

float Beatmup::GL::TextureHandler::getAspectRatio ( ) const
inline

Aspect ratio of the texture.

Definition at line 96 of file texture_handler.h.

96 { return (float)getWidth() / getHeight(); }
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const int getWidth() const =0
Width of the texture in pixels.

◆ getInvAspectRatio()

float Beatmup::GL::TextureHandler::getInvAspectRatio ( ) const
inline

Inverse of the aspect ratio of the texture.

Definition at line 101 of file texture_handler.h.

101 { return (float)getHeight() / getWidth(); }

◆ getTextureFormat()

virtual const TextureFormat Beatmup::GL::TextureHandler::getTextureFormat ( ) const
pure virtual

Returns the texture format specifying how the shader must interpret the data.

Implemented in Beatmup::Android::ExternalBitmap, Beatmup::NNets::Storage::TextureHandler, Beatmup::GL::Vector, Beatmup::GL::LinearMapping::Matrix, and Beatmup::AbstractBitmap.

◆ isFloatingPoint()

const bool Beatmup::GL::TextureHandler::isFloatingPoint ( ) const
inline

Definition at line 108 of file texture_handler.h.

108  {
110  return format == TextureFormat::Rx32f || format == TextureFormat::RGBx32f || format == TextureFormat::RGBAx32f;
111  }
TextureFormat
Texture format, specifies how the texture should be interpreted on the shader side.
virtual const TextureFormat getTextureFormat() const =0
Returns the texture format specifying how the shader must interpret the data.

◆ getNumberOfChannels()

const int TextureHandler::getNumberOfChannels ( ) const

Returns number of channels containing in the texture.

Definition at line 75 of file texture_handler.cpp.

75  {
76  switch (getTextureFormat())
77  {
78  case GL::TextureHandler::TextureFormat::Rx8:
79  case GL::TextureHandler::TextureFormat::Rx32f:
80  return 1;
81  case GL::TextureHandler::TextureFormat::RGBx8:
82  case GL::TextureHandler::TextureFormat::RGBx32f:
83  return 3;
84  case GL::TextureHandler::TextureFormat::RGBAx8:
85  case GL::TextureHandler::TextureFormat::RGBAx32f:
86  return 4;
87 
88  case OES_Ext:
89  return 3;
90  //fixme
91  }
92  return 0;
93 }

◆ hasValidHandle()

bool Beatmup::GL::TextureHandler::hasValidHandle ( ) const
inline

Returns true if the texture handle points to a valid texture.

Definition at line 121 of file texture_handler.h.

121 { return textureHandle > 0; }

Friends And Related Function Documentation

◆ ::Beatmup::GraphicPipeline

friend class ::Beatmup::GraphicPipeline
friend

Definition at line 38 of file texture_handler.h.

Member Data Documentation

◆ TEXTURE_FORMAT_BYTES_PER_PIXEL

const int TextureHandler::TEXTURE_FORMAT_BYTES_PER_PIXEL
static
Initial value:
= {
1, 3, 4,
4 * 1, 4 * 3, 4 * 4,
0
}

size of a texel in bytes for different texture formats

Definition at line 54 of file texture_handler.h.

◆ textureHandle

handle_t Beatmup::GL::TextureHandler::textureHandle
protected

Definition at line 59 of file texture_handler.h.


The documentation for this class was generated from the following files: