emilib
gl_lib_fwd.hpp
1 // By Emil Ernerfeldt 2012-2016
2 // LICENSE:
3 // This software is dual-licensed to the public domain and under the following
4 // license: you are granted a perpetual, irrevocable license to copy, modify,
5 // publish, and distribute this file as you see fit.
6 
7 #pragma once
8 
9 #include <memory>
10 #include <string>
11 #include <utility>
12 
13 #if __APPLE__
14  #include "TargetConditionals.h"
15 #endif
16 
17 // ----------------------------------------------------------------------------
18 
19 #if TARGET_OS_IPHONE
20 
21  #define GLLIB_GLES 1
22  #define GLLIB_OPENGL_VERSION 200
23  #define GLLIB_TRILLINEAR_FILTERING 1
24 
25 #elif TARGET_OS_MAC
26 
27  #define GLLIB_GLES 0
28  #define GLLIB_OPENGL_VERSION 320 // 210, 320, 330, 410, ...
29  #define GLLIB_TRILLINEAR_FILTERING 1
30 
31 #else
32 
33  // Works on Ubuntu 16.04
34  #define GLLIB_GLES 0
35  #define GLLIB_OPENGL_VERSION 210 // 210, 320, 330, 410, ...
36  #define GLLIB_TRILLINEAR_FILTERING 1
37 
38 #endif
39 
40 // ----------------------------------------------------------------------------
41 
42 namespace gl {
43 
44 class Program;
45 using Program_UP = std::unique_ptr<Program>;
46 using Program_SP = std::shared_ptr<Program>;
47 
49 {
50  std::string debug_name;
51  std::string vs;
52  std::string fs;
53 };
54 
55 class Texture;
56 using Texture_UP = std::unique_ptr<Texture>;
57 using Texture_SP = std::shared_ptr<Texture>;
58 
59 struct VertComp;
60 class VertexFormat;
61 
62 class VBO;
63 using VBO_UP = std::unique_ptr<VBO>;
64 using VBO_SP = std::shared_ptr<VBO>;
65 
66 class VAO;
67 using VAO_UP = std::unique_ptr<VAO>;
68 using VAO_SP = std::shared_ptr<VAO>;
69 
70 class MeshPainter;
71 using MeshPainter_UP = std::unique_ptr<MeshPainter>;
72 using MeshPainter_SP = std::shared_ptr<MeshPainter>;
73 
74 template<typename Vertex>
75 class TriangleStrip;
76 
77 class FBO;
78 using FBO_UP = std::unique_ptr<FBO>;
79 using FBO_SP = std::shared_ptr<FBO>;
80 
82 enum class Usage
83 {
84  WRITE_ONCE_READ_MANY,
85  WRITE_MANY_READ_MANY,
86  WRITE_ONCE_READ_ONCE,
87 };
88 
89 struct Size
90 {
91  unsigned x, y;
92 };
93 
94 struct Rectangle
95 {
96  int x, y;
97  int width, height;
98 };
99 
100 // ------------------------------------------------
101 // ImageFormat
102 
103 enum class ImageFormat
104 {
105  INVALID,
106  Alpha8,
107  Red8,
108  RGB24,
109  RGBA32,
110  BGRA32,
111  AlphaHF,
112  RGBAHF,
113  RGBAf,
114 
115  // Available as render-target:
116  //RGBA16F_EXT 0x881A
117  //RGB16F_EXT 0x881B
118  //RG16F_EXT 0x822F
119  //R16F_EXT
120 };
121 
123 constexpr int format_size(ImageFormat format)
124 {
125  return (format == ImageFormat::Alpha8 ? 1 : 4);
126 }
127 
128 constexpr bool is_half(ImageFormat f)
129 {
131 }
132 
133 // ------------------------------------------------
134 
135 enum class TexFilter
136 {
137  Nearest,
138  Linear,
139  Mipmapped,
140  DontCare,
141 };
142 
143 enum class WrapMode
144 {
145  Repeat,
146  Mirror,
147  Clamp,
148  DontCare,
149 };
150 
151 struct TexParams
152 {
153  TexFilter filter = TexFilter::Mipmapped;
154  std::pair<WrapMode, WrapMode> wrap = std::make_pair(WrapMode::Clamp, WrapMode::Clamp);
155 
156  TexParams() {}
157  TexParams(TexFilter f, WrapMode w) : filter(f), wrap(w,w) {}
158  TexParams(TexFilter f, WrapMode u, WrapMode v) : filter(f), wrap(u,v) {}
159 
160  static TexParams clamped(TexFilter f=TexFilter::DontCare) { return TexParams(f, WrapMode::Clamp); }
161  static TexParams repeated(TexFilter f=TexFilter::DontCare) { return TexParams(f, WrapMode::Repeat); }
162  static TexParams clamped_nearest() { return clamped(TexFilter::Nearest); }
163  static TexParams clamped_linear() { return clamped(TexFilter::Linear); }
164  static TexParams clamped_mipmapped() { return clamped(TexFilter::Mipmapped); }
165  static TexParams repeated_linear() { return repeated(TexFilter::Linear); }
166  static TexParams repeated_mipmapped() { return repeated(TexFilter::Mipmapped); }
167  static TexParams mipmapped(WrapMode u, WrapMode v) { return TexParams(TexFilter::Mipmapped, u, v); }
168 
169  friend bool operator<(const TexParams& a, const TexParams& b)
170  {
171  if (a.filter != b.filter) { return a.filter < b.filter; }
172  if (a.wrap != b.wrap) { return a.wrap < b.wrap; }
173  return false; // Same
174  }
175 
176  friend bool operator==(const TexParams& a, const TexParams& b)
177  {
178  return a.filter == b.filter && a.wrap == b.wrap;
179  }
180 };
181 
182 // ------------------------------------------------
183 
184 void check_for_gl_error(const char* file, int line);
185 
186 #ifndef NDEBUG
187  #define CHECK_FOR_GL_ERROR gl::check_for_gl_error(__FILE__, __LINE__)
188 #else
189  #define CHECK_FOR_GL_ERROR
190 #endif
191 
192 // ----------------------------------------------------------------------------
193 
195 {
196 public:
197  PaintGrouper(const char* name);
198  PaintGrouper(const std::string& name);
199  ~PaintGrouper();
200  PaintGrouper(PaintGrouper&) = delete;
201  PaintGrouper& operator=(PaintGrouper&) = delete;
202 };
203 
204 #define NAME_PAINT_GROUP(name) gl::PaintGrouper LOGURU_ANONYMOUS_VARIABLE(paint_scope_)(name)
205 
206 #define NAME_PAINT_FUNCTION() NAME_PAINT_GROUP(__PRETTY_FUNCTION__)
207 
208 // ------------------------------------------------
209 
210 } // gl
Definition: gl_lib.hpp:419
TexFilter
Definition: gl_lib_fwd.hpp:135
ImageFormat
Definition: gl_lib_fwd.hpp:103
Definition: gl_lib_fwd.hpp:194
Definition: file_system.hpp:18
16-bit half-float, alpha channel only.
Definition: gl_lib.hpp:236
Definition: gl_lib_fwd.hpp:151
Definition: gl_lib.hpp:338
Definition: gl_lib.hpp:278
Definition: gl_lib.hpp:48
Definition: gl_lib_fwd.hpp:89
constexpr int format_size(ImageFormat format)
byte size per pixel
Definition: gl_lib_fwd.hpp:123
Definition: gl_lib.hpp:257
GL_BGRA - Four bytes.
Definition: gl_lib.hpp:357
Definition: gl_lib_fwd.hpp:48
Best based on size.
Usage
For VBO:s and the like.
Definition: gl_lib_fwd.hpp:82
An off-screen buffer you can draw onto.
Definition: gl_lib.hpp:499
RGBA Half-float.
OpenGL wrapper classes.
Definition: gl_lib.hpp:30
Definition: gl_lib_fwd.hpp:94
32bit float RGBA