116 lines
2.7 KiB
C++
116 lines
2.7 KiB
C++
#include "allocate/factory.h"
|
|
#include "code/return.h"
|
|
#include "target/linux/draw/opengl_x11_service.h"
|
|
#include <X11/Xlib.h>
|
|
#include <X11/X.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <string>
|
|
#include <GL/gl.h>
|
|
#include <GL/glx.h>
|
|
#include <GL/glu.h>
|
|
|
|
opengl_x11_service_t::opengl_x11_service_t(
|
|
opengl_x11_service_t::configuration_t* configuration_p
|
|
) {
|
|
configuration_m = configuration_p;
|
|
}
|
|
|
|
return_t<opengl_x11_service_t::error_t, XVisualInfo*> opengl_x11_service_t::get_visual_info(
|
|
Display* display_p
|
|
) {
|
|
return_t<opengl_x11_service_t::error_t, XVisualInfo*> return_l;
|
|
return_l.error_m = opengl_x11_service_t::error_t::none;
|
|
GLint attributes_l[] = {
|
|
GLX_RGBA,
|
|
GLX_DEPTH_SIZE,
|
|
24,
|
|
GLX_DOUBLEBUFFER,
|
|
None
|
|
};
|
|
XVisualInfo *visual_info_l = glXChooseVisual(
|
|
display_p,
|
|
0,
|
|
attributes_l
|
|
);
|
|
if (visual_info_l == NULL) {
|
|
return_l.error_m = opengl_x11_service_t::error_t::no_visual_found;
|
|
}
|
|
return_l.value_m = visual_info_l;
|
|
return return_l;
|
|
}
|
|
|
|
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::initialize_context(
|
|
Display* display_p,
|
|
XVisualInfo* visual_info_p,
|
|
Window window_p
|
|
){
|
|
void_t<opengl_x11_service_t::error_t> void_l;
|
|
configuration_m->glx_context_m = glXCreateContext(
|
|
display_p,
|
|
visual_info_p,
|
|
NULL,
|
|
GL_TRUE
|
|
);
|
|
glXMakeCurrent(
|
|
display_p,
|
|
window_p,
|
|
configuration_m->glx_context_m
|
|
);
|
|
void_l.error_m = opengl_x11_service_t::error_t::none;
|
|
return void_l;
|
|
}
|
|
|
|
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::swap_buffers(
|
|
Display* display_p,
|
|
Window window_p
|
|
) {
|
|
void_t<opengl_x11_service_t::error_t> void_l;
|
|
void_l.error_m = opengl_x11_service_t::error_t::none;
|
|
glXSwapBuffers(
|
|
display_p,
|
|
window_p
|
|
);
|
|
return void_l;
|
|
}
|
|
|
|
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::dispose(
|
|
Display* display_p
|
|
) {
|
|
void_t<opengl_x11_service_t::error_t> void_l;
|
|
void_l.error_m = opengl_x11_service_t::error_t::none;
|
|
glXMakeCurrent(
|
|
display_p,
|
|
None,
|
|
NULL
|
|
);
|
|
glXDestroyContext(
|
|
display_p,
|
|
configuration_m->glx_context_m
|
|
);
|
|
return void_l;
|
|
}
|
|
|
|
return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> opengl_x11_service_factory_t::create(
|
|
opengl_x11_service_t::configuration_t* configuration_p
|
|
) {
|
|
opengl_x11_service_t* opengl_x11_service_l = new opengl_x11_service_t(
|
|
configuration_p
|
|
);
|
|
return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> return_l;
|
|
return_l.error_m = opengl_x11_service_t::error_t::none;
|
|
return_l.value_m = opengl_x11_service_l;
|
|
return return_l;
|
|
}
|
|
|
|
void_t<opengl_x11_service_t::error_t> opengl_x11_service_factory_t::dispose(
|
|
opengl_x11_service_t* opengl_x11_service_p
|
|
) {
|
|
delete opengl_x11_service_p;
|
|
void_t<opengl_x11_service_t::error_t> void_l;
|
|
void_l.error_m = opengl_x11_service_t::error_t::none;
|
|
return void_l;
|
|
}
|
|
|