13 return "GL_INVALID_ENUM";
14 case GL_INVALID_VALUE:
15 return "GL_INVALID_VALUE";
16 case GL_INVALID_OPERATION:
17 return "GL_INVALID_OPERATION";
18 case GL_INVALID_FRAMEBUFFER_OPERATION:
19 return "GL_INVALID_FRAMEBUFFER_OPERATION";
20 case GL_OUT_OF_MEMORY:
21 return "GL_OUT_OF_MEMORY";
22 case GL_STACK_UNDERFLOW:
23 return "GL_STACK_UNDERFLOW";
24 case GL_STACK_OVERFLOW:
25 return "GL_STACK_OVERFLOW";
34 std::string full_message = message;
42 GLuint return_value = glCreateShader(type);
44 if(return_value == 0) {
48 std::string s_source(source);
49 GLchar
const* texts[] = {
51 "#extension GL_ARB_explicit_uniform_location : enable\r\n",
52 "#extension GL_ARB_explicit_attrib_location : enable\r\n",
53 "#extension GL_ARB_shader_subroutine : enable\r\n",
54 "#extension GL_ARB_vertex_array_object : enable\r\n"
55 "#define M_PI 3.1415926535897932384626433832795\r\n",
56 "#define PI 3.1415926535897932384626433832795\r\n",
59 glShaderSource(return_value, 7, texts,
nullptr);
60 glCompileShader(return_value);
63 glGetShaderiv(return_value, GL_COMPILE_STATUS, &result);
64 if(result == GL_FALSE) {
66 glGetShaderiv(return_value, GL_INFO_LOG_LENGTH, &log_length);
68 auto log = std::unique_ptr<char[]>(
new char[
static_cast<size_t>(log_length)]);
70 glGetShaderInfoLog(return_value, log_length, &written, log.get());
76GLuint
create_program(std::string_view vertex_shader, std::string_view fragment_shader) {
77 GLuint return_value = glCreateProgram();
78 if(return_value == 0) {
83 auto f_shader =
compile_shader(fragment_shader, GL_FRAGMENT_SHADER);
85 glAttachShader(return_value, v_shader);
86 glAttachShader(return_value, f_shader);
87 glLinkProgram(return_value);
90 glGetProgramiv(return_value, GL_LINK_STATUS, &result);
91 if(result == GL_FALSE) {
93 glGetProgramiv(return_value, GL_INFO_LOG_LENGTH, &logLen);
95 char* log =
new char[
static_cast<size_t>(logLen)];
97 glGetProgramInfoLog(return_value, logLen, &written, log);
101 glDeleteShader(v_shader);
102 glDeleteShader(f_shader);
108 auto root = get_root(state.common_fs);
161 case GL_FRAMEBUFFER_UNDEFINED:
162 return "GL_FRAMEBUFFER_UNDEFINED";
163 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
164 return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
165 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
166 return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT ";
167 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
168 return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
169 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
170 return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
171 case GL_FRAMEBUFFER_UNSUPPORTED:
172 return "GL_FRAMEBUFFER_UNSUPPORTED";
173 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
174 return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
175 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
176 return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
184 if(state.user_settings.antialias_level == 0)
186 if(!size_x || !size_y)
188 glEnable(GL_MULTISAMPLE);
190 static const float sq_vertices[] = {
192 -1.0f, 1.0f, 0.0f, 1.0f,
193 -1.0f, -1.0f, 0.0f, 0.0f,
194 1.0f, -1.0f, 1.0f, 0.0f,
195 -1.0f, 1.0f, 0.0f, 1.0f,
196 1.0f, -1.0f, 1.0f, 0.0f,
197 1.0f, 1.0f, 1.0f, 1.0f
199 glGenVertexArrays(1, &state.open_gl.msaa_vao);
200 glGenBuffers(1, &state.open_gl.msaa_vbo);
201 glBindVertexArray(state.open_gl.msaa_vao);
202 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.msaa_vbo);
203 glBufferData(GL_ARRAY_BUFFER,
sizeof(sq_vertices), &sq_vertices, GL_STATIC_DRAW);
204 glEnableVertexAttribArray(0);
205 glEnableVertexAttribArray(1);
206 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 *
sizeof(
float), (
void*)0);
207 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 *
sizeof(
float), (
void*)(2 *
sizeof(
float)));
209 glGenFramebuffers(1, &state.open_gl.msaa_framebuffer);
210 glBindFramebuffer(GL_FRAMEBUFFER, state.open_gl.msaa_framebuffer);
212 glGenTextures(1, &state.open_gl.msaa_texcolorbuffer);
213 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, state.open_gl.msaa_texcolorbuffer);
214 glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, GLsizei(state.user_settings.antialias_level), GL_RGBA, size_x, size_y, GL_TRUE);
215 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
216 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, state.open_gl.msaa_texcolorbuffer, 0);
218 glGenRenderbuffers(1, &state.open_gl.msaa_rbo);
219 glBindRenderbuffer(GL_RENDERBUFFER, state.open_gl.msaa_rbo);
220 glRenderbufferStorageMultisample(GL_RENDERBUFFER, GLsizei(state.user_settings.antialias_level), GL_DEPTH24_STENCIL8, size_x, size_y);
221 glBindRenderbuffer(GL_RENDERBUFFER, 0);
222 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, state.open_gl.msaa_rbo);
223 if(
auto r = glCheckFramebufferStatus(GL_FRAMEBUFFER); r != GL_FRAMEBUFFER_COMPLETE) {
225 state.user_settings.antialias_level--;
227 if(state.user_settings.antialias_level != 0) {
230 state.open_gl.msaa_enabled =
false;
235 glGenFramebuffers(1, &state.open_gl.msaa_interbuffer);
236 glBindFramebuffer(GL_FRAMEBUFFER, state.open_gl.msaa_interbuffer);
238 glGenTextures(1, &state.open_gl.msaa_texture);
239 glBindTexture(GL_TEXTURE_2D, state.open_gl.msaa_texture);
240 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_x, size_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
243 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, state.open_gl.msaa_texture, 0);
244 if(
auto r = glCheckFramebufferStatus(GL_FRAMEBUFFER); r != GL_FRAMEBUFFER_COMPLETE) {
247 glBindFramebuffer(GL_FRAMEBUFFER, 0);
249 auto root = get_root(state.common_fs);
250 auto msaa_fshader = open_file(root,
NATIVE(
"assets/shaders/glsl/msaa_f_shader.glsl"));
251 auto msaa_vshader = open_file(root,
NATIVE(
"assets/shaders/glsl/msaa_v_shader.glsl"));
252 if(
bool(msaa_fshader) &&
bool(msaa_vshader)) {
253 auto vertex_content = view_contents(*msaa_vshader);
254 auto fragment_content = view_contents(*msaa_fshader);
255 state.open_gl.msaa_shader_program =
create_program(std::string_view(vertex_content.data, vertex_content.file_size), std::string_view(fragment_content.data, fragment_content.file_size));
256 state.open_gl.msaa_uniform_screen_size = glGetUniformLocation(state.open_gl.msaa_shader_program,
"screen_size");
257 state.open_gl.msaa_uniform_gaussian_blur = glGetUniformLocation(state.open_gl.msaa_shader_program,
"gaussian_radius");
261 state.open_gl.msaa_enabled =
true;
266 if(!state.open_gl.msaa_enabled)
269 state.open_gl.msaa_enabled =
false;
270 if(state.open_gl.msaa_texture)
271 glDeleteTextures(1, &state.open_gl.msaa_texture);
272 if(state.open_gl.msaa_interbuffer)
273 glDeleteFramebuffers(1, &state.open_gl.msaa_framebuffer);
274 if(state.open_gl.msaa_rbo)
275 glDeleteRenderbuffers(1, &state.open_gl.msaa_rbo);
276 if(state.open_gl.msaa_texcolorbuffer)
277 glDeleteTextures(1, &state.open_gl.msaa_texcolorbuffer);
278 if(state.open_gl.msaa_framebuffer)
279 glDeleteFramebuffers(1, &state.open_gl.msaa_framebuffer);
280 if(state.open_gl.msaa_vbo)
281 glDeleteBuffers(1, &state.open_gl.msaa_vbo);
282 if(state.open_gl.msaa_vao)
283 glDeleteVertexArrays(1, &state.open_gl.msaa_vao);
284 if(state.open_gl.msaa_shader_program)
285 glDeleteProgram(state.open_gl.msaa_shader_program);
286 glDisable(GL_MULTISAMPLE);
292 glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
293 glEnable(GL_LINE_SMOOTH);
300 state.world.for_each_national_identity([&](dcon::national_identity_id ident_id) {
302 auto nat_id = fat_id.get_nation_from_identity_holder().id;
303 for(
auto gov_id : state.world.in_government_type) {
308 std::sort(state.flag_types.begin(), state.flag_types.end());
309 state.flag_types.erase(std::unique(state.flag_types.begin(), state.flag_types.end()), state.flag_types.end());
313 for(
auto type : state.flag_types)
315 assert(state.flag_type_map[0] == 0);
318 state.open_gl.asset_textures.resize(
319 state.ui_defs.textures.size() + (state.world.national_identity_size() + 1) * state.flag_types.size());
321 state.map_state.load_map(state);
328static const GLfloat global_square_data[] = {
329 0.0f, 0.0f, 0.0f, 0.0f,
330 0.0f, 1.0f, 0.0f, 1.0f,
331 1.0f, 1.0f, 1.0f, 1.0f,
332 1.0f, 0.0f, 1.0f, 0.0f
334static const GLfloat global_square_right_data[] = {
335 0.0f, 0.0f, 0.0f, 1.0f,
336 0.0f, 1.0f, 1.0f, 1.0f,
337 1.0f, 1.0f, 1.0f, 0.0f,
338 1.0f, 0.0f, 0.0f, 0.0f
340static const GLfloat global_square_left_data[] = {
341 0.0f, 0.0f, 1.0f, 0.0f,
342 0.0f, 1.0f, 0.0f, 0.0f,
343 1.0f, 1.0f, 0.0f, 1.0f,
344 1.0f, 0.0f, 1.0f, 1.0f
346static const GLfloat global_square_flipped_data[] = {
347 0.0f, 0.0f, 0.0f, 1.0f,
348 0.0f, 1.0f, 0.0f, 0.0f,
349 1.0f, 1.0f, 1.0f, 0.0f,
350 1.0f, 0.0f, 1.0f, 1.0f
352static const GLfloat global_square_right_flipped_data[] = {
353 0.0f, 0.0f, 0.0f, 0.0f,
354 0.0f, 1.0f, 1.0f, 0.0f,
355 1.0f, 1.0f, 1.0f, 1.0f,
356 1.0f, 0.0f, 0.0f, 1.0f
358static const GLfloat global_square_left_flipped_data[] = {
359 0.0f, 0.0f, 1.0f, 1.0f,
360 0.0f, 1.0f, 0.0f, 1.0f,
361 1.0f, 1.0f, 0.0f, 0.0f,
362 1.0f, 0.0f, 1.0f, 0.0f
366static const GLfloat global_rtl_square_data[] = {
367 0.0f, 0.0f, 1.0f, 0.0f,
368 0.0f, 1.0f, 1.0f, 1.0f,
369 1.0f, 1.0f, 0.0f, 1.0f,
370 1.0f, 0.0f, 0.0f, 0.0f
372static const GLfloat global_rtl_square_right_data[] = {
373 0.0f, 1.0f, 1.0f, 0.0f,
374 0.0f, 0.0f, 0.0f, 0.0f,
375 1.0f, 0.0f, 0.0f, 1.0f,
376 1.0f, 1.0f, 1.0f, 1.0f
378static const GLfloat global_rtl_square_left_data[] = {
379 0.0f, 0.0f, 0.0f, 0.0f,
380 0.0f, 1.0f, 1.0f, 0.0f,
381 1.0f, 1.0f, 1.0f, 1.0f,
382 1.0f, 0.0f, 0.0f, 1.0f
384static const GLfloat global_rtl_square_flipped_data[] = {
385 0.0f, 0.0f, 1.0f, 1.0f,
386 0.0f, 1.0f, 1.0f, 0.0f,
387 1.0f, 1.0f, 0.0f, 0.0f,
388 1.0f, 0.0f, 0.0f, 1.0f
390static const GLfloat global_rtl_square_right_flipped_data[] = {
391 0.0f, 0.0f, 1.0f, 0.0f,
392 0.0f, 1.0f, 0.0f, 0.0f,
393 1.0f, 1.0f, 0.0f, 1.0f,
394 1.0f, 0.0f, 1.0f, 1.0f
396static const GLfloat global_rtl_square_left_flipped_data[] = {
397 0.0f, 0.0f, 0.0f, 1.0f,
398 0.0f, 1.0f, 1.0f, 1.0f,
399 1.0f, 1.0f, 1.0f, 0.0f,
400 1.0f, 0.0f, 0.0f, 0.0f
404 auto root = get_root(state.common_fs);
405 auto ui_fshader = open_file(root,
NATIVE(
"assets/shaders/glsl/ui_f_shader.glsl"));
406 auto ui_vshader = open_file(root,
NATIVE(
"assets/shaders/glsl/ui_v_shader.glsl"));
407 if(
bool(ui_fshader) &&
bool(ui_vshader)) {
408 auto vertex_content = view_contents(*ui_vshader);
409 auto fragment_content = view_contents(*ui_fshader);
410 state.open_gl.ui_shader_program =
create_program(std::string_view(vertex_content.data, vertex_content.file_size), std::string_view(fragment_content.data, fragment_content.file_size));
412 state.open_gl.ui_shader_texture_sampler_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"texture_sampler");
413 state.open_gl.ui_shader_secondary_texture_sampler_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"secondary_texture_sampler");
414 state.open_gl.ui_shader_screen_width_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"screen_width");
415 state.open_gl.ui_shader_screen_height_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"screen_height");
416 state.open_gl.ui_shader_gamma_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"gamma");
418 state.open_gl.ui_shader_d_rect_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"d_rect");
419 state.open_gl.ui_shader_subroutines_index_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"subroutines_index");
420 state.open_gl.ui_shader_inner_color_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"inner_color");
421 state.open_gl.ui_shader_subrect_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"subrect");
422 state.open_gl.ui_shader_border_size_uniform = glGetUniformLocation(state.open_gl.ui_shader_program,
"border_size");
430 glGenBuffers(1, &state.open_gl.global_square_buffer);
431 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_square_buffer);
432 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_square_data, GL_STATIC_DRAW);
434 glGenBuffers(1, &state.open_gl.global_rtl_square_buffer);
435 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_rtl_square_buffer);
436 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_rtl_square_data, GL_STATIC_DRAW);
438 glGenVertexArrays(1, &state.open_gl.global_square_vao);
439 glBindVertexArray(state.open_gl.global_square_vao);
440 glEnableVertexAttribArray(0);
441 glEnableVertexAttribArray(1);
443 glBindVertexBuffer(0, state.open_gl.global_square_buffer, 0,
sizeof(GLfloat) * 4);
445 glVertexAttribFormat(0, 2, GL_FLOAT, GL_FALSE, 0);
446 glVertexAttribFormat(1, 2, GL_FLOAT, GL_FALSE,
sizeof(GLfloat) * 2);
447 glVertexAttribBinding(0, 0);
448 glVertexAttribBinding(1, 0);
450 glGenBuffers(1, &state.open_gl.global_square_left_buffer);
451 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_square_left_buffer);
452 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_square_left_data, GL_STATIC_DRAW);
454 glGenBuffers(1, &state.open_gl.global_square_right_buffer);
455 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_square_right_buffer);
456 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_square_right_data, GL_STATIC_DRAW);
458 glGenBuffers(1, &state.open_gl.global_square_right_flipped_buffer);
459 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_square_right_flipped_buffer);
460 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_square_right_flipped_data, GL_STATIC_DRAW);
462 glGenBuffers(1, &state.open_gl.global_square_left_flipped_buffer);
463 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_square_left_flipped_buffer);
464 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_square_left_flipped_data, GL_STATIC_DRAW);
466 glGenBuffers(1, &state.open_gl.global_square_flipped_buffer);
467 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_square_flipped_buffer);
468 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_square_flipped_data, GL_STATIC_DRAW);
471 glGenBuffers(1, &state.open_gl.global_rtl_square_left_buffer);
472 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_rtl_square_left_buffer);
473 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_rtl_square_left_data, GL_STATIC_DRAW);
475 glGenBuffers(1, &state.open_gl.global_rtl_square_right_buffer);
476 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_rtl_square_right_buffer);
477 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_rtl_square_right_data, GL_STATIC_DRAW);
479 glGenBuffers(1, &state.open_gl.global_rtl_square_right_flipped_buffer);
480 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_rtl_square_right_flipped_buffer);
481 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_rtl_square_right_flipped_data, GL_STATIC_DRAW);
483 glGenBuffers(1, &state.open_gl.global_rtl_square_left_flipped_buffer);
484 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_rtl_square_left_flipped_buffer);
485 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_rtl_square_left_flipped_data, GL_STATIC_DRAW);
487 glGenBuffers(1, &state.open_gl.global_rtl_square_flipped_buffer);
488 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.global_rtl_square_flipped_buffer);
489 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_rtl_square_flipped_data, GL_STATIC_DRAW);
491 glGenBuffers(64, state.open_gl.sub_square_buffers);
493 glBindBuffer(GL_ARRAY_BUFFER, state.open_gl.sub_square_buffers[i]);
495 float const cell_x =
static_cast<float>(i & 7) / 8.0f;
496 float const cell_y =
static_cast<float>((i >> 3) & 7) / 8.0f;
498 GLfloat global_sub_square_data[] = {0.0f, 0.0f, cell_x, cell_y, 0.0f, 1.0f, cell_x, cell_y + 1.0f / 8.0f, 1.0f, 1.0f,
499 cell_x + 1.0f / 8.0f, cell_y + 1.0f / 8.0f, 1.0f, 0.0f, cell_x + 1.0f / 8.0f, cell_y};
501 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * 16, global_sub_square_data, GL_STATIC_DRAW);
523 glBindVertexBuffer(0, rtl ? state.open_gl.global_rtl_square_buffer : state.open_gl.global_square_buffer, 0,
sizeof(GLfloat) * 4);
525 glBindVertexBuffer(0, rtl ? state.open_gl.global_rtl_square_flipped_buffer : state.open_gl.global_square_flipped_buffer, 0,
sizeof(GLfloat) * 4);
529 glBindVertexBuffer(0, rtl ? state.open_gl.global_rtl_square_left_buffer: state.open_gl.global_square_left_buffer, 0,
sizeof(GLfloat) * 4);
531 glBindVertexBuffer(0, rtl ? state.open_gl.global_rtl_square_left_flipped_buffer : state.open_gl.global_square_left_flipped_buffer, 0,
sizeof(GLfloat) * 4);
535 glBindVertexBuffer(0, rtl ? state.open_gl.global_rtl_square_right_buffer : state.open_gl.global_square_right_buffer, 0,
sizeof(GLfloat) * 4);
537 glBindVertexBuffer(0, rtl ? state.open_gl.global_rtl_square_right_flipped_buffer : state.open_gl.global_square_right_flipped_buffer, 0,
sizeof(GLfloat) * 4);
544 float x,
float y,
float width,
float height,
545 float red,
float green,
float blue,
548 glBindVertexArray(state.open_gl.global_square_vao);
550 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
552 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
553 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, red, green, blue);
556 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
561 float x,
float y,
float width,
float height,
562 float red,
float green,
float blue,
float alpha
564 glBindVertexArray(state.open_gl.global_square_vao);
565 glBindVertexBuffer(0, state.open_gl.global_square_buffer, 0,
sizeof(GLfloat) * 4);
566 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
568 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
569 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, red, green, blue);
570 glUniform1f(state.open_gl.ui_shader_border_size_uniform, alpha);
573 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
578 state, x, y, width, height, 1.0f, 1.0f, 1.0f, r, flipped, rtl
583 GLuint texture_handle,
ui::rotation r,
bool flipped,
bool rtl) {
584 glBindVertexArray(state.open_gl.global_square_vao);
588 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
591 glActiveTexture(GL_TEXTURE0);
592 glBindTexture(GL_TEXTURE_2D, texture_handle);
595 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
598 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
602 glBindVertexArray(state.open_gl.global_square_vao);
604 glBindVertexBuffer(0, state.open_gl.global_square_buffer, 0,
sizeof(GLfloat) * 4);
606 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
608 glActiveTexture(GL_TEXTURE0);
609 glBindTexture(GL_TEXTURE_2D, handle);
612 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
615 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
620 glBindVertexArray(state.open_gl.global_square_vao);
624 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
626 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
632 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 0.f, 0.f, 0.f);
633 glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(l.
count));
637 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 0.f, 0.f, 0.f);
639 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 1.f, 1.f, 0.f);
641 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 1.f, 1.f, 1.f);
643 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 1.f, 1.f, 0.f);
645 glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(l.
count));
650 glBindVertexArray(state.open_gl.global_square_vao);
654 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
656 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
662 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 0.f, 0.f, 0.f);
663 glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(l.
count));
666 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, r, g, b);
667 glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(l.
count));
670void render_linegraph(
sys::state const& state,
color_modification enabled,
float x,
float y,
float width,
float height,
float r,
float g,
float b,
float a,
lines& l) {
671 glBindVertexArray(state.open_gl.global_square_vao);
675 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
677 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
680 glUniform1f(state.open_gl.ui_shader_border_size_uniform, a);
684 glLineWidth(2.0f + 2.0f * state.user_settings.ui_scale);
685 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, 0.f, 0.f, 0.f);
686 glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(l.
count));
688 glLineWidth(2.0f * state.user_settings.ui_scale);
689 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, r, g, b);
690 glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei
>(l.
count));
695 glBindVertexArray(state.open_gl.global_square_vao);
699 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
701 glActiveTexture(GL_TEXTURE0);
702 glBindTexture(GL_TEXTURE_2D, t.
handle());
705 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
708 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
712 glBindVertexArray(state.open_gl.global_square_vao);
714 glBindVertexBuffer(0, state.open_gl.global_square_buffer, 0,
sizeof(GLfloat) * 4);
716 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, size, size);
718 glActiveTexture(GL_TEXTURE0);
719 glBindTexture(GL_TEXTURE_2D, t.
handle());
722 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
725 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
728 glBindVertexArray(state.open_gl.global_square_vao);
730 glBindVertexBuffer(0, state.open_gl.global_square_buffer, 0,
sizeof(GLfloat) * 4);
732 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, sizex, sizey);
734 glActiveTexture(GL_TEXTURE0);
735 glBindTexture(GL_TEXTURE_2D, t.
handle());
738 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
741 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
744 float height, GLuint texture_handle,
ui::rotation r,
bool flipped,
bool rtl) {
745 glBindVertexArray(state.open_gl.global_square_vao);
749 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
750 glUniform1f(state.open_gl.ui_shader_border_size_uniform,
border_size);
752 glActiveTexture(GL_TEXTURE0);
753 glBindTexture(GL_TEXTURE_2D, texture_handle);
756 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
759 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
763 GLuint texture_handle, GLuint mask_texture_handle,
ui::rotation r,
bool flipped,
bool rtl) {
764 glBindVertexArray(state.open_gl.global_square_vao);
768 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
770 glActiveTexture(GL_TEXTURE0);
771 glBindTexture(GL_TEXTURE_2D, texture_handle);
772 glActiveTexture(GL_TEXTURE1);
773 glBindTexture(GL_TEXTURE_2D, mask_texture_handle);
776 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
779 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
783 float height, GLuint left_texture_handle, GLuint right_texture_handle,
ui::rotation r,
bool flipped,
bool rtl) {
784 glBindVertexArray(state.open_gl.global_square_vao);
788 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
789 glUniform1f(state.open_gl.ui_shader_border_size_uniform, progress);
791 glActiveTexture(GL_TEXTURE0);
792 glBindTexture(GL_TEXTURE_2D, left_texture_handle);
793 glActiveTexture(GL_TEXTURE1);
794 glBindTexture(GL_TEXTURE_2D, right_texture_handle);
797 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
800 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
804 GLuint texture_handle,
ui::rotation rot,
bool flipped,
bool rtl) {
805 glBindVertexArray(state.open_gl.global_square_vao);
809 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, r, g, b);
810 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
812 glActiveTexture(GL_TEXTURE0);
813 glBindTexture(GL_TEXTURE_2D, texture_handle);
816 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
819 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
824 float x,
float y,
float width,
float height,
825 float r,
float g,
float b,
828 glBindVertexArray(state.open_gl.global_square_vao);
830 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, r, g, b);
831 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
833 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
834 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
838 float width,
float height,
float r,
float g,
float b, GLuint texture_handle,
ui::rotation rot,
bool flipped,
840 glBindVertexArray(state.open_gl.global_square_vao);
844 auto const scale = 1.0f /
static_cast<float>(total_frames);
845 glUniform3f(state.open_gl.ui_shader_inner_color_uniform,
static_cast<float>(frame) * scale, scale, 0.0f);
846 glUniform4f(state.open_gl.ui_shader_subrect_uniform, r, g, b, 0);
847 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
849 glActiveTexture(GL_TEXTURE0);
850 glBindTexture(GL_TEXTURE_2D, texture_handle);
853 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
856 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
860 float width,
float height, GLuint texture_handle,
ui::rotation r,
bool flipped,
bool rtl) {
861 glBindVertexArray(state.open_gl.global_square_vao);
865 auto const scale = 1.0f /
static_cast<float>(total_frames);
866 glUniform3f(state.open_gl.ui_shader_inner_color_uniform,
static_cast<float>(frame) * scale, scale, 0.0f);
867 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, y, width, height);
869 glActiveTexture(GL_TEXTURE0);
870 glBindTexture(GL_TEXTURE_2D, texture_handle);
873 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
876 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
882 ltag[0] = char(toupper(tag[0]));
883 ltag[1] = char(toupper(tag[1]));
884 ltag[2] = char(toupper(tag[2]));
885 dcon::national_identity_id
ident{};
886 state.world.for_each_national_identity([&](dcon::national_identity_id
id) {
888 if(curr[0] == ltag[0] && curr[1] == ltag[1] && curr[2] == ltag[2]) {
897 auto nation = fat_id.get_nation_from_identity_holder();
899 if(
bool(nation.id) && nation.get_owned_province_count() != 0) {
908 tag[0] = char(toupper(tag[0]));
909 tag[1] = char(toupper(tag[1]));
910 tag[2] = char(toupper(tag[2]));
911 dcon::national_identity_id
ident{};
912 state.world.for_each_national_identity([&](dcon::national_identity_id
id) {
914 if(curr[0] == tag[0] && curr[1] == tag[1] && curr[2] == tag[2])
922 float icon_baseline = baseline_y + (f.
internal_ascender / 64.f * font_size) - font_size;
925 glActiveTexture(GL_TEXTURE0);
930 glBindTexture(GL_TEXTURE_2D, state.open_gl.army_icon_tex );
933 glBindTexture(GL_TEXTURE_2D, state.open_gl.navy_icon_tex);
937 glBindTexture(GL_TEXTURE_2D, state.open_gl.checkmark_icon_tex);
938 icon_baseline += font_size * 0.1f;
943 ? state.open_gl.color_blind_cross_icon_tex
944 : state.open_gl.cross_icon_tex;
945 glBindTexture(GL_TEXTURE_2D, false_icon);
946 icon_baseline += font_size * 0.1f;
952 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, icon_subroutines[0], icon_subroutines[1]);
954 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, icon_baseline, scale * font_size, scale * font_size);
955 glUniform4f(state.open_gl.ui_shader_subrect_uniform, 0.f, 1.f, 0.f, 1.f);
956 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
960 float icon_baseline = baseline_y + (f.
internal_ascender / 64.f * font_size) - font_size;
963 auto nation = fat_id.get_nation_from_identity_holder();
965 if(
bool(nation.id) && nation.get_owned_province_count() != 0) {
973 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, icon_subroutines[0], icon_subroutines[1]);
976 glActiveTexture(GL_TEXTURE0);
977 glBindTexture(GL_TEXTURE_2D, flag_texture_handle);
978 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x, icon_baseline + font_size * 0.15f, 1.5f * font_size * 0.9f, font_size * 0.9f);
979 glUniform4f(state.open_gl.ui_shader_subrect_uniform, 0.f, 1.f, 0.f, 1.f);
980 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
984 auto ascender_size = f.
ascender(int32_t(font_size));
986 float icon_baseline = baseline_y + top_adj + ascender_size;
993 state.ui_state.defs_by_name.find(
994 state.lookup_key(
"gfx_storage_unit_types")
996 ].data.image.gfx_object;
998 auto& gfx_def = state.ui_defs.gfx[gfx_id];
1000 auto frame = state.military_definitions.unit_base_definitions[id].icon - 1;
1006 gfx_def.number_of_frames,
1007 float(x) - ascender_size * 0.125f,
1008 icon_baseline - ascender_size,
1009 ascender_size * 1.25f,
1010 ascender_size * 1.25f,
1013 gfx_def.is_vertically_flipped(),
1020 float x,
float y,
float w,
float h
1024 state.ui_state.defs_by_name.find(
1025 state.lookup_key(
"gfx_storage_commodity")
1026 )->second.definition
1027 ].data.image.gfx_object;
1029 auto& gfx_def = state.ui_defs.gfx[gfx_id];
1031 auto frame = state.world.commodity_get_icon(cid);
1037 gfx_def.number_of_frames,
1044 gfx_def.is_vertically_flipped(),
1051 float x,
float baseline_y,
1054 float icon_baseline = baseline_y + (f.
internal_ascender / 64.f * font_size) - font_size;
1059 font_size, font_size
1065 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
1068 unsigned int glyph_count =
static_cast<unsigned int>(txt.
glyph_info.size());
1069 for(
unsigned int i = 0; i < glyph_count; i++) {
1070 hb_codepoint_t glyphid = txt.
glyph_info[i].codepoint;
1075 glBindVertexBuffer(0, state.open_gl.sub_square_buffers[gso.texture_slot & 63], 0,
sizeof(GLfloat) * 4);
1078 glActiveTexture(GL_TEXTURE0);
1079 glBindTexture(GL_TEXTURE_2D, f.
textures[gso.texture_slot >> 6]);
1080 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, x + x_offset * size / 64.f, baseline_y + y_offset * size / 64.f, size, size);
1081 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1082 x += x_advance * size / 64.f;
1088 std::string codepoints =
"";
1090 codepoints.push_back(
char(txt.
glyph_info[i].codepoint));
1094 float adv = 1.0f / font.
width;
1097 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
1112 glActiveTexture(GL_TEXTURE0);
1113 glBindTexture(GL_TEXTURE_2D, font.
ftexid);
1115 for(
uint32_t i = 0; i < count; ++i) {
1117 if(i != 0 && i < count - 1 && ch == 0xC2 &&
uint8_t(codepoints[i + 1]) == 0xA3) {
1120 }
else if(ch == 0xA4) {
1123 auto const& f = font.
chars[ch];
1124 float CurX = x + f.x_offset;
1125 float CurY = y + f.y_offset;
1126 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, CurX, CurY,
float(f.width),
float(f.height));
1127 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, c.
r, c.
g, c.
b);
1128 glUniform4f(state.open_gl.ui_shader_subrect_uniform,
float(f.x) /
float(font.
width) ,
1129 float(f.width) /
float(font.
width) ,
float(f.y) /
float(font.
width) ,
1130 float(f.height) /
float(font.
width)
1132 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1139 glUniform3f(state.open_gl.ui_shader_inner_color_uniform, c.
r, c.
g, c.
b);
1140 glUniform1f(state.open_gl.ui_shader_border_size_uniform, 0.08f * 16.0f / size);
1146 if(state.user_settings.use_classic_fonts) {
1154 for(int32_t i = 0; i < static_cast<int32_t>(
count); ++i) {
1155 buffer[i * 4] =
static_cast<float>(i) /
static_cast<float>(
count - 1);
1156 buffer[i * 4 + 1] = 1.0f - v[i];
1157 buffer[i * 4 + 2] = 0.5f;
1158 buffer[i * 4 + 3] = v[i];
1160 pending_data_update =
true;
1164 for(int32_t i = 0; i < static_cast<int32_t>(
count); ++i) {
1165 buffer[i * 4] =
static_cast<float>(i) /
static_cast<float>(
count - 1);
1166 buffer[i * 4 + 1] = 0.5f;
1167 buffer[i * 4 + 2] = 0.5f;
1168 buffer[i * 4 + 3] = 0.5f;
1170 pending_data_update =
true;
1174 if(buffer_handle == 0) {
1175 glGenBuffers(1, &buffer_handle);
1177 glBindBuffer(GL_ARRAY_BUFFER, buffer_handle);
1178 glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) *
count * 4,
nullptr, GL_DYNAMIC_DRAW);
1180 if(buffer && pending_data_update) {
1181 glBindBuffer(GL_ARRAY_BUFFER, buffer_handle);
1182 glBufferSubData(GL_ARRAY_BUFFER, 0,
sizeof(GLfloat) *
count * 4, buffer);
1183 pending_data_update =
false;
1186 glBindVertexBuffer(0, buffer_handle, 0,
sizeof(GLfloat) * 4);
1190 return state.open_gl.msaa_enabled;
1194 int32_t file_channels = 4;
1198 auto data = stbi_load_from_memory(
reinterpret_cast<uint8_t const*
>(content.data), int32_t(content.file_size), &size_x, &size_y, &file_channels, 4);
1203 GLuint texture_handle;
1204 glGenTextures(1, &texture_handle);
1205 const GLuint internalformats[] = { GL_R8, GL_RG8, GL_RGB8, GL_RGBA8 };
1206 const GLuint formats[] = { GL_RED, GL_RG, GL_RGB, GL_RGBA };
1207 if(texture_handle) {
1208 glBindTexture(GL_TEXTURE_2D, texture_handle);
1209 glTexStorage2D(GL_TEXTURE_2D, 1, internalformats[channels - 1], size_x, size_y);
1210 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size_x, size_y, formats[channels - 1], GL_UNSIGNED_BYTE,
data);
1211 glBindTexture(GL_TEXTURE_2D, 0);
1214 return texture_handle;
1217 auto file = open_file(dir, file_name);
1225 glBindTexture(texture_type, texture_handle);
1226 if(filter == GL_LINEAR_MIPMAP_NEAREST || filter == GL_LINEAR_MIPMAP_LINEAR) {
1227 glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter);
1228 glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1229 glGenerateMipmap(texture_type);
1231 glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, filter);
1232 glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1234 glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, wrap);
1235 glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, wrap);
1236 glBindTexture(texture_type, 0);
1242 GLuint texture_handle = 0;
1243 glGenTextures(1, &texture_handle);
1244 if(texture_handle) {
1245 glBindTexture(GL_TEXTURE_2D_ARRAY, texture_handle);
1249 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, GLsizei(p_dx), GLsizei(p_dy), GLsizei(tiles_x * tiles_y), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1250 glPixelStorei(GL_UNPACK_ROW_LENGTH,
image.
size_x);
1251 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
image.
size_y);
1253 for(int32_t x = 0; x < tiles_x; x++)
1254 for(int32_t y = 0; y < tiles_y; y++)
1255 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, GLint(x * tiles_x + y), GLsizei(p_dx), GLsizei(p_dy), 1, GL_RGBA, GL_UNSIGNED_BYTE, ((
uint32_t const*)
image.
data) + (x * p_dy *
image.
size_x + y * p_dx));
1257 set_gltex_parameters(texture_handle, GL_TEXTURE_2D_ARRAY, GL_LINEAR_MIPMAP_NEAREST, GL_REPEAT);
1258 glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
1259 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1260 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
1262 return texture_handle;
1266 if(state.x_size > max_x || state.y_size > max_y) {
1267 max_x = std::max(max_x, state.x_size);
1268 max_y = std::max(max_y, state.y_size);
1271 glDeleteTextures(1, &texture_handle);
1273 glDeleteFramebuffers(1, &framebuffer);
1275 glGenFramebuffers(1, &framebuffer);
1276 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1278 glGenTextures(1, &texture_handle);
1279 glBindTexture(GL_TEXTURE_2D, texture_handle);
1280 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, max_x, max_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
1281 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1284 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture_handle, 0);
1286 GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
1287 glDrawBuffers(1, DrawBuffers);
1289 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1290 glClear(GL_COLOR_BUFFER_BIT);
1292 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1293 glUseProgram(state.open_gl.ui_shader_program);
1294 glUniform1i(state.open_gl.ui_shader_texture_sampler_uniform, 0);
1295 glUniform1i(state.open_gl.ui_shader_secondary_texture_sampler_uniform, 1);
1296 glUniform1f(state.open_gl.ui_shader_screen_width_uniform,
float(max_x) / state.user_settings.ui_scale);
1297 glUniform1f(state.open_gl.ui_shader_screen_height_uniform,
float(max_y) / state.user_settings.ui_scale);
1298 glUniform1f(state.open_gl.ui_shader_gamma_uniform, state.user_settings.gamma);
1299 glViewport(0, 0, max_x, max_y);
1300 glDepthRange(-1.0f, 1.0f);
1302 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1304 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1305 glClear(GL_COLOR_BUFFER_BIT);
1307 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1308 glUseProgram(state.open_gl.ui_shader_program);
1309 glUniform1i(state.open_gl.ui_shader_texture_sampler_uniform, 0);
1310 glUniform1i(state.open_gl.ui_shader_secondary_texture_sampler_uniform, 1);
1311 glUniform1f(state.open_gl.ui_shader_screen_width_uniform,
float(max_x) / state.user_settings.ui_scale);
1312 glUniform1f(state.open_gl.ui_shader_screen_height_uniform,
float(max_y) / state.user_settings.ui_scale);
1313 glUniform1f(state.open_gl.ui_shader_gamma_uniform, state.user_settings.gamma);
1314 glViewport(0, 0, max_x, max_y);
1315 glDepthRange(-1.0f, 1.0f);
1319 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1322 return texture_handle;
1326 glDeleteTextures(1, &texture_handle);
1328 glDeleteFramebuffers(1, &framebuffer);
1330void render_subrect(
sys::state const& state,
float target_x,
float target_y,
float target_width,
float target_height,
float source_x,
float source_y,
float source_width,
float source_height, GLuint texture_handle) {
1333 glUniform2ui(state.open_gl.ui_shader_subroutines_index_uniform, subroutines[0], subroutines[1]);
1335 glActiveTexture(GL_TEXTURE0);
1336 glBindTexture(GL_TEXTURE_2D, texture_handle);
1338 glUniform4f(state.open_gl.ui_shader_d_rect_uniform, target_x, target_y, target_width, target_height);
1339 glUniform4f(state.open_gl.ui_shader_subrect_uniform, source_x , source_width , source_y , source_height );
1340 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1344 start_state.
ready(state);
1345 state.current_scene.get_root(state)->impl_render(state, 0, 0);
1346 start_state.
finish(state);
1352 ms_run_time = runtime;
1353 start_time = std::chrono::steady_clock::now();
1359 if(needs_new_state) {
1360 end_state.
ready(state);
1361 state.current_scene.get_root(state)->impl_render(state, 0, 0);
1369 auto entry_time = std::chrono::steady_clock::now();
1370 auto ms_count = std::chrono::duration_cast<std::chrono::milliseconds>(entry_time - start_time).count();
1371 if(ms_count > ms_run_time) {
1374 float percent = float(ms_count) / float(ms_run_time);
1378 float extent = cos((percent) * 3.14159f / 2.0f);
1379 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size * extent),
float(y_size),
1380 float(x_pos) * state.user_settings.ui_scale /
float(start_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(start_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(start_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(start_state.max_y),
1386 float extent = cos((percent) * 3.14159f / 2.0f);
1387 render_subrect(state,
float(x_pos + (x_size * (1.0f - extent))),
float(y_pos),
float(x_size * extent),
float(y_size),
1388 float(x_pos) * state.user_settings.ui_scale /
float(start_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(start_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(start_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(start_state.max_y),
1394 float extent = cos((percent) * 3.14159f / 2.0f);
1395 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size),
float(y_size * extent),
1396 float(x_pos) * state.user_settings.ui_scale /
float(start_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(start_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(start_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(start_state.max_y),
1402 float extent = cos((1.0f - percent) * 3.14159f / 2.0f);
1403 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size),
float(y_size),
1404 float(x_pos) * state.user_settings.ui_scale /
float(start_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(start_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(start_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(start_state.max_y),
1406 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size * extent),
float(y_size),
1407 float(x_pos) * state.user_settings.ui_scale /
float(end_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(end_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(end_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(end_state.max_y),
1413 float extent = cos((1.0f - percent) * 3.14159f / 2.0f);
1414 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size),
float(y_size),
1415 float(x_pos) * state.user_settings.ui_scale /
float(start_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(start_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(start_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(start_state.max_y),
1417 render_subrect(state,
float(x_pos + (x_size * (1.0f - extent))),
float(y_pos),
float(x_size * extent),
float(y_size),
1418 float(x_pos) * state.user_settings.ui_scale /
float(end_state.max_x),
float(end_state.max_y - y_pos) * state.user_settings.ui_scale /
float(end_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(end_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(end_state.max_y),
1424 float extent = cos((1.0f - percent) * 3.14159f / 2.0f);
1425 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size),
float(y_size),
1426 float(x_pos) * state.user_settings.ui_scale /
float(start_state.max_x),
float(start_state.max_y - y_pos) * state.user_settings.ui_scale /
float(start_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(start_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(start_state.max_y),
1428 render_subrect(state,
float(x_pos),
float(y_pos),
float(x_size),
float(y_size * extent),
1429 float(x_pos) * state.user_settings.ui_scale /
float(end_state.max_x),
float(end_state.max_y - y_pos) * state.user_settings.ui_scale /
float(end_state.max_y),
float(x_size) * state.user_settings.ui_scale /
float(end_state.max_x),
float(-y_size) * state.user_settings.ui_scale /
float(end_state.max_y),
void start_animation(sys::state &state, int32_t x, int32_t y, int32_t w, int32_t h, type t, int32_t runtime)
void post_update_frame(sys::state &state)
void render(sys::state &state)
void ready(sys::state &state)
void finish(sys::state &state)
std::array< char_descriptor, 256 > chars
float top_adjustment(int32_t size) const
ankerl::unordered_dense::map< char32_t, glyph_sub_offset > glyph_positions
float ascender(int32_t size) const
std::vector< uint32_t > textures
#define assert(condition)
flag_type get_current_flag_type(sys::state const &state, dcon::nation_id target_nation)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
std::string int_to_tag(uint32_t v)
constexpr GLuint piechart
constexpr GLuint interactable
constexpr GLuint frame_stretch
constexpr GLuint no_filter
constexpr GLuint transparent_color
constexpr GLuint progress_bar
constexpr GLuint alpha_color
constexpr GLuint use_mask
constexpr GLuint stripchart
constexpr GLuint linegraph_acolor
constexpr GLuint subsprite_b
constexpr GLuint barchart
constexpr GLuint disabled
constexpr GLuint linegraph
constexpr GLuint subsprite_c
constexpr GLuint alternate_tint
constexpr GLuint interactable_disabled
constexpr GLuint solid_color
constexpr GLuint sub_sprite
constexpr GLuint linegraph_color
void render_tinted_subsprite(sys::state const &state, int frame, int total_frames, float x, float y, float width, float height, float r, float g, float b, GLuint texture_handle, ui::rotation rot, bool flipped, bool rtl)
std::string_view opengl_get_error_name(GLenum t)
void initialize_opengl(sys::state &state)
GLuint make_gl_texture(uint8_t *data, uint32_t size_x, uint32_t size_y, uint32_t channels)
void create_opengl_context(sys::state &state)
void render_barchart(sys::state const &state, color_modification enabled, float x, float y, float width, float height, data_texture &t, ui::rotation r, bool flipped, bool rtl)
void initialize_msaa(sys::state &state, int32_t size_x, int32_t size_y)
void render_colored_rect(sys::state const &state, float x, float y, float width, float height, float red, float green, float blue, ui::rotation r, bool flipped, bool rtl)
bool msaa_enabled(sys::state const &state)
void load_shaders(sys::state &state)
void render_bordered_rect(sys::state const &state, color_modification enabled, float border_size, float x, float y, float width, float height, GLuint texture_handle, ui::rotation r, bool flipped, bool rtl)
void render_alpha_colored_rect(sys::state const &state, float x, float y, float width, float height, float red, float green, float blue, float alpha)
void internal_text_render(sys::state &state, text::stored_glyphs const &txt, float x, float baseline_y, float size, text::font &f)
void render_piechart(sys::state const &state, color_modification enabled, float x, float y, float size, data_texture &t)
void render_masked_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, GLuint mask_texture_handle, ui::rotation r, bool flipped, bool rtl)
void load_global_squares(sys::state &state)
void deinitialize_msaa(sys::state &state)
void render_new_text(sys::state &state, text::stored_glyphs const &txt, color_modification enabled, float x, float y, float size, color3f const &c, text::font &f)
void render_text_commodity_icon(sys::state &state, text::embedded_commodity_icon ico, float x, float baseline_y, float font_size, text::font &f)
auto map_color_modification_to_index(color_modification e)
void render_subsprite(sys::state const &state, color_modification enabled, int frame, int total_frames, float x, float y, float width, float height, GLuint texture_handle, ui::rotation r, bool flipped, bool rtl)
void render_text(sys::state &state, text::stored_glyphs const &txt, color_modification enabled, float x, float y, color3f const &c, uint16_t font_id)
void render_linegraph(sys::state const &state, color_modification enabled, float x, float y, float width, float height, lines &l)
void render_text_flag(sys::state &state, text::embedded_flag ico, float x, float baseline_y, float font_size, text::font &f, ogl::color_modification cmod)
GLuint load_texture_array_from_file(simple_fs::file &file, int32_t tiles_x, int32_t tiles_y)
void bind_vertices_by_rotation(sys::state const &state, ui::rotation r, bool flipped, bool rtl)
void render_simple_rect(sys::state const &state, float x, float y, float width, float height, ui::rotation r, bool flipped, bool rtl)
void render_subrect(sys::state const &state, float target_x, float target_y, float target_width, float target_height, float source_x, float source_y, float source_width, float source_height, GLuint texture_handle)
void set_gltex_parameters(GLuint texture_handle, GLuint texture_type, GLuint filter, GLuint wrap)
void render_commodity_icon(sys::state &state, dcon::commodity_id cid, float x, float y, float w, float h)
image load_stb_image(simple_fs::file &file)
GLuint create_program(std::string_view vertex_shader, std::string_view fragment_shader)
void render_textured_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, ui::rotation r, bool flipped, bool rtl)
GLuint SOIL_direct_load_DDS_from_memory(unsigned char const *const buffer, uint32_t buffer_length, uint32_t &width, uint32_t &height, int soil_flags)
bool display_tag_is_valid(sys::state &state, char tag[3])
void render_tinted_rect(sys::state const &state, float x, float y, float width, float height, float r, float g, float b, ui::rotation rot, bool flipped, bool rtl)
@ SOIL_FLAG_TEXTURE_REPEATS
void load_special_icons(sys::state &state)
void render_classic_text(sys::state &state, text::stored_glyphs const &txt, float x, float y, float size, color_modification enabled, color3f const &c, text::bm_font const &font, text::font &base_font)
void render_stripchart(sys::state const &state, color_modification enabled, float x, float y, float sizex, float sizey, data_texture &t)
GLuint get_texture_handle(sys::state &state, dcon::texture_id id, bool keep_data)
std::string_view framebuffer_error(GLenum e)
void render_text_icon(sys::state &state, text::embedded_icon ico, float x, float baseline_y, float font_size, text::font &f, ogl::color_modification cmod)
GLint compile_shader(std::string_view source, GLenum type)
void render_tinted_textured_rect(sys::state const &state, float x, float y, float width, float height, float r, float g, float b, GLuint texture_handle, ui::rotation rot, bool flipped, bool rtl)
void render_text_unit_icon(sys::state &state, text::embedded_unit_icon ico, float x, float baseline_y, float font_size, text::font &f, ogl::color_modification cmod)
GLuint get_flag_texture_handle_from_tag(sys::state &state, const char tag[3])
void render_textured_rect_direct(sys::state const &state, float x, float y, float width, float height, uint32_t handle)
void notify_user_of_fatal_opengl_error(std::string message)
void render_progress_bar(sys::state const &state, color_modification enabled, float progress, float x, float y, float width, float height, GLuint left_texture_handle, GLuint right_texture_handle, ui::rotation r, bool flipped, bool rtl)
GLuint get_flag_handle(sys::state &state, dcon::national_identity_id nat_id, culture::flag_type type)
directory open_directory(directory const &dir, native_string_view directory_name)
std::optional< file > open_file(directory const &dir, native_string_view file_name)
file_contents view_contents(file const &f)
constexpr int magnification_factor
int32_t size_from_font_id(uint16_t id)
bm_font const & get_bm_font(sys::state &state, uint16_t font_handle)
font_selection font_index_from_font_id(sys::state &state, uint16_t id)
void emit_error_message(std::string const &content, bool fatal)
std::string_view native_string_view
Holds important data about the game world, state, and other data regarding windowing,...
dcon::commodity_id commodity
dcon::national_identity_id tag
dcon::unit_type_id unit_type
std::vector< stored_glyph > glyph_info