commit 1d79a744f594bc569b9bd769b35e24e8baeeb283
parent 4db80aba976d7495a1d7a38f8af40a35b650e001
Author: William Casarin <jb55@jb55.com>
Date: Mon, 19 Nov 2018 21:21:41 -0800
cache model loading
Diffstat:
6 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
@@ -44,6 +44,7 @@ OBJS += $(SRC)/uniform.o
OBJS += $(SRC)/update.o
OBJS += $(SRC)/util.o
OBJS += $(SRC)/vec3.o
+OBJS += $(SRC)/scene.o
SRCS=$(OBJS:.o=.c)
diff --git a/src/geometry.c b/src/geometry.c
@@ -22,6 +22,8 @@ destroy_buffer_geometry(struct geometry *geom) {
check_gl();
glDeleteBuffers(ARRAY_SIZE(buffers), buffers);
check_gl();
+
+ geom->has_vbos = 0;
}
void bind_geometry(struct geometry *geom, struct attributes *attrs) {
@@ -83,6 +85,7 @@ void init_geometry(struct geometry *geom) {
geom->vertices = NULL;
geom->tex_coords = NULL;
geom->num_uv_components = 2;
+ geom->has_vbos = 0;
geom->vbos.color.handle = 0;
geom->vbos.normal.handle = 0;
@@ -149,6 +152,8 @@ make_buffer_geometry(struct geometry *geom) {
geom->num_indices * (int)sizeof(*geom->indices),
&geom->vbos.index
);
+
+ geom->has_vbos = 1;
}
diff --git a/src/geometry.h b/src/geometry.h
@@ -16,6 +16,7 @@ struct buffer_geometry {
struct geometry {
struct buffer_geometry vbos;
+ int has_vbos;
float min[3];
float max[3];
int num_uv_components;
diff --git a/src/main.c b/src/main.c
@@ -1,24 +1,26 @@
-#include "gl.h"
-#include "game.h"
-#include "slab.h"
+#include "event.h"
+#include "fbo.h"
#include "file.h"
-#include "update.h"
-#include "window.h"
-#include "slab_geom.h"
-#include "slab.h"
+#include "game.h"
#include "geometry.h"
-#include "event.h"
+#include "gl.h"
+#include "hires.h"
+#include "ply.h"
+#include "poisson.h"
#include "render.h"
+#include "scene.h"
+#include "slab.h"
+#include "slab.h"
+#include "slab_geom.h"
#include "terrain.h"
+#include "uniform.h"
+#include "update.h"
#include "util.h"
+#include "window.h"
+
#include <assert.h>
#include <time.h>
-#include "poisson.h"
-#include "uniform.h"
-#include "ply.h"
-#include "fbo.h"
-#include "hires.h"
int main(void)
@@ -56,6 +58,7 @@ int main(void)
SDL_GL_CreateContext(window);
game_init(&game, width, height);
+ default_scene(&game);
check_gl();
double last = hires_time_in_seconds();
@@ -99,7 +102,6 @@ int main(void)
last = new_time;
- GLuint texture = game.test_resources.shadow_buffer.attachments[0];
struct fbo *fbo = &game.test_resources.shadow_buffer;
check_fbo(fbo);
bind_fbo(fbo);
diff --git a/src/model.c b/src/model.c
@@ -11,6 +11,9 @@ void init_model(struct model *model) {
int load_model(struct model *model, const char *name) {
static char path[128] = {0};
+ if (model->geom.has_vbos)
+ return 2;
+
int ok = 0;
// Load mesh
diff --git a/src/model.h b/src/model.h
@@ -8,6 +8,8 @@
#include "geometry.h"
#include "common.h"
+#define MAX_MODELS 128
+
enum shading {
SHADING_TERRAIN,
SHADING_VERT_COLOR,