moved to single vertex buffer for all windows
This commit is contained in:
parent
1fabef898e
commit
c7c6cf827c
|
@ -5,24 +5,9 @@ out vec2 local_position;
|
|||
|
||||
uniform mat4 global_transform = mat4(1.0);
|
||||
|
||||
uniform float screen_height;
|
||||
uniform float screen_width;
|
||||
|
||||
uniform float window_x;
|
||||
uniform float window_y;
|
||||
|
||||
uniform float window_width;
|
||||
uniform float window_height;
|
||||
|
||||
void main(void) {
|
||||
local_position = vec2(vertex_position.x/window_width, vertex_position.y/window_height);
|
||||
|
||||
vec3 new_position = (vec4(vertex_position.xyz, 1.0) * global_transform).xyz;
|
||||
|
||||
new_position = vec3(new_position.x/screen_width, new_position.y/screen_height, 0.0);
|
||||
|
||||
new_position = new_position + vec3(window_x/screen_width, window_y/screen_height, 0.0);
|
||||
new_position = new_position * vec3(1.0, -1.0, 1.0);
|
||||
|
||||
gl_Position = vec4(new_position.x, new_position.y, new_position.z, 1.0);
|
||||
// The texture position is the same as the vertices as they go from -1.0 to 1.0
|
||||
// in both dimensions
|
||||
local_position = vec2(vertex_position.x, -vertex_position.y);
|
||||
gl_Position = vec4(vertex_position.x, vertex_position.y, vertex_position.z, 1.0)* global_transform;
|
||||
}
|
115
src/cm.c
115
src/cm.c
|
@ -25,14 +25,14 @@ typedef struct window_vertices_t
|
|||
} window_vertices_t;
|
||||
|
||||
static const char * MAIN_SHADER_UNIFORM_NAMES[] = {
|
||||
"screen_width",
|
||||
"screen_height",
|
||||
// "screen_width",
|
||||
// "screen_height",
|
||||
|
||||
"window_x",
|
||||
"window_y",
|
||||
// "window_x",
|
||||
// "window_y",
|
||||
|
||||
"window_width",
|
||||
"window_height",
|
||||
// "window_width",
|
||||
// "window_height",
|
||||
|
||||
"texture_sampler",
|
||||
|
||||
|
@ -45,14 +45,14 @@ typedef struct main_shader_t
|
|||
|
||||
struct
|
||||
{
|
||||
int screen_width;
|
||||
int screen_height;
|
||||
// int screen_width;
|
||||
// int screen_height;
|
||||
|
||||
int window_x;
|
||||
int window_y;
|
||||
// int window_x;
|
||||
// int window_y;
|
||||
|
||||
int window_width;
|
||||
int window_height;
|
||||
// int window_width;
|
||||
// int window_height;
|
||||
|
||||
int texture_sampler;
|
||||
|
||||
|
@ -154,6 +154,22 @@ WINDOW_INDICES[] = {
|
|||
1, 2, 3,
|
||||
};
|
||||
|
||||
|
||||
static const float
|
||||
WINDOW_VERTICES[] = {
|
||||
// Top right
|
||||
1.0, -1.0, 0.0f,
|
||||
|
||||
// Botom right
|
||||
1.0, 1.0, 0.0f,
|
||||
|
||||
// Bottom left
|
||||
-1.0, 1.0, 0.0f,
|
||||
|
||||
// Top left
|
||||
-1.0, -1.0, 0.0f
|
||||
};
|
||||
|
||||
static inline bool
|
||||
should_render_window( window_node_t * node )
|
||||
{
|
||||
|
@ -342,7 +358,9 @@ static int
|
|||
render_window( window_node_t * window_node )
|
||||
{
|
||||
int ret = 0;
|
||||
float height = 0.0f, width = 0.0f;
|
||||
matrix_t ma, mb, transform;
|
||||
float height = 0.0f, width = 0.0f, x = 0.0f, y = 0.0f,
|
||||
output_width = 0.0f, output_height = 0.0f;
|
||||
window_extra_t * extra = NULL;
|
||||
|
||||
extra = create_window_extra_if_none(window_node);
|
||||
|
@ -350,59 +368,28 @@ render_window( window_node_t * window_node )
|
|||
XGetWindowAttributes(cm.display, cm.output_window, &cm.output_window_attributes);
|
||||
XGetWindowAttributes(cm.display, window_node->window, &window_node->attributes);
|
||||
|
||||
width = window_node->attributes.width;
|
||||
height = window_node->attributes.height;
|
||||
x = (float)window_node->attributes.x;
|
||||
y = (float)window_node->attributes.y;
|
||||
|
||||
float vertices[] = {
|
||||
// Top right
|
||||
width, height, 0.0f,
|
||||
width = (float)window_node->attributes.width;
|
||||
height = (float)window_node->attributes.height;
|
||||
|
||||
// Botom right
|
||||
width, -height, 0.0f,
|
||||
output_width = (float)cm.output_window_attributes.width;
|
||||
output_height = (float)cm.output_window_attributes.height;
|
||||
|
||||
// Bottom left
|
||||
-width, -height, 0.0f,
|
||||
|
||||
// Top left
|
||||
-width, height, 0.0f
|
||||
};
|
||||
|
||||
glBindVertexArray(cm.vao);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, cm.vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cm.ebo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(WINDOW_INDICES), WINDOW_INDICES, GL_STATIC_DRAW);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
if(window_node->attributes.width % 2) x += .5f;
|
||||
if(window_node->attributes.height % 2) y += .5f;
|
||||
|
||||
y = -y;
|
||||
|
||||
// Setup unifroms for main shader
|
||||
glUseProgram(cm.main_shader.program);
|
||||
|
||||
glUniform1f(cm.main_shader.uniforms.screen_height, (float)cm.output_window_attributes.height);
|
||||
glUniform1f(cm.main_shader.uniforms.screen_width, (float)cm.output_window_attributes.width);
|
||||
|
||||
glUniform1f(cm.main_shader.uniforms.window_x, (float)window_node->attributes.x - (float)window_node->attributes.width/2);
|
||||
glUniform1f(cm.main_shader.uniforms.window_y, (float)window_node->attributes.y - (float)window_node->attributes.height/2);
|
||||
|
||||
glUniform1f(cm.main_shader.uniforms.window_height, (float)window_node->attributes.height);
|
||||
glUniform1f(cm.main_shader.uniforms.window_width, (float)window_node->attributes.width);
|
||||
|
||||
glUniform1i(cm.main_shader.uniforms.texture_sampler, 0);
|
||||
|
||||
matrix_t transform = {0}, rotation = {0}, scale = {0};
|
||||
struct pv_t axis = {.z = 1.0, .y = 1.0};
|
||||
|
||||
static float t = 0;
|
||||
make_rotation_matrix(t, &axis, rotation);
|
||||
t += 1.0f;
|
||||
make_scaling_matrix(0.7, 0.7, 0.2, scale);
|
||||
mxm(scale, rotation, transform);
|
||||
make_scaling_matrix(width/output_width, height/output_height, 0.0f, ma);
|
||||
make_translation_matrix((x - width/2.0f)/output_width, (y + height/2.0f)/output_height, 0.0f, mb);
|
||||
mxm(mb, ma, transform);
|
||||
|
||||
glUniformMatrix4fv(cm.main_shader.uniforms.global_transform, 1, GL_FALSE, &transform[0][0]);
|
||||
|
||||
|
@ -430,6 +417,20 @@ cm_render_windows(void)
|
|||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glBindVertexArray(cm.vao);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, cm.vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(WINDOW_VERTICES), WINDOW_VERTICES, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cm.ebo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(WINDOW_INDICES), WINDOW_INDICES, GL_STATIC_DRAW);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
// XGrabServer(cm.display);
|
||||
|
||||
node = wm_get_first_window_node();
|
||||
|
|
20
src/main.c
20
src/main.c
|
@ -1,17 +1,30 @@
|
|||
#include <signal.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "wm.h"
|
||||
#include "cm.h"
|
||||
#include "mema.h"
|
||||
|
||||
static volatile bool stop_loop = false;
|
||||
|
||||
static void
|
||||
signal_handler()
|
||||
{
|
||||
stop_loop = true;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char const *argv[])
|
||||
{
|
||||
uint64_t current_update = 0, last_update = 0, accum = 0;
|
||||
gmema_init();
|
||||
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
|
||||
cm_init(Mod1Mask);
|
||||
|
||||
while(!wm_process_events())
|
||||
while(!wm_process_events() && !stop_loop)
|
||||
{
|
||||
current_update = time_ms();
|
||||
accum += current_update - last_update;
|
||||
|
@ -20,9 +33,10 @@ main(int argc, char const *argv[])
|
|||
if(accum >= 16)
|
||||
{
|
||||
accum = 0;
|
||||
// cm_render_windows();
|
||||
cm_render_windows();
|
||||
}
|
||||
usleep(100);
|
||||
|
||||
usleep(100);
|
||||
}
|
||||
cm_destroy();
|
||||
|
||||
|
|
Loading…
Reference in New Issue