diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b5089e3a44853ba4c46d44d4ac797575cba38e7..e62316f2138973c6dd31e4aaaf36f5e6678fae21 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -338,6 +338,7 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_trick.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_vertarray.c ) set (SRB2_HWRENDER_HEADERS @@ -350,6 +351,7 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_vertarray.h ) set(SRB2_R_OPENGL_SOURCES diff --git a/src/hardware/hw_vertarray.c b/src/hardware/hw_vertarray.c new file mode 100644 index 0000000000000000000000000000000000000000..07b9e4fa824075edb90311fde0c720c423e63b67 --- /dev/null +++ b/src/hardware/hw_vertarray.c @@ -0,0 +1,54 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2015 by Sonic Team Jr. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief Resizeable vertex array implementation + +#include "hw_vertarray.h" + +#include "../z_zone.h" + +#define RESIZE_FACTOR 2 + + +void HWR_InitVertexArray(FVertexArray * varray, unsigned int initialSize) +{ + varray->size = initialSize; + varray->used = 0; + varray->buffer = Z_Malloc(varray->size * sizeof(FOutVector), PU_STATIC, varray); +} + +void HWR_FreeVertexArray(FVertexArray * varray) +{ + Z_Free(varray->buffer); +} + +void HWR_InsertVertexArray(FVertexArray * varray, int numElements, FOutVector * elements) +{ + int i = 0; + if (varray->used + numElements >= varray->size) + { + varray->size *= RESIZE_FACTOR; + varray->buffer = Z_Realloc(varray->buffer, varray->size * sizeof(FOutVector), PU_STATIC, varray); + } + + for (i = 0; i < numElements; i++) + { + varray->buffer[i + varray->used] = elements[i]; + } + + varray->used += numElements; +} diff --git a/src/hardware/hw_vertarray.h b/src/hardware/hw_vertarray.h new file mode 100644 index 0000000000000000000000000000000000000000..9971511ab5cb4b86ba0dab78c15ba5541b5ffc9a --- /dev/null +++ b/src/hardware/hw_vertarray.h @@ -0,0 +1,37 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2015 by Sonic Team Jr. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief Resizeable vertex array + +#ifndef __HWR_VERTARRAY_H__ +#define __HWR_VERTARRAY_H__ + +#include "hw_defs.h" + +typedef struct +{ + FOutVector * buffer; + unsigned int used; + unsigned int size; +} FVertexArray; + +void HWR_InitVertexArray(FVertexArray * varray, unsigned int initialSize); +void HWR_FreeVertexArray(FVertexArray * varray); + +void HWR_InsertVertexArray(FVertexArray * varray, int numElements, FOutVector * elements); + +#endif // __HWR_VERTARRAY_H__