From 4c7b23e8de2f6677a5db1c6f5218e60ff4aaf55c Mon Sep 17 00:00:00 2001 From: CobaltXII Date: Sun, 30 Dec 2018 13:52:36 -0500 Subject: [PATCH] Large changes to documentation --- src/inc/block.hpp | 5 ++--- src/inc/face.hpp | 2 +- src/inc/image.hpp | 2 +- src/inc/mesh.hpp | 14 ++++++-------- src/inc/program.hpp | 2 +- src/inc/texture.hpp | 13 ++++++++----- src/inc/voxel.hpp | 6 ++---- src/inc/world.hpp | 6 +++--- src/main.hpp | 14 ++++---------- 9 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/inc/block.hpp b/src/inc/block.hpp index 06d5671..078af35 100644 --- a/src/inc/block.hpp +++ b/src/inc/block.hpp @@ -92,8 +92,7 @@ enum block_id id_null }; -// Returns true if the given block_id has any non-opaque pixels. Otherwise, -// returns false. +// Returns true if the block is not opaque. Otherwise, returns false. inline bool is_transparent(block_id id) { @@ -114,7 +113,7 @@ inline bool is_transparent(block_id id) } return false; -} +} // Conversion from block_id to std::string. diff --git a/src/inc/face.hpp b/src/inc/face.hpp index cf6f2b4..025bc82 100644 --- a/src/inc/face.hpp +++ b/src/inc/face.hpp @@ -1,7 +1,7 @@ #include // A struct of type face_info represents the layer (w coordinate) of each face -// of a block. It is used to map the correct texture on to each face of a +// of a block. It is used to map the correct texture onto each face of a // block. struct face_info diff --git a/src/inc/image.hpp b/src/inc/image.hpp index 21c8dc2..ec7dbb8 100644 --- a/src/inc/image.hpp +++ b/src/inc/image.hpp @@ -1,7 +1,7 @@ #include #include -// A list of all the files in /tex (excluding file extensions). +// A list of all the files in tex/ (excluding file extensions). std::vector all_tex = { diff --git a/src/inc/mesh.hpp b/src/inc/mesh.hpp index b347cb8..5ae1119 100644 --- a/src/inc/mesh.hpp +++ b/src/inc/mesh.hpp @@ -1,6 +1,6 @@ -// Convert a subset of a world into a vertex array (also called a mesh). The -// generated vertex array is stored in target, and it's size (in floats) is -// stored in target_size_in_floats. +// Convert a subset of a world into a vertex array. The generated vertex +// array is stored in target, and it's size in floats is stored in +// target_size_in_floats. void world_subset_to_mesh ( @@ -43,8 +43,6 @@ void world_subset_to_mesh block_id voxel_id = input->get_id(cx, cy, cz); // Ignore voxels that have a block_id equivalent to id_air. - // Voxels that have a block_id equivalent to id_air are fully - // transparent, and do not need to be rendered. if (voxel_id == id_air) { @@ -56,8 +54,8 @@ void world_subset_to_mesh face_info* cube_face_info = block_face_info[voxel_id]; - // Get the layer index corresponding to each face of the - // current voxel. + // Get the layer (w coordinate) corresponding to each face of + // the current voxel. float layer_top = cube_face_info->l_top; @@ -84,7 +82,7 @@ void world_subset_to_mesh float voxel_light = std::max(voxel_light_natural, voxel_light_artificial); // Calculate the lighting value of each face by multiplying - // the lighting value of the current voxel by a constant + // the final lighting value of the current voxel by a constant // coefficient. float lighting_top = 1.0f * voxel_light; diff --git a/src/inc/program.hpp b/src/inc/program.hpp index b89dbb9..0c0f6c7 100644 --- a/src/inc/program.hpp +++ b/src/inc/program.hpp @@ -2,7 +2,7 @@ #include // Load a shader program from two files. One is a vertex shader, and one is a -// fragment shader. Geometry shader support is not implemented. +// fragment shader. GLuint load_program(std::string vertex_path, std::string fragment_path) { diff --git a/src/inc/texture.hpp b/src/inc/texture.hpp index 013c355..c25bbe2 100644 --- a/src/inc/texture.hpp +++ b/src/inc/texture.hpp @@ -17,7 +17,7 @@ GLuint load_block_texture_array() int channels = 4; - // The texture array must have one layer for each texture in all_tex. + // The texture array must have one layer for each texture path in all_tex. GLsizei layers = all_tex.size(); @@ -68,7 +68,7 @@ GLuint load_block_texture_array() exit(12); } - // Copy the sub-texture texels to the texel array. + // Copy the sub-texture's texels to the texel array. memcpy(texels + (i * x_res * y_res * channels), sub_data, x_res * y_res * channels); @@ -76,7 +76,8 @@ GLuint load_block_texture_array() stbi_image_free(sub_data); - // Add to map. + // Add a map entry that has a key of the sub-texture's name and a + // value of the sub-texture's layer index to the map. block_name_to_layer.emplace(all_tex[i], float(i)); } @@ -87,6 +88,8 @@ GLuint load_block_texture_array() glGenTextures(1, &texture_array); + // Bind the texture array to the current state. + glBindTexture(GL_TEXTURE_2D_ARRAY, texture_array); // Allocate storage for the 2D texture array. @@ -105,7 +108,7 @@ GLuint load_block_texture_array() glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - // Unbind the texture array. + // Unbind the texture array from the current state. glBindTexture(GL_TEXTURE_2D_ARRAY, 0); @@ -113,7 +116,7 @@ GLuint load_block_texture_array() free(texels); - // Return the output std::map. + // Return the reference to the texture array. return texture_array; } \ No newline at end of file diff --git a/src/inc/voxel.hpp b/src/inc/voxel.hpp index f21fd49..22ae74e 100644 --- a/src/inc/voxel.hpp +++ b/src/inc/voxel.hpp @@ -1,8 +1,6 @@ // A voxel can be represented with 16 bits of data. The last 8 bits hold the -// block_id information (that allows 256 distinct block_id values). The first -// 4 bits hold the natural light information, and the second 4 bits hold the -// artificial light information. That allows for 16 unique lighting values for -// each lighting component, and 256 unique lighting permutations in total. +// block_id information. The first 4 bits hold the natural light information, +// and the second 4 bits hold the artificial light information. typedef unsigned short voxel; diff --git a/src/inc/world.hpp b/src/inc/world.hpp index 6adbb82..1a583f8 100644 --- a/src/inc/world.hpp +++ b/src/inc/world.hpp @@ -1,6 +1,6 @@ #include -// A world struct hold information about a worlds dimensions and block data. +// A world struct holds information about a world's dimensions and block data. // It makes it easy and efficient to modify and read the properties of every // voxel it contains. @@ -198,8 +198,8 @@ world* allocate_world(unsigned int x_res, unsigned int y_res, unsigned int z_res return new_world; } -// Deallocate a world*'s voxels, and then delete the pointer to the underlying -// world object. +// Deallocate a world*'s voxels, and then delete the pointer to the world +// object. void deallocate_world(world* to_be_annihilated) { diff --git a/src/main.hpp b/src/main.hpp index e906dd1..cccc6e5 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -2,9 +2,7 @@ #include #include -// GLM is used as the mathematics library. It provides functions that are -// based on GLSL, and makes it really easy to generate projection and view -// matrices. +// GLM is used as the mathematics library. #include @@ -12,19 +10,15 @@ #include -// GLAD is used as the loader for OpenGL functions. On operating systems such -// as OS X, a loader is not necessarily needed. However, on most other -// systems, a loader is required in order to use any OpenGL functions. +// GLAD is used as the loader for OpenGL functions. #include -// SDL2 is used as the multimedia interface for Minceraft. It provides -// cross-platform functions that allow easy access to the operating system. +// SDL2 is used as the multimedia interface. #include -// stb_image is used as the image loading library. It makes it as simple as -// one function call to load a .png image. +// stb_image is used as the image loading library. #define STB_IMAGE_IMPLEMENTATION