summaryrefslogtreecommitdiff
path: root/src/wx/gl_util.h
blob: 101a35721ba659de0a1b7cfa20fa0953026871d2 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
    Copyright (C) 2025 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#ifndef DCPOMATIC_GL_UTIL_H
#define DCPOMATIC_GL_UTIL_H


#include <dcp/types.h>
#include <wx/wx.h>


/* This will only build on an new-enough wxWidgets: see the comment in gl_video_view.h */
#if wxCHECK_VERSION(3,1,0)

#ifdef DCPOMATIC_OSX
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl3.h>
#endif

#ifdef DCPOMATIC_LINUX
#include <GL/glu.h>
#include <GL/glext.h>
#endif

#ifdef DCPOMATIC_WINDOWS
#include <GL/glu.h>
#include <GL/wglext.h>
#endif


class Image;


namespace dcpomatic {
namespace gl {


extern GLuint compile_shader(GLenum type, char const* source);
extern void check_gl_error(char const* last);


class Texture
{
public:
	/** @param unit Unit, or index, of this texture (from 0 to GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1) */
	Texture(GLint unpack_alignment, int unit = 0);
	~Texture();

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

	Texture(Texture&&);
	Texture& operator=(Texture&&);

	void bind();
	void set(std::shared_ptr<const Image> image, int component = 0);

private:
	GLuint _name;
	GLint _unpack_alignment;
	int _unit;
	boost::optional<dcp::Size> _size;
};


class Coords
{
public:
	class Rectangle
	{
	public:
		Rectangle(Coords& coords, int node, int index);

		virtual void draw() = 0;

		void set(wxSize canvas_size, int x, int y, dcp::Size size);
		void set(wxSize canvas_size, int x, int y, wxSize size);

		int index() const {
			return _index;
		}

	protected:
		Coords& _coords;
		int _node;
		int _index;
	};

	class FilledRectangle : public Rectangle
	{
	public:
		FilledRectangle(Coords& coords);
		void draw() override;
	};

	class OutlineRectangle : public Rectangle
	{
	public:
		OutlineRectangle(Coords& coords);
		void draw() override;
	};

	class FilledRectangleGroup
	{
	public:
		void add(FilledRectangle const& rectangle);
		void draw();

	private:
		int _index = -1;
		int _number = 0;
	};

	FilledRectangle add_filled_rectangle();
	OutlineRectangle add_outline_rectangle();

	void setup();
	void set_array_buffer();

private:
	friend class Rectangle;

	bool _setup = false;
	int _nodes = 0;
	std::vector<unsigned int> _indices;
	std::vector<float> _coords;
};


class Uniform
{
public:
	void setup(int program, char const* name);

protected:
	int _location = -1;
};


class UniformVec4f : public Uniform
{
public:
	void set(float a, float b, float c, float d);
};


class Uniform1i : public Uniform
{
public:
	void set(int v);
};


}
}


#endif
#endif