UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
Sdl_window Struct Reference

#include <sdl_window.hpp>

Collaboration diagram for Sdl_window:
Collaboration graph

Public Member Functions

 Sdl_window (bool double_buffer=false)
 
 Sdl_window (const char *title, int x, int y, int w, int h, Uint32 flags, bool double_buffer=false)
 
 Sdl_window (const Sdl_window &)=delete
 
 Sdl_window (Sdl_window &&o)
 
 ~Sdl_window ()
 
SDL_GLContext get_worker_context ()
 
void make_render_context_current ()
 
void make_worker_context_current ()
 
Sdl_window & operator= (const Sdl_window &)=delete
 
Sdl_window & operator= (Sdl_window &&o)
 
void set_title (const std::string &title)
 
void swap (Sdl_window &o)
 

Public Attributes

int height
 
SDL_GLContext sdl_gl_context
 
SDL_GLContext sdl_gl_worker_context = nullptr
 
SDL_Window * sdl_window
 
int width
 

Detailed Description

RAII wrapper for Sdl window

Definition at line 64 of file sdl_window.hpp.

Constructor & Destructor Documentation

◆ Sdl_window() [1/4]

Sdl_window::Sdl_window ( bool double_buffer = false)

Creates a window using default parameters.

Parameters
double_bufferControls the double buffering. If true, the default is used, if false it is disabled

Definition at line 41 of file sdl_window.cpp.

41 : Sdl_window("UltraGrid",
42 SDL_WINDOWPOS_CENTERED,
43 SDL_WINDOWPOS_CENTERED,
44 640,
45 480,
46 SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE, double_buffer) { }
Sdl_window(bool double_buffer=false)

◆ Sdl_window() [2/4]

Sdl_window::Sdl_window ( const char * title,
int x,
int y,
int w,
int h,
Uint32 flags,
bool double_buffer = false )

Creates a window.

Parameters
titlewindow title
xx position of the window, for centering SDL_WINDOWPOS_CENTERED can be passed
yy position of the window, for centering SDL_WINDOWPOS_CENTERED can be passed
wwidth of window
hheight of window
flagsSdl flags for window creation
double_bufferControls the double buffering. If true, the default is used, if false it is disabled

Definition at line 48 of file sdl_window.cpp.

51 : width(w), height(h)
52{
53 SDL_InitSubSystem(SDL_INIT_VIDEO);
54 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
55 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
56 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
57
58 if(!double_buffer)
59 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
60
61 sdl_window = SDL_CreateWindow(title,
62 x,
63 y,
64 w,
65 h,
66 flags);
67
68 if(!sdl_window){
69 throw std::runtime_error("Failed to create SDL window!");
70 }
71
72 SDL_SetWindowMinimumSize(sdl_window, 200, 200);
73
74 sdl_gl_context = SDL_GL_CreateContext(sdl_window);
75 if(!sdl_gl_context){
76 throw std::runtime_error("Failed to create gl context!");
77 }
78
79#ifndef __APPLE__
80 glewExperimental = GL_TRUE;
81 GLenum glewError = glewInit();
82 if(glewError != GLEW_OK){
83 throw std::runtime_error("Failed to initialize gl context!");
84 }
85#endif //__APPLE__
86
87 glClearColor(0,0,0,1);
88 glClear(GL_COLOR_BUFFER_BIT);
89 SDL_GL_SwapWindow(sdl_window);
90}
const char unsigned int flags
SDL_GLContext sdl_gl_context
SDL_Window * sdl_window

References flags, sdl_gl_context, and sdl_window.

◆ ~Sdl_window()

Sdl_window::~Sdl_window ( )

Definition at line 92 of file sdl_window.cpp.

92 {
93 SDL_GL_DeleteContext(sdl_gl_context);
94 SDL_GL_DeleteContext(sdl_gl_worker_context);
95 SDL_DestroyWindow(sdl_window);
96 SDL_QuitSubSystem(SDL_INIT_VIDEO);
97}
SDL_GLContext sdl_gl_worker_context

References sdl_gl_context, sdl_gl_worker_context, and sdl_window.

◆ Sdl_window() [3/4]

Sdl_window::Sdl_window ( const Sdl_window & )
delete

◆ Sdl_window() [4/4]

Sdl_window::Sdl_window ( Sdl_window && o)
inline

Definition at line 94 of file sdl_window.hpp.

94{ swap(o); }
void swap(Sdl_window &o)

References swap().

Here is the call graph for this function:

Member Function Documentation

◆ get_worker_context()

SDL_GLContext Sdl_window::get_worker_context ( )

Returns the underlying worker context object. If it doesn'ลง yet exists it gets created. Should be called at least once from the rendering thread before the worker thread starts.

Definition at line 120 of file sdl_window.cpp.

120 {
122 SDL_GL_MakeCurrent(sdl_window, sdl_gl_context);
123 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
124 sdl_gl_worker_context = SDL_GL_CreateContext(sdl_window);
125 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
126 SDL_GL_MakeCurrent(sdl_window, sdl_gl_context);
127 }
128
130}

References sdl_gl_context, sdl_gl_worker_context, and sdl_window.

Referenced by make_worker_context_current().

◆ make_render_context_current()

void Sdl_window::make_render_context_current ( )

If using multiple OpenGL contexts for multithreading this function makes the render context current

Definition at line 111 of file sdl_window.cpp.

111 {
112 SDL_GL_MakeCurrent(sdl_window, sdl_gl_context);
113}

References sdl_gl_context, and sdl_window.

Referenced by display_xrgl_run().

◆ make_worker_context_current()

void Sdl_window::make_worker_context_current ( )

If using multiple OpenGL contexts for multithreading this function makes the worker context current

Definition at line 115 of file sdl_window.cpp.

115 {
116 SDL_GLContext worker_context = get_worker_context();
117 SDL_GL_MakeCurrent(sdl_window, worker_context);
118}
SDL_GLContext get_worker_context()

References get_worker_context(), and sdl_window.

Referenced by display_xrgl_run(), and worker().

Here is the call graph for this function:

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Definition at line 96 of file sdl_window.hpp.

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

References swap().

Here is the call graph for this function:

◆ set_title()

void Sdl_window::set_title ( const std::string & title)
inline

Sets window title

Parameters
titleTitle to use

Definition at line 112 of file sdl_window.hpp.

112 {
113 SDL_SetWindowTitle(sdl_window, title.c_str());
114 }

References sdl_window.

◆ swap()

void Sdl_window::swap ( Sdl_window & o)

Definition at line 132 of file sdl_window.cpp.

132 {
133 std::swap(sdl_window, o.sdl_window);
134 std::swap(sdl_gl_context, o.sdl_gl_context);
135 std::swap(width, o.width);
136 std::swap(height, o.height);
137}

References height, sdl_gl_context, sdl_window, and width.

Referenced by Sdl_window(), and operator=().

Member Data Documentation

◆ height

int Sdl_window::height

Definition at line 141 of file sdl_window.hpp.

Referenced by display_xrgl_run(), draw(), handle_window_event(), and swap().

◆ sdl_gl_context

SDL_GLContext Sdl_window::sdl_gl_context

◆ sdl_gl_worker_context

SDL_GLContext Sdl_window::sdl_gl_worker_context = nullptr

Definition at line 139 of file sdl_window.hpp.

Referenced by ~Sdl_window(), and get_worker_context().

◆ sdl_window

◆ width

int Sdl_window::width

Definition at line 140 of file sdl_window.hpp.

Referenced by display_xrgl_run(), draw(), handle_window_event(), and swap().


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