backup nonfunction opengl 4 code in another branch
This commit is contained in:
parent
a932fc00ea
commit
08527cac9f
1 changed files with 133 additions and 55 deletions
|
|
@ -1,9 +1,11 @@
|
|||
/* $Id$ */
|
||||
|
||||
// #include <GL/gl.h>
|
||||
#include <GL/gl.h>
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <cairo/cairo.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -30,6 +32,24 @@ PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
|
|||
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
|
||||
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
|
||||
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatus;
|
||||
PFNGLCREATEBUFFERSPROC glCreateBuffers;
|
||||
PFNGLBINDBUFFERPROC glBindBuffer;
|
||||
PFNGLBUFFERDATAPROC glBufferData;
|
||||
PFNGLBUFFERSUBDATAPROC glBufferSubData;
|
||||
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
|
||||
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
|
||||
PFNGLVERTEXARRAYVERTEXBUFFERPROC glVertexArrayVertexBuffer;
|
||||
PFNGLVERTEXARRAYATTRIBFORMATPROC glVertexArrayAttribFormat;
|
||||
PFNGLVERTEXARRAYATTRIBBINDINGPROC glVertexArrayAttribBinding;
|
||||
PFNGLENABLEVERTEXARRAYATTRIBPROC glEnableVertexArrayAttrib;
|
||||
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
|
||||
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
|
||||
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
||||
PFNGLATTACHSHADERPROC glAttachShader;
|
||||
PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||
PFNGLCREATESHADERPROC glCreateShader;
|
||||
PFNGLSHADERSOURCEPROC glShaderSource;
|
||||
PFNGLCOMPILESHADERPROC glCompileShader;
|
||||
|
||||
#define WAYLAND_GET_INTERFACE(r, inter) shget(r.wl_protocol_map, inter##_interface.name)
|
||||
|
||||
|
|
@ -155,10 +175,22 @@ static MwBool egl_setup(MwLL self, int width, int height) {
|
|||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGL_NONE};
|
||||
EGLint contextAttribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 1,
|
||||
EGL_CONTEXT_MAJOR_VERSION, 1,
|
||||
EGL_CONTEXT_MAJOR_VERSION, 4,
|
||||
EGL_CONTEXT_MINOR_VERSION, 1,
|
||||
EGL_NONE};
|
||||
GLuint vs, fs;
|
||||
const char* vertex_shader =
|
||||
"#version 410 core\n"
|
||||
"in vec3 vp;"
|
||||
"void main() {"
|
||||
" gl_Position = vec4( vp, 1.0 );"
|
||||
"}";
|
||||
const char* fragment_shader =
|
||||
"#version 410 core\n"
|
||||
"out vec4 frag_colour;"
|
||||
"void main() {"
|
||||
" frag_colour = vec4( 0.5, 0.0, 0.5, 1.0 );"
|
||||
"}";
|
||||
|
||||
EGLDisplay display = eglGetDisplay(self->wayland.display);
|
||||
if(display == EGL_NO_DISPLAY) {
|
||||
|
|
@ -217,10 +249,29 @@ static MwBool egl_setup(MwLL self, int width, int height) {
|
|||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)eglGetProcAddress("glGenRenderbuffers");
|
||||
// glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)eglGetProcAddress("glRenderbufferStorage");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)eglGetProcAddress("glFramebufferRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)eglGetProcAddress("glBindRenderbuffer");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)eglGetProcAddress("glBindFramebuffer");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)eglGetProcAddress("glCheckFramebufferStatus");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)eglGetProcAddress("glFramebufferRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)eglGetProcAddress("glBindRenderbuffer");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)eglGetProcAddress("glBindFramebuffer");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)eglGetProcAddress("glCheckFramebufferStatus");
|
||||
glCreateBuffers = (PFNGLCREATEBUFFERSPROC)eglGetProcAddress("glCreateBuffers");
|
||||
glBindBuffer = (PFNGLBINDBUFFERPROC)eglGetProcAddress("glBindBuffer");
|
||||
glBufferData = (PFNGLBUFFERDATAPROC)eglGetProcAddress("glBufferData");
|
||||
glBufferSubData = (PFNGLBUFFERSUBDATAPROC)eglGetProcAddress("glBufferSubData");
|
||||
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)eglGetProcAddress("glBindVertexArray");
|
||||
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)eglGetProcAddress("glGenVertexArrays");
|
||||
glVertexArrayVertexBuffer = (PFNGLVERTEXARRAYVERTEXBUFFERPROC)eglGetProcAddress("glVertexArrayVertexBuffer");
|
||||
glVertexArrayAttribFormat = (PFNGLVERTEXARRAYATTRIBFORMATPROC)eglGetProcAddress("glVertexArrayAttribFormat");
|
||||
glVertexArrayAttribBinding = (PFNGLVERTEXARRAYATTRIBBINDINGPROC)eglGetProcAddress("glVertexArrayAttribBinding");
|
||||
glEnableVertexArrayAttrib = (PFNGLENABLEVERTEXARRAYATTRIBPROC)eglGetProcAddress("glEnableVertexArrayAttrib");
|
||||
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)eglGetProcAddress("glVertexAttribPointer");
|
||||
glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)eglGetProcAddress("glEnableVertexAttribArray");
|
||||
glCreateProgram = (PFNGLCREATEPROGRAMPROC)eglGetProcAddress("glCreateProgram");
|
||||
glAttachShader = (PFNGLATTACHSHADERPROC)eglGetProcAddress("glAttachShader");
|
||||
glLinkProgram = (PFNGLLINKPROGRAMPROC)eglGetProcAddress("glLinkProgram");
|
||||
|
||||
glCreateShader = (PFNGLCREATESHADERPROC)eglGetProcAddress("glCreateShader");
|
||||
glShaderSource = (PFNGLSHADERSOURCEPROC)eglGetProcAddress("glShaderSource");
|
||||
glCompileShader = (PFNGLCOMPILESHADERPROC)eglGetProcAddress("glCompileShader");
|
||||
|
||||
glGenTextures(1, &self->wayland.fbo_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, self->wayland.fbo_texture);
|
||||
|
|
@ -259,10 +310,32 @@ static MwBool egl_setup(MwLL self, int width, int height) {
|
|||
self->wayland.egl_display = display;
|
||||
self->wayland.egl_surface = surface;
|
||||
self->wayland.egl_context = context;
|
||||
|
||||
vs = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vs, 1, &vertex_shader, NULL);
|
||||
glCompileShader(vs);
|
||||
fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fs, 1, &fragment_shader, NULL);
|
||||
glCompileShader(fs);
|
||||
|
||||
GLuint shader_program = glCreateProgram();
|
||||
glAttachShader(shader_program, fs);
|
||||
glAttachShader(shader_program, vs);
|
||||
glLinkProgram(shader_program);
|
||||
|
||||
printf("EGL success\n");
|
||||
return MwTRUE;
|
||||
}
|
||||
|
||||
static void egl_vbo_setup(MwLL self) {
|
||||
glCreateBuffers(1, &self->wayland.vertex_buffer);
|
||||
glGenVertexArrays(1, &self->wayland.vertex_array);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self->wayland.vertex_buffer);
|
||||
|
||||
glVertexAttribPointer(self->wayland.z_index, 2, GL_INT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(self->wayland.z_index);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_configure(void* data,
|
||||
struct xdg_toplevel* xdg_toplevel,
|
||||
MwI32 width, MwI32 height,
|
||||
|
|
@ -283,6 +356,7 @@ static void xdg_toplevel_configure(void* data,
|
|||
|
||||
if(!self->wayland.egl_setup) {
|
||||
self->wayland.egl_setup = egl_setup(self, width, height);
|
||||
egl_vbo_setup(self);
|
||||
MwLLForceRender(self);
|
||||
} else {
|
||||
wl_egl_window_resize(self->wayland.egl_window_native, width, height, 0, 0);
|
||||
|
|
@ -290,18 +364,6 @@ static void xdg_toplevel_configure(void* data,
|
|||
glLoadIdentity();
|
||||
glOrtho(0, width, height, 0, -1, 1);
|
||||
self->wayland.do_clear = MwTRUE;
|
||||
|
||||
// glDeleteTextures(1, &self->wayland.fbo_texture);
|
||||
// glGenTextures(1, &self->wayland.fbo_texture);
|
||||
// glBindTexture(GL_TEXTURE_2D, self->wayland.fbo_texture);
|
||||
|
||||
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
// glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -451,8 +513,6 @@ static void setup_toplevel(MwLL r, int x, int y, int width, int height) {
|
|||
// buffer_setup(&r->wayland);
|
||||
|
||||
wl_surface_commit(r->wayland.surface);
|
||||
|
||||
// glGenBuffers(1, &vertex_buffer);
|
||||
}
|
||||
|
||||
static void setup_subsurface(MwLL parent, MwLL r, int x, int y, int width, int height) {
|
||||
|
|
@ -494,7 +554,12 @@ static void setup_subsurface(MwLL parent, MwLL r, int x, int y, int width, int h
|
|||
r->wayland.fbo = parent->wayland.fbo;
|
||||
r->wayland.fbo_texture = parent->wayland.fbo_texture;
|
||||
r->wayland.rbo = parent->wayland.rbo;
|
||||
|
||||
// egl_vbo_setup(r);
|
||||
}
|
||||
|
||||
static int z_index_counter = 0;
|
||||
|
||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||
MwLL r;
|
||||
r = malloc(sizeof(*r));
|
||||
|
|
@ -505,9 +570,10 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
|||
if(width == 0) width = 1;
|
||||
if(height == 0) height = 1;
|
||||
|
||||
r->wayland.ww = width;
|
||||
r->wayland.wh = height;
|
||||
r->wayland.parent = parent;
|
||||
r->wayland.ww = width;
|
||||
r->wayland.wh = height;
|
||||
r->wayland.parent = parent;
|
||||
r->wayland.z_index = z_index_counter++;
|
||||
|
||||
r->wayland.force_redraw = MwFALSE;
|
||||
r->wayland.do_clear = MwFALSE;
|
||||
|
|
@ -555,14 +621,49 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) {
|
|||
}
|
||||
}
|
||||
|
||||
static void polygon_setup(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
|
||||
int i;
|
||||
MwPoint* points_translated = malloc(points_count * sizeof(MwPoint));
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, handle->wayland.fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle->wayland.fbo_texture, 0);
|
||||
glLineWidth(1);
|
||||
glPointSize(5);
|
||||
|
||||
for(i = 0; i < points_count; i++) {
|
||||
points_translated[i].x = ceil(handle->wayland.x) + ceil(points[i].x);
|
||||
points_translated[i].y = ceil(handle->wayland.y) + ceil(points[i].y);
|
||||
printf("%d %d\n", points_translated[i].x, points_translated[i].y);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, handle->wayland.vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, points_count * sizeof(MwPoint), &points_translated[0], GL_STATIC_DRAW);
|
||||
|
||||
glPolygonMode(GL_FRONT, GL_LINE);
|
||||
glPolygonMode(GL_BACK, GL_LINE);
|
||||
glBindVertexArray(handle->wayland.vertex_buffer);
|
||||
if(points_count == 3) {
|
||||
glDrawArrays(GL_TRIANGLES, 0, points_count);
|
||||
} else if(points_count == 4) {
|
||||
glDrawArrays(GL_QUADS, 0, points_count);
|
||||
} else {
|
||||
glDrawArrays(GL_TRIANGLES, 0, points_count);
|
||||
}
|
||||
glPolygonMode(GL_FRONT, GL_FILL);
|
||||
glPolygonMode(GL_BACK, GL_FILL);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
free(points_translated);
|
||||
}
|
||||
|
||||
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
|
||||
/*
|
||||
* TODO: this function sucks shit, ioi needs to make it not suck shit :)
|
||||
*/
|
||||
int i;
|
||||
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)eglGetProcAddress("glBindFramebuffer");
|
||||
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)eglGetProcAddress("glBindRenderbuffer");
|
||||
int w, h;
|
||||
int w, h;
|
||||
|
||||
polygon_setup(handle, points, points_count, color);
|
||||
|
||||
if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) {
|
||||
w = handle->wayland.ww;
|
||||
|
|
@ -576,29 +677,6 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
|
|||
h = parent->wayland.wh;
|
||||
}
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, handle->wayland.fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle->wayland.fbo_texture, 0);
|
||||
glLineWidth(1);
|
||||
|
||||
if(points_count == 3) {
|
||||
glBegin(GL_TRIANGLES);
|
||||
} else if(points_count == 4) {
|
||||
glBegin(GL_QUADS);
|
||||
} else {
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
}
|
||||
|
||||
for(i = 0; i < points_count; i++) {
|
||||
glColor3f(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0);
|
||||
glVertex2f(
|
||||
ceil(handle->wayland.x) + ceil(points[i].x),
|
||||
ceil(handle->wayland.y) + ceil(points[i].y));
|
||||
}
|
||||
glEnd();
|
||||
glFinish();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue