Skip to content

Commit

Permalink
Dynamic meshes (#18)
Browse files Browse the repository at this point in the history
* Implementing character string (Text) rendering (WIP)

* added text_shader.glsl

* Added space (' ') whitespace support.

* Added new font

* Some refactoring

* Updated HPML submodule

* Updated HPML and MeshLib

* Extended shader_compiler and shader_binary file format

* Added vulkan_descriptor_set

* Refactored for vulkan_descriptor_set

* shader_compiler integration testing and bug fixes

* Added Serialization headers and Source

* Fixed release mode build linking errors

* Updated HPML

* Added ASSERT_WRN and assert_wrn in assert.h

* Added INTERNAL define, which does nothing

* Implemented material_set_texture2d()

* Refactoring

Renamed: stage_shader to vulkan_stage_shader
Renamed: shader to vulkan_shader
Created new: shader

* removed some white space in vulkan_descriptor_set.c

* Updated BufferLib submodule

* Added uniform buffer support, one can set values in uniform block easily now!
  • Loading branch information
ravi688 authored Jan 4, 2022
1 parent 02ee1d0 commit b2ccb73
Show file tree
Hide file tree
Showing 51 changed files with 4,078 additions and 579 deletions.
2 changes: 1 addition & 1 deletion dependencies/MeshLib
172 changes: 172 additions & 0 deletions include/renderer/Serialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#ifndef _SERIALIZATION_H_
#define _SERIALIZATION_H_
#include <renderer/defs.h>
#include <buffer.h>

#define serialized_struct_set_property_int8(struct_name, property_name, value, object_ptr)\
{\
int8_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_int16(struct_name, property_name, value, object_ptr)\
{\
int16_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_int32(struct_name, property_name, value, object_ptr)\
{\
int32_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_int64(struct_name, property_name, value, object_ptr)\
{\
int64_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_uint8(struct_name, property_name, value, object_ptr)\
{\
uint8_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_uint16(struct_name, property_name, value, object_ptr)\
{\
uint16_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_uint32(struct_name, property_name, value, object_ptr)\
{\
uint32_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_uint64(struct_name, property_name, value, object_ptr)\
{\
uint64_t _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_float(struct_name, property_name, value, object_ptr)\
{\
float _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_double(struct_name, property_name, value, object_ptr)\
{\
double _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value, object_ptr);\
}
#define serialized_struct_set_property_long_double(struct_name, property_name, value, object_ptr)\
{\
long double _value = value;\
serialized_struct_set_property_value(struct_name, property_name,&_value);\
}

#define serialized_struct_get_property_int8(struct_name, property_name, object_ptr) (*(int8_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_int16(struct_name, property_name, object_ptr) (*(int16_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_int32(struct_name, property_name, object_ptr) (*(int32_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_int64(struct_name, property_name, object_ptr) (*(int64_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_uint8(struct_name, property_name, object_ptr) (*(uint8_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_uint16(struct_name, property_name, object_ptr) (*(uint16_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_uint32(struct_name, property_name, object_ptr) (*(uint32_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_uint64(struct_name, property_name, object_ptr) (*(uint64_t*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_float(struct_name, property_name, object_ptr) (*(float*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_double(struct_name, property_name, object_ptr) (*(double*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))
#define serialized_struct_get_property_long_double(struct_name, property_name, object_ptr) (*(long double*)serialized_struct_get_property_value(struct_name, property_name, object_ptr))

#define serialized_property_set_int8(property, value)\
{\
int8_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_int16(property, value)\
{\
int16_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_int32(property, value)\
{\
int32_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_int64(property, _value)\
{\
int64_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_uint8(property, value)\
{\
uint8_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_uint16(property, value)\
{\
uint16_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_uint32(property, value)\
{\
uint32_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_uint64(property, value)\
{\
uint64_t _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_float(property, value)\
{\
float _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_double(property, value)\
{\
double _value = value;\
serialized_property_set_value(property, &_value);\
}
#define serialized_property_set_long_double(property, value)\
{\
long double _value = value;\
serialized_property_set_value(property, &_value);\
}

#define serialized_property_get_int8(property) (*(int8_t*)serialized_property_get_value(property))
#define serialized_property_get_int16(property) (*(int16_t*)serialized_property_get_value(property))
#define serialized_property_get_int32(property) (*(int32_t*)serialized_property_get_value(property))
#define serialized_property_get_int64(property) (*(int64_t*)serialized_property_get_value(property))
#define serialized_property_get_uint8(property) (*(uint8_t*)serialized_property_get_value(property))
#define serialized_property_get_uint16(property) (*(uint16_t*)serialized_property_get_value(property))
#define serialized_property_get_uint32(property) (*(uint32_t*)serialized_property_get_value(property))
#define serialized_property_get_uint64(property) (*(uint64_t*)serialized_property_get_value(property))
#define serialized_property_get_float(property) (*(float*)serialized_property_get_value(property))
#define serialized_property_get_double(property) (*(double*)serialized_property_get_vaule(property))
#define serialized_property_get_long_double(property) (*(long double*)serialized_property_get_value(property))

//loads the source file from secondary storage to the main memory for further parsing and compiling
void load_serialization_source_file(const char* name);
//sets the internal source buffer
//NOTE: if this buffer is allocated in the heap then it will not be automatically freed, you must have to free it explicitly
void set_serialization_source_buffer(const char* buffer);
//destoyes the allocated buffers for the serialized objects and properties
void destroy_serialization_data();
//prints the details of a serialized property
void serialized_property_print(SerializedProperty* property);
//prints the details of a serialized struct along with its all property details
void serialized_struct_print(const char* name);
//serializes a struct and stores the retrieved (serialized information) information into a buffer of SerializedStructs
void struct_serialize(const char* struct_name);
//instantiates a new object of type typeof('serialized_struct_name')
//NOTE: that struct must be serialized first
void* instantiate_object(const char* struct_name);
//returns a pointer to the memory bock which corresponds to the property
void* serialized_property_get_value(SerializedProperty* property);
//sets a value of a memory block which corresponds to the property
void serialized_property_set_value(SerializedProperty* property, void* value);
//sets a value to a property in the serialized struct named as 'struct_name'
void serialized_struct_set_property_value(const char* struct_name, const char* property_name, void* value, void* object_ptr);
//returns a pointer to the memory block of property of the struct named as 'struct_name'
void* serialized_struct_get_property_value(const char* struct_name, const char* property_name, void* object_ptr);
//returns the property with name 'property_name' and you have to pass the base address of an object (struct)
SerializedProperty serialized_struct_get_property(const char* serialized_struct_name, const char* property_name, void* object_ptr);

SerializedStruct* serialized_struct_get(const char* name);


#endif
20 changes: 19 additions & 1 deletion include/renderer/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@
#endif

#if defined(GLOBAL_DEBUG)
# define ASSERT_WRN(boolean, ...)\
do\
{\
if(!(boolean))\
{\
printf("[Warning] Assertion Failed: ");\
printf(__VA_ARGS__);\
puts(calltrace_string());\
}\
} while(0)
# define ASSERT(boolean, ...)\
do\
{\
if(!(boolean))\
{\
printf("Assertion Failed: ");\
printf("[Fetal Error] Assertion Failed: ");\
printf(__VA_ARGS__);\
puts(calltrace_string());\
exit(0);\
Expand All @@ -28,17 +38,25 @@

#if defined(GLOBAL_DEBUG)
# define assert(condition) ASSERT((condition) != false, "\"%s\" is found to be false\n", #condition)
# define assert_wrn(condition) ASSERT_WRN((condition) != false, "\"%s\" is found to be false\n", #condition)
# define ASSERT_NOT_NULL(ptr) assert(ptr != NULL)
#else
# define assert(condition)
# define assert_wrn(condition)
# define ASSERT_NOT_NULL(ptr)
#endif

#if defined(GLOBAL_DEBUG)
# define LOG_MSG(...) log_msg(__VA_ARGS__)
# define LOG_ERR(...) log_err(__VA_ARGS__)
# define LOG_WRN(...) log_wrn(__VA_ARGS__)
# define LOG_FETAL_ERR(...) log_fetal_err(__VA_ARGS__)
#else
# define LOG_WRN(...)\
{\
printf("[Warning]: ");\
printf(__VA_ARGS__);\
}
# define LOG_MSG(...)\
{\
printf("[Log]: ");\
Expand Down
5 changes: 5 additions & 0 deletions include/renderer/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ typedef int8_t s8;

typedef float f32;
typedef double f64;
typedef u32 uint;



#define INTERNAL
96 changes: 96 additions & 0 deletions include/renderer/defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#ifndef _DEFS_H_
#define _DEFS_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <buffer.h>

#define TOKEN_BUFFER_SIZE 80
#define SINGLE_LINE_COMMENT "\\"
#define MULTIPLE_LINE_COMMENT "/**/"
#define VERSION(__version__)

#define _sizeof(serialized_property) __sizeof(serialized_property)

#ifdef DEBUG
#define GOTO(label) { printf("Returned from %d\n", __LINE__); goto label; }
#else
#define GOTO(label) { goto label; }
#endif

#define INCREMENT_CHAR_PTR(ch, amount)\
do {\
if((ch == NULL) || (*ch == 0)) { exit(0); puts("FILE ENDED"); }\
ch += amount;\
if(*ch == 0) { exit(0); puts("FILE ENDED");} } while (false)

#ifdef DEBUG
#define throw_error(error_str, line_no, discription)\
do{\
printf("[ERROR]: Parsing error at line no %d \n%s: %s\n", line_no, error_str, discription);\
exit(0);\
}while(false)
#else
#define throw_error(error_str, line_no, description)
#endif

typedef enum
{
STSP_STATIC = 0,
STSP_REGISTER = 1,
STSP_EXTERN = 2,
STSP_NONE = 3
} _storage_specifiers;

typedef enum
{
TYPE_SIGNED_INT8 = 0, //char, signed char
TYPE_SIGNED_INT16 = 1, //short, signed short, short int, signed short int
TYPE_SIGNED_INT32 = 2, //int, signed int, long, long int
TYPE_SIGNED_INT64 = 3, //long long int

TYPE_UNSIGNED_INT8 = 4, //unsigned char
TYPE_UNSIGNED_INT16 = 5, //unsigned short, unsigned short int
TYPE_UNSIGNED_INT32 = 6, //unsigned int, unsigned long, unsigned long int
TYPE_UNSIGNED_INT64 = 7, //unsigned long long, unsigned long long int

TYPE_FLOAT = 8, //float
TYPE_DOUBLE = 9, //double
TYPE_LONG_DOUBLE = 10, //long double
TYPE_STRING = 11,
TYPE_NONE = 12,
TYPE_INCOMPLETE = 13,
TYPE_VOID = 14
} _type_specifiers;

typedef struct
{
bool is_pointer; //true if this property is a pointer
bool is_const; //true if this property is a constant property
_storage_specifiers storage; //extern, static, register
_type_specifiers type; //int, short, long ...etc
intptr_t address; //address of the property
char name[TOKEN_BUFFER_SIZE]; //name of the property
} SerializedProperty;

typedef struct
{
char name[TOKEN_BUFFER_SIZE]; //name of this struct
bool is_valid; //true, if this SerializedStruct is a valid serialized struct
uint32_t size; //size of the serialized struct in bytes
BUFFER* properties; //list of properties
} SerializedStruct;

char* defs_load_text_from_file(const char* file_name);
char* defs_load_text_from_file_exclude_comments(const char* file_name);

int __sizeof(SerializedProperty* property);
bool isstorage(const char* string, _storage_specifiers* storage);
bool istype(const char* string, _type_specifiers* type);


#endif
8 changes: 7 additions & 1 deletion include/renderer/internal/vulkan/vulkan_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ typedef struct renderer_t renderer_t;
typedef struct vulkan_buffer_create_info_t
{
void* data;
uint32_t stride;
uint32_t count;
uint32_t stride;
uint32_t size;
VkBufferUsageFlags usage_flags;
VkSharingMode sharing_mode;
VkMemoryPropertyFlags memory_property_flags;
Expand All @@ -19,6 +20,7 @@ typedef struct vulkan_buffer_t
{
VkBuffer handle;
VkDeviceMemory memory;
uint32_t size;
uint32_t stride;
uint32_t count;
} vulkan_buffer_t;
Expand All @@ -29,3 +31,7 @@ vulkan_buffer_t* vulkan_buffer_create(renderer_t* renderer, vulkan_buffer_create
void vulkan_buffer_create_no_alloc(renderer_t* renderer, vulkan_buffer_create_info_t* create_info, vulkan_buffer_t* buffer);
void vulkan_buffer_destroy(vulkan_buffer_t* buffer, renderer_t* renderer);
void vulkan_buffer_release_resources(vulkan_buffer_t* buffer);

void vulkan_buffer_copy_data(vulkan_buffer_t* buffer, renderer_t* renderer, void* data, u32 start_offset, u32 size);
void* vulkan_buffer_map(vulkan_buffer_t* buffer, renderer_t* renderer);
void vulkan_buffer_unmap(vulkan_buffer_t* buffer, renderer_t* renderer);
35 changes: 35 additions & 0 deletions include/renderer/internal/vulkan/vulkan_descriptor_set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@


#pragma once

#include <renderer/defines.h>
#include <vulkan/vulkan_wrapper.h>

typedef struct renderer_t renderer_t;
typedef struct vulkan_texture_t vulkan_texture_t;
typedef struct vulkan_buffer_t vulkan_buffer_t;
typedef struct vulkan_pipeline_layout_t vulkan_pipeline_layout_t;

typedef struct vulkan_descriptor_set_create_info_t
{
VkDescriptorPool pool;
VkDescriptorSetLayout layout;
} vulkan_descriptor_set_create_info_t;

typedef struct vulkan_descriptor_set_t
{
VkDescriptorSet handle;
VkDescriptorPool pool; //the pool from it has been allocated
} vulkan_descriptor_set_t;



vulkan_descriptor_set_t* vulkan_descriptor_set_new();
vulkan_descriptor_set_t* vulkan_descriptor_set_create(renderer_t* renderer, vulkan_descriptor_set_create_info_t* create_info);
void vulkan_descriptor_set_create_no_alloc(renderer_t* renderer, vulkan_descriptor_set_create_info_t* create_info, vulkan_descriptor_set_t* set);
void vulkan_descriptor_set_destroy(vulkan_descriptor_set_t* set, renderer_t* renderer);
void vulkan_descriptor_set_release_resources(vulkan_descriptor_set_t* set);

void vulkan_descriptor_set_bind(vulkan_descriptor_set_t* set, renderer_t* renderer, vulkan_pipeline_layout_t* pipeline_layout);
void vulkan_descriptor_set_write_texture(vulkan_descriptor_set_t* set, renderer_t* renderer, u32 binding_index, vulkan_texture_t* texture);
void vulkan_descriptor_set_write_uniform_buffer(vulkan_descriptor_set_t* set, renderer_t* renderer, u32 binding_index, vulkan_buffer_t* buffer);
Loading

0 comments on commit b2ccb73

Please sign in to comment.