summaryrefslogtreecommitdiff
path: root/c++/window-opengl/gl_xcb.h
blob: 128733b9368cf25ff950de0db84eac01aff9f7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#include <forstio/window/xcb.h>

#ifndef SAW_OGL
#error "OpenGL is not supported"
#endif

#include "gl_backends.h"

#include <GL/glx.h>

namespace saw {
namespace gfx {

struct glx_library_extensions {
public:
	std::string_view raw_extension_string;
	GLXContext (*glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext, Bool, const int*) = nullptr;
};

template<>
class gl_context<gl::backend::linux_xcb> final {
private:
	glx_library_extensions ext_lib_;
	own<device<backend::linux_xcb>> device_;
	int visual_id_;
	GLXContext context_;
	GLXFBConfig fb_config_;
public:
	gl_context(const glx_library_extensions&, own<device<backend::linux_xcb>>, int, GLXContext, GLXFBConfig);
	~gl_context();

	own<gl_window<gl::backend::linux_xcb>> create_window(const video_mode&, std::string_view);

	void flush();
};

template<>
class gl_window<gl::backend::linux_xcb> final {
private:
	own<window<backend::linux_xcb>> window_;
	gl_context<gl::backend::linux_xcb>* context_;

	::GLXWindow glx_window_handle_;

public:
	gl_window(own<window<backend::linux_xcb>> window, gl_context<gl::backend::linux_xcb>& ctx,
			::GLXWindow);
	~gl_window();

	void bind();
	void swap();
	void show();
	void hide();

	const video_mode& get_video_mode() const;
	const std::string_view get_title() const;

	void resize(size_t height, size_t width);

	conveyor<data<schema::WindowEvents>> on_event();
};
}
}