My Project: openb3dlib.mod/openb3d/src/sprite_batch.h Source File

My Project

sprite_batch.h
Go to the documentation of this file.
1 /*
2 * sprite_batch.h
3 * iminib3d
4 *
5 * Created by Simon Harrison.
6 * Copyright Si Design. All rights reserved.
7 *
8 */
9
10 #ifndef SPRITE_BATCH_H
11 #define SPRITE_BATCH_H
12
13 #include "mesh.h"
14 #include "global.h"
15 #include "surface.h"
16 #include "texture.h"
17
18 #include <iostream>
19 using namespace std;
20
21 class SpriteBatch{
22
23 public:
24
25 static list<SpriteBatch*> sprite_batch_list;
26 Surface* surf;
27 Mesh* mesh;
28 Texture* texture;
29 int blend;
30 int order;
31
32 SpriteBatch(){
33
34 surf=NULL;
35 mesh=NULL;
36 texture=NULL;
37 blend=0;
38 order=0;
39
40 };
41
42 static Surface* GetSpriteBatchSurface(Texture* tex,int blend,int order){
43
44 SpriteBatch* sprite_batch=NULL;
45
46 // check if sprite batch already exists for specified texture, if so return it
47 list<SpriteBatch*>::iterator it;
48 for(it=sprite_batch_list.begin();it!=sprite_batch_list.end();it++){
49 sprite_batch=*it;
50 if(sprite_batch->texture==tex && sprite_batch->blend==blend && sprite_batch->order==order){
51 return sprite_batch->surf;
52 }
53 }
54
55 // if no sprite batch surface exists, create new sprite batch with new surface
56 sprite_batch=new SpriteBatch;
57 sprite_batch->surf=new Surface;
58 sprite_batch->surf->vbo_enabled=false;
59 sprite_batch->surf->ShaderMat=Global::ambient_shader;
60 sprite_batch->texture=tex;
61 sprite_batch->blend=blend;
62 sprite_batch->order=order;
63 sprite_batch_list.push_back(sprite_batch);
64 return sprite_batch->surf;
65
66 }
67
68 Mesh* GetSpriteBatchMesh(){
69
70 mesh=new Mesh();
71
72 mesh->surf_list.push_back(surf);
73
74 mesh->no_surfs=mesh->no_surfs+1;
75
76 // new mesh surface - update reset flags
77 mesh->reset_bounds=true;
78 mesh->reset_col_tree=true;
79
80 mesh->brush.tex[0]=texture;
81 mesh->brush.cache_frame[0]=texture->texture;
82
83 mesh->brush.no_texs=1;
84 mesh->brush.blend=blend;
85 mesh->brush.fx=35;
86
87 mesh->order=order;
88
89 return mesh;
90
91 }
92
93 static void Clear(){
94
95 list<SpriteBatch*>::iterator it;
96 for(it=sprite_batch_list.begin();it!=sprite_batch_list.end();it++){
97 SpriteBatch* sprite_batch=*it;
98 delete sprite_batch->mesh;
99 delete sprite_batch->surf;
100 delete sprite_batch;
101 }
102 sprite_batch_list.clear();
103
104 }
105
106 };
107
108 #endif
Brush::fx
int fx
Definition: brush.h:29
Mesh
Definition: mesh.h:34
Global::ambient_shader
static Shader * ambient_shader
Definition: global.h:24
Texture::texture
unsigned int texture
Definition: texture.h:27
Surface
Definition: surface.h:19
Brush::no_texs
int no_texs
Definition: brush.h:25
mesh.h
std
SpriteBatch::surf
Surface * surf
Definition: sprite_batch.h:26
Brush::blend
int blend
Definition: brush.h:29
global.h
Brush::cache_frame
unsigned int cache_frame[8]
Definition: brush.h:30
texture.h
SpriteBatch::SpriteBatch
SpriteBatch()
Definition: sprite_batch.h:32
SpriteBatch::sprite_batch_list
static list< SpriteBatch * > sprite_batch_list
Definition: sprite_batch.h:25
SpriteBatch::mesh
Mesh * mesh
Definition: sprite_batch.h:27
SpriteBatch::texture
Texture * texture
Definition: sprite_batch.h:28
SpriteBatch::GetSpriteBatchSurface
static Surface * GetSpriteBatchSurface(Texture *tex, int blend, int order)
Definition: sprite_batch.h:42
Surface::vbo_enabled
int vbo_enabled
Definition: surface.h:65
Mesh::reset_bounds
int reset_bounds
Definition: mesh.h:52
Mesh::reset_col_tree
int reset_col_tree
Definition: mesh.h:49
Entity::brush
Brush brush
Definition: entity.h:49
Texture
Definition: texture.h:23
load3ds::mesh
Mesh * mesh
Definition: 3ds.cpp:46
surface.h
SpriteBatch::GetSpriteBatchMesh
Mesh * GetSpriteBatchMesh()
Definition: sprite_batch.h:68
Surface::ShaderMat
Shader * ShaderMat
Definition: surface.h:51
Brush::tex
Texture * tex[8]
Definition: brush.h:31
Mesh::no_surfs
int no_surfs
Definition: mesh.h:38
Mesh::surf_list
list< Surface * > surf_list
Definition: mesh.h:40
Entity::order
int order
Definition: entity.h:52
SpriteBatch::Clear
static void Clear()
Definition: sprite_batch.h:93
SpriteBatch
Definition: sprite_batch.h:21
SpriteBatch::blend
int blend
Definition: sprite_batch.h:29
load3ds::texture
Texture * texture
Definition: 3ds.cpp:50
SpriteBatch::order
int order
Definition: sprite_batch.h:30
NULL
#define NULL
Definition: tree.cpp:4