From f09133f413624c0ee192a3943ef460d764acb711 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 16 Oct 2014 17:23:31 -0700 Subject: [PATCH] Adding the Batch class to GPU --- interface/src/gpu/Batch.cpp | 65 +++++++++++++++++++++++++ interface/src/gpu/Batch.h | 94 +++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 interface/src/gpu/Batch.cpp create mode 100644 interface/src/gpu/Batch.h diff --git a/interface/src/gpu/Batch.cpp b/interface/src/gpu/Batch.cpp new file mode 100644 index 0000000000..a364a678fc --- /dev/null +++ b/interface/src/gpu/Batch.cpp @@ -0,0 +1,65 @@ +// +// Batch.cpp +// interface/src/gpu +// +// Created by Sam Gateau on 10/14/2014. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "Batch.h" + +#include + +using namespace gpu; + +Batch::Batch() : + _commands(), + _params(), + _resources(){ +} + +Batch::~Batch() { +} + +void Batch::clear() { + _commands.clear(); + _params.clear(); + _resources.clear(); +} + +void Batch::draw( Primitive primitiveType, int nbVertices, int startVertex) { + _commands.push(COMMAND_DRAW); + _params.push(startVertex); + _params.push(nbVertices); + _params.push(primitiveType); +} + +void Batch::drawIndexed( Primitive primitiveType, int nbIndices, int startIndex) { + _commands.push(COMMAND_DRAW_INDEXED); + _params.push(startIndex); + _params.push(nbIndices); + _params.push(primitiveType); +} + +void Batch::drawInstanced( uint32 nbInstances, Primitive primitiveType, int nbVertices, int startVertex, int startInstance) { + _commands.push(COMMAND_DRAW_INSTANCED); + _params.push(startInstance); + _params.push(startVertex); + _params.push(nbVertices); + _params.push(primitiveType); + _params.push(nbInstances); +} + +void Batch::drawIndexedInstanced( uint32 nbInstances, Primitive primitiveType, int nbIndices, int startIndex, int startInstance) { + _commands.push(COMMAND_DRAW_INDEXED_INSTANCED); + _params.push(startInstance); + _params.push(startIndex); + _params.push(nbIndices); + _params.push(primitiveType); + _params.push(nbInstances); +} + + + diff --git a/interface/src/gpu/Batch.h b/interface/src/gpu/Batch.h new file mode 100644 index 0000000000..43888e517b --- /dev/null +++ b/interface/src/gpu/Batch.h @@ -0,0 +1,94 @@ +// +// Batch.h +// interface/src/gpu +// +// Created by Sam Gateau on 10/14/2014. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_gpu_Batch_h +#define hifi_gpu_Batch_h + +#include +#include "InterfaceConfig.h" + +namespace gpu { + +class Buffer; +typedef int Stamp; + +// TODO: move the backend namespace into dedicated files, for now we keep it close to the gpu objects definition for convenience +namespace backend { + +}; + +enum Primitive { + PRIMITIVE_POINTS = 0, + PRIMITIVE_LINES, + PRIMITIVE_LINE_STRIP, + PRIMITIVE_TRIANGLES, + PRIMITIVE_TRIANGLE_STRIP, + PRIMITIVE_QUADS, +}; + +class Batch { +public: + + Batch(); + Batch(const Batch& batch); + ~Batch(); + + void clear(); + + void draw( Primitive primitiveType, int nbVertices, int startVertex = 0); + void drawIndexed( Primitive primitiveType, int nbIndices, int startIndex = 0 ); + void drawInstanced( uint32 nbInstances, Primitive primitiveType, int nbVertices, int startVertex = 0, int startInstance = 0); + void drawIndexedInstanced( uint32 nbInstances, Primitive primitiveType, int nbIndices, int startIndex = 0, int startInstance = 0); + + void glBindBuffer( GLenum +protected: + + enum Command { + COMMAND_DRAW = 0, + COMMAND_DRAW_INDEXED, + COMMAND_DRAW_INSTANCED, + COMMAND_DRAW_INDEXED_INSTANCED, + + COMMAND_SET_PIPE_STATE, + COMMAND_SET_VIEWPORT, + COMMAND_SET_FRAMEBUFFER, + COMMAND_SET_RESOURCE, + COMMAND_SET_VERTEX_STREAM, + COMMAND_SET_INDEX_STREAM, + + COMMAND_GL_SET_UNIFORM, + + }; + typedef std::vector Commands; + + class Param { + public: + union { + uint32 _uint; + char _chars[4]; + }; + Param( uint32 val ): _uint(val) {} + }; + typedef std::vector Params; + + class ResourceCache { + public: + Resource* _resource; + }; + typedef std::vector Resources; + + Commands _commands; + Params _params; + Resources _resources; +}; + +}; + +#endif