/* Copyright (c) 2022 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 */ #include "3dmodelio/ShaderRegistry.h" #include #define stemobject_implementation ShaderRegistry stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_end(); ShaderRegistry * ShaderRegistry_create(void) { stemobject_create_implementation(init) } bool ShaderRegistry_init(ShaderRegistry * self) { call_super(init, self); self->entryCount = 0; self->entries = NULL; return true; } void ShaderRegistry_dispose(ShaderRegistry * self) { free(self->entries); call_super_virtual(dispose, self); } void ShaderRegistry_registerShader(ShaderRegistry * self, struct ShaderRegistry_entry entry) { for (unsigned int entryIndex = 0; entryIndex < self->entryCount; entryIndex++) { if (self->entries[entryIndex].name == entry.name) { #ifdef DEBUG fprintf(stderr, "Warning: Attempt to register shader \"%s\", which is already registered; doing nothing\n", entry.name); #endif return; } } self->entries = realloc(self->entries, (self->entryCount + 1) * sizeof(*self->entries)); self->entries[self->entryCount] = entry; self->entryCount++; } struct ShaderRegistry_entry * ShaderRegistry_lookup(ShaderRegistry * self, Atom name) { for (unsigned int entryIndex = 0; entryIndex < self->entryCount; entryIndex++) { if (self->entries[entryIndex].name == name) { return &self->entries[entryIndex]; } } return NULL; }