Wrap IBO index type into one definition
Makes it easier to switch between types (eg. 32 -> 16 bit).
This commit is contained in:
		
							parent
							
								
									295e0e5b15
								
							
						
					
					
						commit
						caae9c5689
					
				
					 4 changed files with 18 additions and 11 deletions
				
			
		| 
						 | 
					@ -25,11 +25,18 @@
 | 
				
			||||||
#include "gl-util.h"
 | 
					#include "gl-util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <limits>
 | 
				
			||||||
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef uint32_t index_t;
 | 
				
			||||||
 | 
					#define INDEX_T_MAX std::numeric_limits<index_t>::max()
 | 
				
			||||||
 | 
					#define _GL_INDEX_TYPE GL_UNSIGNED_INT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct GlobalIBO
 | 
					struct GlobalIBO
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	IBO::ID ibo;
 | 
						IBO::ID ibo;
 | 
				
			||||||
	std::vector<uint32_t> buffer;
 | 
						std::vector<index_t> buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	GlobalIBO()
 | 
						GlobalIBO()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					@ -43,6 +50,8 @@ struct GlobalIBO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void ensureSize(size_t quadCount)
 | 
						void ensureSize(size_t quadCount)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							assert(quadCount*6 < INDEX_T_MAX);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (buffer.size() >= quadCount*6)
 | 
							if (buffer.size() >= quadCount*6)
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,14 +60,14 @@ struct GlobalIBO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (size_t i = startInd; i < quadCount; ++i)
 | 
							for (size_t i = startInd; i < quadCount; ++i)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			static const uint32_t indTemp[] = { 0, 1, 2, 2, 3, 0 };
 | 
								static const index_t indTemp[] = { 0, 1, 2, 2, 3, 0 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (size_t j = 0; j < 6; ++j)
 | 
								for (size_t j = 0; j < 6; ++j)
 | 
				
			||||||
				buffer.push_back(i * 4 + indTemp[j]);
 | 
									buffer.push_back(i * 4 + indTemp[j]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		IBO::bind(ibo);
 | 
							IBO::bind(ibo);
 | 
				
			||||||
		IBO::uploadData(buffer.size() * sizeof(uint32_t), &buffer[0]);
 | 
							IBO::uploadData(buffer.size() * sizeof(index_t), &buffer[0]);
 | 
				
			||||||
		IBO::unbind();
 | 
							IBO::unbind();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -176,7 +176,7 @@ struct Quad
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		VAO::bind(vao);
 | 
							VAO::bind(vao);
 | 
				
			||||||
		gl.DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
 | 
							gl.DrawElements(GL_TRIANGLES, 6, _GL_INDEX_TYPE, 0);
 | 
				
			||||||
		VAO::unbind();
 | 
							VAO::unbind();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,9 +31,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef uint32_t index_t;
 | 
					 | 
				
			||||||
#define _GL_INDEX_TYPE GL_UNSIGNED_INT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* A small hack to get mutable QuadArray constructors */
 | 
					/* A small hack to get mutable QuadArray constructors */
 | 
				
			||||||
inline void initBufferBindings(Vertex *)
 | 
					inline void initBufferBindings(Vertex *)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@
 | 
				
			||||||
#include "sharedstate.h"
 | 
					#include "sharedstate.h"
 | 
				
			||||||
#include "glstate.h"
 | 
					#include "glstate.h"
 | 
				
			||||||
#include "gl-util.h"
 | 
					#include "gl-util.h"
 | 
				
			||||||
 | 
					#include "global-ibo.h"
 | 
				
			||||||
#include "etc-internal.h"
 | 
					#include "etc-internal.h"
 | 
				
			||||||
#include "quadarray.h"
 | 
					#include "quadarray.h"
 | 
				
			||||||
#include "texpool.h"
 | 
					#include "texpool.h"
 | 
				
			||||||
| 
						 | 
					@ -1124,12 +1125,12 @@ void GroundLayer::draw()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void GroundLayer::drawInt()
 | 
					void GroundLayer::drawInt()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	gl.DrawElements(GL_TRIANGLES, vboCount, GL_UNSIGNED_INT, (GLvoid*) 0);
 | 
						gl.DrawElements(GL_TRIANGLES, vboCount, _GL_INDEX_TYPE, (GLvoid*) 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void GroundLayer::drawFlashInt()
 | 
					void GroundLayer::drawFlashInt()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	gl.DrawElements(GL_TRIANGLES, p->flash.quadCount * 6, GL_UNSIGNED_INT, 0);
 | 
						gl.DrawElements(GL_TRIANGLES, p->flash.quadCount * 6, _GL_INDEX_TYPE, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void GroundLayer::onGeometryChange(const Scene::Geometry &geo)
 | 
					void GroundLayer::onGeometryChange(const Scene::Geometry &geo)
 | 
				
			||||||
| 
						 | 
					@ -1154,7 +1155,7 @@ void ScanRow::setIndex(int value)
 | 
				
			||||||
	z = calculateZ(p, index);
 | 
						z = calculateZ(p, index);
 | 
				
			||||||
	scene->reinsert(*this);
 | 
						scene->reinsert(*this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vboOffset = p->scanrowBases[index] * sizeof(uint32_t) * 6;
 | 
						vboOffset = p->scanrowBases[index] * sizeof(index_t) * 6;
 | 
				
			||||||
	vboCount = p->scanrowSize(index) * 6;
 | 
						vboCount = p->scanrowSize(index) * 6;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1178,7 +1179,7 @@ void ScanRow::draw()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ScanRow::drawInt()
 | 
					void ScanRow::drawInt()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	gl.DrawElements(GL_TRIANGLES, vboBatchCount, GL_UNSIGNED_INT, (GLvoid*) vboOffset);
 | 
						gl.DrawElements(GL_TRIANGLES, vboBatchCount, _GL_INDEX_TYPE, (GLvoid*) vboOffset);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ScanRow::calculateZ(TilemapPrivate *p, int index)
 | 
					int ScanRow::calculateZ(TilemapPrivate *p, int index)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue