31 Mesh::Mesh(GLuint type, GLuint hint) :
GLContainer(), _type(type), _hint(hint), _usageCount(0), _vao(0), _radius(0.0f) {
55 void Mesh::setType(GLuint type) {
59 GLuint Mesh::getType()
const {
63 void Mesh::setHint(GLuint hint) {
67 GLuint Mesh::getHint()
const {
72 float minx = 0.0f, miny = 0.0f, minz = 0.0f, maxx = 0.0f, maxy = 0.0f, maxz = 0.0f;
75 if (decl.size() >= 1) {
77 if ((decl[0].type == GL_FLOAT) && (decl[0].size == 3)) {
79 minx = maxx = *vertices++;
80 miny = maxy = *vertices++;
81 minz = maxz = *vertices++;
83 for (
size_t i = 0; i < vertexCount; ++i) {
84 float vx = *vertices++;
85 float vy = *vertices++;
86 float vz = *vertices++;
87 if (minx > vx) minx = vx;
88 if (miny > vy) miny = vy;
89 if (minz > vz) minz = vz;
90 if (maxx < vx) maxx = vx;
91 if (maxy < vy) maxy = vy;
92 if (maxz < vz) maxz = vz;
93 if (decl[0].stride > (
int32)(3 *
sizeof(float))) {
94 vertices += (decl[0].stride /
sizeof(float)) - 3;
97 _min = glm::vec3(minx, miny, minz);
98 _max = glm::vec3(maxx, maxy, maxz);
111 void Mesh::initGL() {
117 glGenVertexArrays(1, &
_vao);
118 glBindVertexArray(
_vao);
123 for (
uint32 i = 0; i < decl.size(); ++i) {
125 intptr_t offset = (intptr_t) (decl[i].pointer);
127 glVertexAttribPointer(decl[i].index,
132 reinterpret_cast<void *>(offset));
133 glEnableVertexAttribArray(decl[i].index);
141 glBindVertexArray(0);
144 glBindBuffer(GL_ARRAY_BUFFER, 0);
145 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
148 glBindBuffer(GL_ARRAY_BUFFER, 0);
149 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
155 void Mesh::updateGL() {
160 void Mesh::destroyGL() {
166 glDeleteVertexArrays(1, &
_vao);
171 void Mesh::renderImmediate() {
177 void Mesh::renderBind() {
179 glBindVertexArray(
_vao);
183 for (
size_t i = 0; i < decl.size(); ++i) {
184 intptr_t offset = (intptr_t) (decl[i].pointer);
186 switch (decl[i].index) {
188 glEnableClientState(GL_VERTEX_ARRAY);
189 glVertexPointer(decl[i].size, decl[i].type, decl[i].stride, (GLvoid *)(offset));
192 glEnableClientState(GL_NORMAL_ARRAY);
193 glNormalPointer(decl[i].type, decl[i].stride, (GLvoid *)(offset));
196 glEnableClientState(GL_COLOR_ARRAY);
197 glColorPointer(decl[i].size, decl[i].type, decl[i].stride, (GLvoid *)(offset));
200 glClientActiveTextureARB(GL_TEXTURE0 + decl[i].index -
VTCOORD);
201 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
202 glTexCoordPointer(decl[i].size, decl[i].type, decl[i].stride, (GLvoid *)(offset));
209 void Mesh::render() {
220 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
227 void Mesh::renderUnbind() {
230 glBindVertexArray(0);
233 for (
size_t i = 0; i < decl.size(); ++i) {
234 switch (decl[i].index) {
236 glDisableClientState(GL_VERTEX_ARRAY);
239 glDisableClientState(GL_NORMAL_ARRAY);
242 glDisableClientState(GL_COLOR_ARRAY);
245 glClientActiveTextureARB(GL_TEXTURE0 + decl[i].index -
VTCOORD);
246 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
250 glBindBuffer(GL_ARRAY_BUFFER, 0);
254 void Mesh::useIncrement() {
258 void Mesh::useDecrement() {
268 const glm::vec3 &Mesh::getCentre()
const {
272 float Mesh::getRadius()
const {
276 void Mesh::doRebuild() {
285 void Mesh::doDestroy() {
Vertex texture coordinates, VTCOORDi = VTCOORD + i.
void destroyGL()
Clear (destroy) GL resources associated with the buffer.
A class holding an UTF-8 string.
uint32 getCount() const
Get vertex count.
Generic mesh handling class.
void addToQueue(QueueType queue)
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
const VertexDecl & getVertexDecl() const
Access vertex declaration.
void updateGL()
Update existing GL buffer object.
void destroyGL()
Clear (destroy) GL resources associated with the buffer.
void initGL(GLuint hint=GL_STATIC_DRAW)
Initialise internal buffer object for GL handling.
Buffer containing vertex data.
GLenum getType() const
Get element type.
void removeFromQueue(QueueType queue)
uint32 getCount() const
Get element count.
void renderBind()
Follows the steps of renderImmediate, but broken into different functions.
VertexBuffer _vertexBuffer
GLvoid * getData()
Access buffer data.
A container of OpenGL elements.
Buffer containing indices data.
void initGL(GLuint hint=GL_STATIC_DRAW)
Initialise internal buffer object for GL handling.
void updateGL()
Update existing GL buffer object.
#define GfxMan
Shortcut for accessing the graphics manager.
GLuint _vao
Vertex Array Object handle. GL3.x only.