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

#include <opengl_utils.hpp>

Collaboration diagram for FlatVideoScene:
Collaboration graph

Public Member Functions

 FlatVideoScene ()=default
 
void enableDeinterlacing (bool enable)
 
GLuint get_texture ()
 
void init ()
 
void put_frame (video_frame *f)
 
void render ()
 
void resize (int width, int height)
 

Private Attributes

video_desc current_desc
 
GlProgram program
 
Model quad
 
int screen_height
 
int screen_width
 
Texture texture
 
FrameUploader uploader
 

Detailed Description

Definition at line 398 of file opengl_utils.hpp.

Constructor & Destructor Documentation

◆ FlatVideoScene()

FlatVideoScene::FlatVideoScene ( )
default

Member Function Documentation

◆ enableDeinterlacing()

void FlatVideoScene::enableDeinterlacing ( bool enable)

Definition at line 432 of file opengl_utils.cpp.

432 {
433 glUseProgram(program.get());
434
435 GLuint pvLoc;
436 pvLoc = glGetUniformLocation(program.get(), "deinterlace");
437 glUniform1i(pvLoc, enable);
438}
GLuint get()

References GlProgram::get(), and program.

Here is the call graph for this function:

◆ get_texture()

GLuint FlatVideoScene::get_texture ( )
inline

Definition at line 409 of file opengl_utils.hpp.

409{ return texture.get(); }
GLuint get() const

References Texture::get(), and texture.

Here is the call graph for this function:

◆ init()

void FlatVideoScene::init ( )

Definition at line 352 of file opengl_utils.cpp.

352 {
353 const char *vert_src = R"END(
354#version 330 core
355layout(location = 0) in vec2 vert_pos;
356layout(location = 1) in vec2 vert_uv;
357
358uniform vec2 scale_vec;
359
360out vec2 UV;
361
362void main(){
363 gl_Position = vec4(vert_pos * scale_vec, 0.0f, 1.0f);
364 UV = vert_uv;
365}
366)END";
367
368 const char *frag_src = R"END(
369#version 330 core
370in vec2 UV;
371out vec3 color;
372uniform sampler2D tex;
373uniform bool deinterlace = false;
374void main(){
375 color = texture(tex, UV).rgb;
376
377 if(deinterlace){
378 float lineOff = 1.0f / textureSize(tex, 0).y;
379 vec3 pix_down = texture(tex, vec2(UV.x, UV.y + lineOff)).rgb;
380 color = (color + pix_down) / 2.0f;
381 }
382}
383)END";
384
389 uploader.enable_pbo(false);
390}
FrameUploader uploader
void enable_pbo(bool enable)
void attach_dst_texture(Texture *tex)
static Model get_quad()
void allocate(int w, int h, GLint internal_fmt)
static const char * vert_src
static const char * frag_src

References Texture::allocate(), FrameUploader::attach_dst_texture(), FrameUploader::enable_pbo(), frag_src, Model::get_quad(), program, quad, texture, uploader, and vert_src.

Here is the call graph for this function:

◆ put_frame()

void FlatVideoScene::put_frame ( video_frame * f)

Definition at line 392 of file opengl_utils.cpp.

392 {
393 auto frame_desc = video_desc_from_frame(f);
394 if(!video_desc_eq(frame_desc, current_desc)){
395 current_desc = frame_desc;
397 }
398
399 uploader.put_frame(f, false);
400}
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
void resize(int width, int height)
video_desc current_desc
void put_frame(video_frame *f, bool pbo_frame=false)
bool video_desc_eq(struct video_desc a, struct video_desc b)
Compares two video descriptions.

References current_desc, FrameUploader::put_frame(), resize(), screen_height, screen_width, uploader, video_desc_eq(), and video_desc_from_frame().

Here is the call graph for this function:

◆ render()

void FlatVideoScene::render ( )

Definition at line 402 of file opengl_utils.cpp.

402 {
403 glUseProgram(program.get());
404
405 glViewport(0, 0, screen_width, screen_height);
406 glBindTexture(GL_TEXTURE_2D, texture.get());
407 quad.render();
408}
void render()

References GlProgram::get(), Texture::get(), program, quad, Model::render(), screen_height, screen_width, and texture.

Here is the call graph for this function:

◆ resize()

void FlatVideoScene::resize ( int width,
int height )

Definition at line 410 of file opengl_utils.cpp.

410 {
411 screen_width = width;
412 screen_height = height;
413
414 double x = 1.0;
415 double y = -1.0;
416
417 double screen_aspect = (double) width / height;
418 double video_aspect = (double) current_desc.width / current_desc.height;
419 if(screen_aspect > video_aspect) {
420 x = (double) height * video_aspect / width;
421 } else {
422 y = (double) -width / (height * video_aspect);
423 }
424
425 glUseProgram(program.get());
426
427 GLuint pvLoc;
428 pvLoc = glGetUniformLocation(program.get(), "scale_vec");
429 glUniform2f(pvLoc, x, y);
430}
unsigned int width
width of every tile (!)
Definition types.h:179
unsigned int height
height of every tile (!)
Definition types.h:180

References current_desc, GlProgram::get(), video_desc::height, program, screen_height, screen_width, and video_desc::width.

Referenced by put_frame().

Here is the call graph for this function:

Member Data Documentation

◆ current_desc

video_desc FlatVideoScene::current_desc
private

Definition at line 416 of file opengl_utils.hpp.

Referenced by put_frame(), and resize().

◆ program

GlProgram FlatVideoScene::program
private

Definition at line 411 of file opengl_utils.hpp.

Referenced by enableDeinterlacing(), init(), render(), and resize().

◆ quad

Model FlatVideoScene::quad
private

Definition at line 412 of file opengl_utils.hpp.

Referenced by init(), and render().

◆ screen_height

int FlatVideoScene::screen_height
private

Definition at line 418 of file opengl_utils.hpp.

Referenced by put_frame(), render(), and resize().

◆ screen_width

int FlatVideoScene::screen_width
private

Definition at line 417 of file opengl_utils.hpp.

Referenced by put_frame(), render(), and resize().

◆ texture

Texture FlatVideoScene::texture
private

Definition at line 413 of file opengl_utils.hpp.

Referenced by get_texture(), init(), and render().

◆ uploader

FrameUploader FlatVideoScene::uploader
private

Definition at line 414 of file opengl_utils.hpp.

Referenced by init(), and put_frame().


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