VideoCommon/IndexGenerator: Eliminate static state

Now that we've extracted all of the stateless functions that can be
hidden, it's time to make the index generator a regular class with
active data members.

This can just be a member that sits within the vertex manager base
class. By deglobalizing the state of the index generator we also get rid
of the wonky dual-initializing that was going on within the OpenGL
backend.

Since the renderer is always initialized before the vertex manager, we
now only call Init() once throughout the execution lifecycle.
This commit is contained in:
Lioncash
2019-12-05 10:01:33 -05:00
parent 159947ab68
commit 10f7674651
12 changed files with 69 additions and 64 deletions

View File

@ -7,26 +7,29 @@
#pragma once
#include <array>
#include "Common/CommonTypes.h"
class IndexGenerator
{
public:
// Init
static void Init();
static void Start(u16* Indexptr);
void Init();
void Start(u16* index_ptr);
static void AddIndices(int primitive, u32 numVertices);
void AddIndices(int primitive, u32 num_vertices);
static void AddExternalIndices(const u16* indices, u32 num_indices, u32 num_vertices);
void AddExternalIndices(const u16* indices, u32 num_indices, u32 num_vertices);
// returns numprimitives
static u32 GetNumVerts() { return base_index; }
static u32 GetIndexLen() { return (u32)(index_buffer_current - BASEIptr); }
static u32 GetRemainingIndices();
u32 GetNumVerts() const { return m_base_index; }
u32 GetIndexLen() const { return static_cast<u32>(m_index_buffer_current - m_base_index_ptr); }
u32 GetRemainingIndices() const;
private:
static u16* index_buffer_current;
static u16* BASEIptr;
static u32 base_index;
u16* m_index_buffer_current = nullptr;
u16* m_base_index_ptr = nullptr;
u32 m_base_index = 0;
using PrimitiveFunction = u16* (*)(u16*, u32, u32);
std::array<PrimitiveFunction, 8> m_primitive_table{};
};