aboutsummaryrefslogtreecommitdiff
path: root/uniform.c
blob: 2face0a66602f39dd005df08f9906c843de28136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <sys/time.h>
#include <time.h>
#include <GL/glew.h>

#include "uniform.h"
#include "consts.h"

int time_start = 0;
GLFWwindow* window = NULL;

void init_uniforms() {
	window = glfwGetCurrentContext();
	time_start = time(NULL);
}

//! update `uniform float time`
static void update_u_time() {
	struct timeval t;
	gettimeofday(&t, NULL);
	t.tv_sec -= time_start;
	float time = t.tv_sec + (t.tv_usec / 1e6);
	glUniform1f(U_LOC_TIME, time);
}

//! update `uniform ivec2 window`
static void update_u_window() {
	int width, height;
	glfwGetWindowSize(window, &width, &height);
	glUniform2i(U_LOC_WINDOW, width, height);
}

void update_uniforms() {
	update_u_time();
	update_u_window();
}