Debian Codegraph @

ruby/video/opengl/opengl.hpp

raw
1 #if defined(PLATFORM_X)
2 #include <GL/gl.h>
3 #include <GL/glx.h>
4 #define glGetProcAddress(name) (*glXGetProcAddress)((const GLubyte*)(name))
5 #elif defined(PLATFORM_MACOSX)
6 #include <OpenGL/gl.h>
7 #include <OpenGL/gl3.h>
8 #elif defined(PLATFORM_WINDOWS)
9 #include <GL/gl.h>
10 #include <GL/glext.h>
11 #define glGetProcAddress(name) wglGetProcAddress(name)
12 #else
13 #error "ruby::OpenGL: unsupported platform"
14 #endif
15
16 namespace ruby {
17
18 #include "bind.hpp"
19 #include "shaders.hpp"
20 #include "utility.hpp"
21
22 struct OpenGL;
23
24 struct OpenGLTexture {
25 GLuint texture = 0;
26 unsigned width = 0;
27 unsigned height = 0;
28 GLuint format = GL_RGBA8;
29 GLuint filter = GL_LINEAR;
30 GLuint wrap = GL_CLAMP_TO_BORDER;
31
32 GLuint getFormat() const;
33 GLuint getType() const;
34 };
35
36 struct OpenGLSurface : OpenGLTexture {
37 GLuint program = 0;
38 GLuint framebuffer = 0;
39 GLuint vao = 0;
40 GLuint vbo[3] = {0, 0, 0};
41 GLuint vertex = 0;
42 GLuint geometry = 0;
43 GLuint fragment = 0;
44 uint32_t* buffer = nullptr;
45
46 void allocate();
47 void size(unsigned width, unsigned height);
48 void release();
49 void render(unsigned sourceWidth, unsigned sourceHeight, unsigned targetWidth, unsigned targetHeight);
50 };
51
52 struct OpenGLProgram : OpenGLSurface {
53 unsigned phase = 0; //frame counter
54 unsigned modulo = 0; //frame counter modulus
55 unsigned absoluteWidth = 0;
56 unsigned absoluteHeight = 0;
57 double relativeWidth = 0;
58 double relativeHeight = 0;
59 vector<OpenGLTexture> pixmaps;
60
61 void bind(OpenGL* instance, const Markup::Node& node, const string& pathname);
62 void parse(OpenGL* instance, string& source);
63 void release();
64 };
65
66 struct OpenGL : OpenGLProgram {
67 vector<OpenGLProgram> programs;
68 vector<OpenGLTexture> history;
69 GLuint inputFormat = GL_RGBA8;
70 unsigned outputWidth = 0;
71 unsigned outputHeight = 0;
72 struct Setting {
73 string name;
74 string value;
75 bool operator< (const Setting& source) { return name < source.name; }
76 bool operator==(const Setting& source) { return name == source.name; }
77 Setting() {}
78 Setting(const string& name) : name(name) {}
79 Setting(const string& name, const string& value) : name(name), value(value) {}
80 };
81 set<Setting> settings;
82
83 void shader(const char* pathname);
84 void allocateHistory(unsigned size);
85 bool lock(uint32_t*& data, unsigned& pitch);
86 void clear();
87 void refresh();
88 bool init();
89 void term();
90 };
91
92 #include "texture.hpp"
93 #include "surface.hpp"
94 #include "program.hpp"
95 #include "main.hpp"
96
97 }