From 520e4e67cd9ff53f3c3512c80d07193625e07e3e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 16 Jun 2023 09:38:15 -0700 Subject: New plugin architecture. --- gltfview/src/plugins/texture_view.c | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 gltfview/src/plugins/texture_view.c (limited to 'gltfview/src/plugins/texture_view.c') diff --git a/gltfview/src/plugins/texture_view.c b/gltfview/src/plugins/texture_view.c new file mode 100644 index 0000000..f2c650f --- /dev/null +++ b/gltfview/src/plugins/texture_view.c @@ -0,0 +1,94 @@ +#include "texture_view.h" + +#include +#include +#include +#include + +#include + +#include +#include + +// Default texture to load if no texture is provided. +static const char* CLOUDS1_TEXTURE = "/assets/skybox/clouds1/clouds1_west.bmp"; + +State* init(Game* game) { + assert(game); + + State* state = calloc(1, sizeof(State)); + return state; +} + +bool boot(State* state, Game* game) { + assert(state); + assert(game); + + // Usage: [texture file] + const char* texture_file = game->argc > 1 ? game->argv[1] : CLOUDS1_TEXTURE; + + RenderBackend* render_backend = gfx_get_render_backend(game->gfx); + + Texture* texture = gfx_load_texture( + render_backend, &(LoadTextureCmd){ + .origin = TextureFromFile, + .type = LoadTexture, + .filtering = LinearFiltering, + .mipmaps = false, + .data.texture.filepath = mstring_make(texture_file)}); + + Camera* camera = gfx_get_camera_camera(game->camera); + spatial3_set_position(&camera->spatial, vec3_make(0, 0, 1)); + + ShaderProgram* shader = gfx_make_view_texture_shader(render_backend); + if (!shader) { + return false; + } + + Geometry* geometry = gfx_make_quad_11(render_backend); + if (!geometry) { + return false; + } + + MaterialDesc material_desc = (MaterialDesc){0}; + material_desc.uniforms[0] = (ShaderUniform){ + .type = UniformTexture, + .value.texture = texture, + .name = sstring_make("Texture")}; + material_desc.num_uniforms = 1; + Material* material = gfx_make_material(&material_desc); + if (!material) { + return false; + } + + MeshDesc mesh_desc = (MeshDesc){0}; + mesh_desc.geometry = geometry; + mesh_desc.material = material; + mesh_desc.shader = shader; + Mesh* mesh = gfx_make_mesh(&mesh_desc); + if (!mesh) { + return false; + } + + SceneObject* object = gfx_make_object(); + if (!object) { + return false; + } + gfx_add_object_mesh(object, mesh); + + SceneNode* node = gfx_make_object_node(object); + SceneNode* root = gfx_get_scene_root(game->scene); + gfx_set_node_parent(node, root); + + return true; +} + +void update(State* state, Game* game, double t, double dt) { + assert(state); + assert(game); +} + +void render(State* state, const Game* game) { + assert(state); + assert(game); +} -- cgit v1.2.3