-
Notifications
You must be signed in to change notification settings - Fork 5
/
DrawBatch.h
90 lines (74 loc) · 3.01 KB
/
DrawBatch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#ifdef WIN32
#include "GL/glew.h"
#endif
#include "Viewport.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
#include "Mesh.h"
#include "FragmentShader.h"
typedef enum {
BLENDTYPE_INVAL = 0,
BLENDTYPE_SRC_ALPHA = 1,
BLENDTYPE_ADD = 2,
} BLENDTYPE;
typedef enum {
VFTYPE_INVAL = 0,
VFTYPE_COORD_COLOR = 1,
VFTYPE_COORD_COLOR_UV = 2,
} VFTYPE;
class DrawBatch {
public:
VFTYPE vf_type;
GLuint tex; // 0 for non-text
GLuint prim_type;
FragmentShader *f_shader; // 0 for default
BLENDTYPE blend_type;
int line_width; // used only when GL_LINES
VertexBuffer *vb; // contains all verts in this batch
IndexBuffer *ib;
int vert_used; // where to put next vertex
int index_used;
Mesh *mesh; // overrides ib,vb,prim_type,vf_type
Vec2 translate, scale; // used only when drawing mesh
float radrot;
Viewport *viewport;
bool perform_transform; // true for drawing Mesh pointer or copied Mesh
static const int MAXQUAD = 256;
static const int MAXVERTEX = MAXQUAD*4;
static const int MAXINDEX = MAXQUAD*6;
static bool debug_batch_cond;
DrawBatch( Viewport *vp, VFTYPE vft, GLuint tx, GLuint primtype, FragmentShader *fs, BLENDTYPE bt, int linew = 1 );
DrawBatch( Viewport *vp, FragmentShader *fs, BLENDTYPE bt, GLuint tx, GLuint primtype, Vec2 translate, Vec2 scale, float r, Mesh *m, bool copy_mesh );
~DrawBatch() {
if(vb)delete vb;
if(ib)delete ib;
};
void setupVBIB(Mesh*m, VFTYPE vft = VFTYPE_INVAL);
bool shouldContinue( Viewport *vp, VFTYPE vft, GLuint texid, GLuint primtype, FragmentShader *fs, BLENDTYPE bt, int linew = 1);
void draw();
int hasVertexRoom( int n ) {
return MAXVERTEX - vert_used;
}
void pushVertices( int vnum, Color *colors, Vec3 *coords, int inum, int *inds);
void pushVertices( int vnum, Color *colors, Vec3 *coords, Vec2 *uvs, int inum, int *inds);
static VertexFormat *getVertexFormat(VFTYPE t);
void dump();
};
class DrawBatchList {
public:
static const int MAXBATCH = 2048;
int used;
DrawBatch *batches[MAXBATCH];
DrawBatchList();
void clear();
void dump();
DrawBatch *getCurrentBatch();
DrawBatch *startNextBatch( Viewport *vp, VFTYPE vft, GLuint tex, GLuint primtype, FragmentShader *fs, BLENDTYPE bt, int linew = 1 );
DrawBatch *startNextMeshBatch( Viewport *vp, FragmentShader *fs, BLENDTYPE bt, GLuint tex, Vec2 tr, Vec2 scl, float radrot, Mesh *mesh, bool copy_mesh );
int drawAll();
bool appendSprite1( Viewport *vp, FragmentShader *fs, BLENDTYPE bt, GLuint tex, Color c, Vec2 tr, Vec2 scl, float radrot, Vec2 lb, Vec2 lt, Vec2 rt, Vec2 rb );
bool appendMesh( Viewport *vp, FragmentShader *fs, BLENDTYPE bt, GLuint tex, Vec2 tr, Vec2 scl, float radrot, Mesh *mesh, bool copy_mesh );
bool appendLine( Viewport *vp, Vec2 a, Vec2 b, Color c, Vec2 tr, Vec2 scl, float radrot, int linew );
bool appendRect( Viewport *vp, Vec2 a, Vec2 b, Color c, Vec2 tr, Vec2 scl, float radrot );
};