/* Copyright (c) 2018 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __MeshData_H__ #define __MeshData_H__ #ifdef __cplusplus extern "C" { #endif typedef struct MeshData MeshData; #define MeshData_superclass StemObject #include "3dmodelio/MeshConfigurationData.h" #include "3dmodelio/ShaderRegistry.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #include "stemobject/StemObject.h" #include #define MESHDATA_FORMAT_VERSION 1 #define MESHDATA_FORMAT_TYPE "mesh" struct MeshData_texture { unsigned int index; char * name; }; #define MeshData_ivars \ StemObject_ivars \ \ char * name; \ PrimitiveType primitiveType; \ char * shaderName; \ char * configurationDataName; \ unsigned int textureCount; \ struct MeshData_texture * textures; \ VertexFormat * vertexFormat; \ bool private_ivar(vertexFormatOwned); \ void * vertices; \ unsigned int vertexCount; \ uint32_t * indexes; \ unsigned int indexCount; #define MeshData_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(MeshData) // Takes ownership of configurationData, vertices, and indexes MeshData * MeshData_create(const char * name, PrimitiveType primitiveType, const char * shaderName, const char * configurationDataName, unsigned int textureCount, struct MeshData_texture * textures, VertexFormat * vertexFormat, bool takeOwnershipOfVertexFormat, void * vertices, unsigned int vertexCount, uint32_t * indexes, unsigned int indexCount); bool MeshData_init(MeshData * self, const char * name, PrimitiveType primitiveType, const char * shaderName, const char * configurationDataName, unsigned int textureCount, struct MeshData_texture * textures, VertexFormat * vertexFormat, bool takeOwnershipOfVertexFormat, void * vertices, unsigned int vertexCount, uint32_t * indexes, unsigned int indexCount); void MeshData_dispose(MeshData * self); // shaderRegistry is used for VertexFormat matching. If NULL, the returned MeshData will use its own VertexFormat as specified // in the mesh being loaded. If non-NULL, the shader specified by the mesh is registered, and the format specified in the mesh // is compatible with the shader's format, the returned MeshData will point to the shader's VertexFormat and not own it. This // will discard attribute names specified in the mesh being loaded, so if they differ from the shader's attribute names, the // distinction will be lost. MeshData * MeshData_deserialize(compat_type(DeserializationContext *) deserializationContext, ShaderRegistry * shaderRegistry); bool MeshData_loadSerializedData(MeshData * self, compat_type(DeserializationContext *) deserializationContext, ShaderRegistry * shaderRegistry); void MeshData_serialize(MeshData * self, compat_type(SerializationContext *) serializationContext); #ifdef __cplusplus } #endif #endif