UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
Texture Class Reference

#include <opengl_utils.hpp>

Collaboration diagram for Texture:
Collaboration graph

Public Member Functions

 Texture ()=default
 
 Texture (const Texture &)=delete
 
 Texture (Texture &&o)
 
 ~Texture ()
 
void allocate ()
 
void allocate (int w, int h, GLint internal_fmt)
 
GLuint get () const
 
void load_frame (int w, int h, GLint internal_format, GLenum src_format, GLenum type, video_frame *f, bool pbo_frame)
 
Texture & operator= (const Texture &)=delete
 
Texture & operator= (Texture &&o)
 
void swap (Texture &o)
 

Private Attributes

int height = 0
 
GLint internal_format = 0
 
GLuint pbo = 0
 
GLuint tex_id = 0
 
int width = 0
 

Detailed Description

RAII wrapper for OpenGL texture object

Definition at line 147 of file opengl_utils.hpp.

Constructor & Destructor Documentation

◆ Texture() [1/3]

Texture::Texture ( )
default

Constructs an instance containing a new OpenGL texture object

◆ ~Texture()

Texture::~Texture ( )

Definition at line 234 of file opengl_utils.cpp.

234 {
235 if(tex_id == 0)
236 return;
237
238 glDeleteTextures(1, &tex_id);
239 glDeleteBuffers(1, &pbo);
240}
GLuint tex_id

References pbo, and tex_id.

◆ Texture() [2/3]

Texture::Texture ( const Texture & )
delete

◆ Texture() [3/3]

Texture::Texture ( Texture && o)
inline

Definition at line 181 of file opengl_utils.hpp.

181{ swap(o); }
void swap(Texture &o)

References swap().

Here is the call graph for this function:

Member Function Documentation

◆ allocate() [1/2]

void Texture::allocate ( )

Definition at line 291 of file opengl_utils.cpp.

291 {
292 if(tex_id != 0)
293 return;
294
295 glGenTextures(1, &tex_id);
296 glBindTexture(GL_TEXTURE_2D, tex_id);
297 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
302 glGenBuffers(1, &pbo);
303}
static unsigned char pixels[]

References pbo, pixels, and tex_id.

Referenced by allocate(), and load_frame().

◆ allocate() [2/2]

void Texture::allocate ( int w,
int h,
GLint internal_fmt )

Allocates the the storage for the texture according to requested resolution and format

Parameters
wwidth of the image
hheight of the image
internal_fmtsame as internalformat parameter of glTexImage2D()

Definition at line 242 of file opengl_utils.cpp.

242 {
243 allocate();
244 if(w != width || h != height || internal_fmt != internal_format){
245 width = w;
246 height = h;
247 internal_format = internal_fmt;
248
249 glBindTexture(GL_TEXTURE_2D, tex_id);
250 /* Only the internalformat parameter is relevant here, the
251 * format and type parameters refer to the source data and we
252 * are passing nullptr here
253 */
254 glTexImage2D(GL_TEXTURE_2D, 0, internal_format,
255 width, height, 0,
256 GL_RGBA, GL_UNSIGNED_BYTE,
257 nullptr);
258 }
259}
GLint internal_format
void allocate()

References allocate(), height, internal_format, tex_id, and width.

Referenced by TripleBufferTexture::allocateTextures(), FlatVideoScene::init(), and FrameUploader::put_frame().

Here is the call graph for this function:

◆ get()

GLuint Texture::get ( ) const
inline

Returns the underlying OpenGL texture id. The texture needs to be allocated first with the allocate member function.

Definition at line 159 of file opengl_utils.hpp.

159{ assert(tex_id); return tex_id; }

References tex_id.

Referenced by Framebuffer::attach_texture(), FlatVideoScene::get_texture(), FrameUploader::put_frame(), PanoramaScene::put_frame(), FlatVideoScene::render(), and PanoramaScene::render().

◆ load_frame()

void Texture::load_frame ( int w,
int h,
GLint internal_format,
GLenum src_format,
GLenum type,
video_frame * f,
bool pbo_frame )

Definition at line 261 of file opengl_utils.cpp.

267{
268 char *src_data = f->tiles[0].data;
270 glBindTexture(GL_TEXTURE_2D, tex_id);
271
272 if(pbo_frame){
273 GlBuffer *pbo = static_cast<GlBuffer *>(f->callbacks.dispose_udata);
274
275 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo->get());
276 glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
277 f->tiles[0].data = nullptr;
278 src_data = nullptr;
279 }
280
281 glTexImage2D(GL_TEXTURE_2D, 0, internal_format,
282 w, h, 0,
283 src_format, type,
284 src_data);
285
286 if(pbo_frame){
287 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
288 }
289}
Option::OptType type
Definition settings.cpp:194
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
struct video_frame_callbacks callbacks
Definition types.h:324

References allocate(), video_frame::callbacks, tile::data, video_frame_callbacks::dispose_udata, internal_format, pbo, tex_id, video_frame::tiles, and type.

Here is the call graph for this function:

◆ operator=() [1/2]

Texture & Texture::operator= ( const Texture & )
delete

◆ operator=() [2/2]

Texture & Texture::operator= ( Texture && o)
inline

Definition at line 183 of file opengl_utils.hpp.

183{ swap(o); return *this; }

References swap().

Here is the call graph for this function:

◆ swap()

void Texture::swap ( Texture & o)
inline

Swaps the contents of two Texture objects

Definition at line 189 of file opengl_utils.hpp.

189 {
190 std::swap(tex_id, o.tex_id);
191 std::swap(width, o.width);
192 std::swap(height, o.height);
193 std::swap(internal_format, o.internal_format);
194 std::swap(pbo, o.pbo);
195 }

References height, internal_format, pbo, tex_id, and width.

Referenced by Texture(), operator=(), TripleBufferTexture::swap_back(), and TripleBufferTexture::swap_front().

Member Data Documentation

◆ height

int Texture::height = 0
private

Definition at line 199 of file opengl_utils.hpp.

Referenced by allocate(), and swap().

◆ internal_format

GLint Texture::internal_format = 0
private

Definition at line 200 of file opengl_utils.hpp.

Referenced by allocate(), load_frame(), and swap().

◆ pbo

GLuint Texture::pbo = 0
private

Definition at line 202 of file opengl_utils.hpp.

Referenced by ~Texture(), allocate(), load_frame(), and swap().

◆ tex_id

GLuint Texture::tex_id = 0
private

Definition at line 197 of file opengl_utils.hpp.

Referenced by ~Texture(), allocate(), allocate(), get(), load_frame(), and swap().

◆ width

int Texture::width = 0
private

Definition at line 198 of file opengl_utils.hpp.

Referenced by allocate(), and swap().


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