From 54f25c8f2fc75c18f3a7887dcee27a155b029da3 Mon Sep 17 00:00:00 2001 From: Ronald Kinard <furyhunter600@gmail.com> Date: Wed, 1 Apr 2015 02:46:01 -0500 Subject: [PATCH] Add resizeable vertex array data structure. This will be used for the vertex array buckets when building the render lists for each FSurfaceInfo being used by the hardware renderer. Generally, we will replace DrawPolygon calls with operations to fill these resizeable arrays, one for each FSurfaceInfo. After the initial BSP node draw call, we will go through the buckets calling DrawPolygon on each one. --- src/CMakeLists.txt | 2 ++ src/hardware/hw_vertarray.c | 54 +++++++++++++++++++++++++++++++++++++ src/hardware/hw_vertarray.h | 37 +++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/hardware/hw_vertarray.c create mode 100644 src/hardware/hw_vertarray.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b5089e3a4..e62316f213 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 0000000000..07b9e4fa82 --- /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 0000000000..9971511ab5 --- /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__ -- GitLab