-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzglPrim2D.cpp
executable file
·144 lines (123 loc) · 3.2 KB
/
zglPrim2D.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (C) 2010 ZiiLABS Pte Ltd
* All Rights Reserved.
*
* This software and its associated documentation may contain some
* proprietary, confidential and trade secret information of
* ZiiLABS Pte Ltd and except as provided by written agreement with
* ZiiLABS Pte Ltd
*
* a) no part may be disclosed, distributed, reproduced, transmitted,
* transcribed, stored in a retrieval system, adapted or translated
* in any form or by any means electronic, mechanical, magnetic,
* optical, chemical, manual or otherwise,
*
* and
*
* b) the recipient is not entitled to discover through reverse
* engineering or reverse compiling or other such techniques or
* processes the trade secrets contained therein or in the
* documentation.
*/
#include <stdlib.h> //!< NULL
#include "zglCore.h"
#include "zglPrim2D.h"
zglPrim2D::zglPrim2D()
{
m_type = TYPE_PRIM2D;
}
void zglPrim2D::init(zglDrawType type, zglVertex * vertex, int vert_num,
zglTexture * texture)
{
m_draw_type = type;
m_vertex = vertex;
m_vertex_num = vert_num;
m_texture = texture;
m_indices = NULL;
m_indices_num = 0;
//!< reset the local coordinate system matrix
m_world = 1.0f;
//!< Add to the node list
queue();
}
void zglPrim2D::init(zglDrawType type, zglVertex* vertex, int vert_num,
unsigned short * indices, int index_num, zglTexture * texture)
{
m_draw_type = type;
m_vertex = vertex;
m_vertex_num = vert_num;
m_texture = texture;
m_indices = (unsigned short *) indices;
m_indices_num = index_num;
//!< reset the local coordinate system matrix
m_world = 1.0f;
//!< Add to the node list
queue();
}
void zglPrim2D::render()
{
//preRender();
zglCore::setModelView(m_world);
zglCore::setBlendType((zglBlendType) m_blend_type);
if(m_hwbuffer_type != HWBUFFER_AVAILABLE)
{
zglCore::setVertexPointer2(&m_vertex->x, sizeof(zglVertex));
zglCore::setColorPointer4(&m_vertex->r, sizeof(zglVertex));
if (m_texture)
{
zglCore::setTexture(m_texture->getTexID(), true);
zglCore::setTexCoordPointer2(&m_vertex->u, sizeof(zglVertex));
}
else
{
zglCore::setTexture(0, false);
}
if( m_indices_num > 0)
{
zglCore::drawElements(m_draw_type, m_indices_num, m_indices);
}
else
{
zglCore::drawArrays(m_draw_type, 0, m_vertex_num);
}
}
else
{
zglCore::setBuffer(VERTEX_BUFFER, m_vbo_vertex);
zglCore::setVertexPointer2(NULL, sizeof(zglVertex));
zglCore::setColorPointer4( ((unsigned char*)NULL + 0x0c), sizeof(zglVertex));
if (m_texture)
{
zglCore::setTexture(m_texture->getTexID(), true);
zglCore::setTexCoordPointer2((float*)((char*)NULL + 0x10), sizeof(zglVertex));
}
else
{
zglCore::setTexture(0, false);
}
if( m_indices_num > 0)
{
zglCore::setBuffer(INDEX_BUFFER, m_vbo_index);
zglCore::drawElements(m_draw_type, m_indices_num, NULL);//
zglCore::setBuffer(INDEX_BUFFER, 0);
}
else
{
zglCore::drawArrays(m_draw_type, 0, m_vertex_num);
}
zglCore::setBuffer(VERTEX_BUFFER, 0);
}
//postRender();
}
void zglPrim2D::calcSortDepth()
{
unsigned char sort_value = m_sort_offset + 0x80;
if (sort_value > 0xff || sort_value < 0x00)
{
m_sort_value = 0x80; //!< Default value is 0x80
}
else
{
m_sort_value = sort_value;
}
}