mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 14:01:38 +02:00
Adding the Batch class to GPU
This commit is contained in:
parent
a46610a7c1
commit
f09133f413
2 changed files with 159 additions and 0 deletions
65
interface/src/gpu/Batch.cpp
Normal file
65
interface/src/gpu/Batch.cpp
Normal file
|
@ -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 <QDebug>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
94
interface/src/gpu/Batch.h
Normal file
94
interface/src/gpu/Batch.h
Normal file
|
@ -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 <assert.h>
|
||||
#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<Command> Commands;
|
||||
|
||||
class Param {
|
||||
public:
|
||||
union {
|
||||
uint32 _uint;
|
||||
char _chars[4];
|
||||
};
|
||||
Param( uint32 val ): _uint(val) {}
|
||||
};
|
||||
typedef std::vector<Param> Params;
|
||||
|
||||
class ResourceCache {
|
||||
public:
|
||||
Resource* _resource;
|
||||
};
|
||||
typedef std::vector<ResourceCache> Resources;
|
||||
|
||||
Commands _commands;
|
||||
Params _params;
|
||||
Resources _resources;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue