Batch::Batch(PrimitiveType t):
prim_type(t),
index_type(UNSIGNED_SHORT),
+ gl_index_type(get_gl_type(index_type)),
max_index(0),
restart(false)
{ }
shrink<UInt32, UInt16>(data);
index_type = t;
+ gl_index_type = get_gl_type(t);
update_offset();
dirty = true;
}
BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER);
const void *data_ptr = setup_draw();
- glDrawElements(prim_type, size(), index_type, data_ptr);
+ glDrawElements(prim_type, size(), gl_index_type, data_ptr);
}
void Batch::draw_instanced(unsigned count) const
BindRestore _bind_ibuf(get_buffer(), ELEMENT_ARRAY_BUFFER);
const void *data_ptr = setup_draw();
- glDrawElementsInstanced(prim_type, size(), index_type, data_ptr, count);
+ glDrawElementsInstanced(prim_type, size(), gl_index_type, data_ptr, count);
}
const void *Batch::setup_draw() const
private:
PrimitiveType prim_type;
DataType index_type;
+ GLenum gl_index_type;
std::vector<UInt8> data;
unsigned max_index;
bool restart;
#include <stdexcept>
+#include <msp/gl/extensions/nv_half_float.h>
#include "datatype.h"
using namespace std;
namespace Msp {
namespace GL {
-unsigned get_type_size(DataType type)
+GLenum get_gl_type(DataType type)
{
switch(type)
{
- case BYTE:
- case UNSIGNED_BYTE: return 1;
- case SHORT:
- case UNSIGNED_SHORT:
- case HALF_FLOAT: return 2;
- case INT:
- case UNSIGNED_INT:
- case FLOAT: return 4;
- default: throw invalid_argument("get_type_size");
+ case BYTE: return GL_BYTE;
+ case UNSIGNED_BYTE: return GL_UNSIGNED_BYTE;
+ case SHORT: return GL_SHORT;
+ case UNSIGNED_SHORT: return GL_UNSIGNED_SHORT;
+ case INT: return GL_INT;
+ case UNSIGNED_INT: return GL_UNSIGNED_INT;
+ case FLOAT: return GL_FLOAT;
+ case HALF_FLOAT: return GL_HALF_FLOAT;
+ default: throw invalid_argument("get_gl_type");
}
}
#define MSP_GL_DATATYPE_H_
#include "gl.h"
-#include <msp/gl/extensions/nv_half_float.h>
namespace Msp {
namespace GL {
enum DataType
{
- BYTE = GL_BYTE,
- UNSIGNED_BYTE = GL_UNSIGNED_BYTE,
- SHORT = GL_SHORT,
- UNSIGNED_SHORT = GL_UNSIGNED_SHORT,
- INT = GL_INT,
- UNSIGNED_INT = GL_UNSIGNED_INT,
- FLOAT = GL_FLOAT,
- HALF_FLOAT = GL_HALF_FLOAT
+ BYTE = 0x101,
+ UNSIGNED_BYTE = 0x001,
+ SHORT = 0x102,
+ UNSIGNED_SHORT = 0x002,
+ INT = 0x104,
+ UNSIGNED_INT = 0x004,
+ FLOAT = 0x304,
+ HALF_FLOAT = 0x302
};
-unsigned get_type_size(DataType);
+inline unsigned get_type_size(DataType t)
+{ return t&0xFF; }
+
+GLenum get_gl_type(DataType);
} // namespace GL
} // namespace Msp
}
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
glTexImage1D(target, level, storage_fmt, w, 0, comp, type, data);
allocated |= 1<<level;
allocate(level);
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
if(ARB_direct_state_access)
glTextureSubImage1D(id, level, x, wd, comp, type, data);
else
}
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
glTexImage2D(target, level, storage_fmt, w, h, 0, comp, type, data);
allocated |= 1<<level;
allocate(level);
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
if(ARB_direct_state_access)
glTextureSubImage2D(id, level, x, y, wd, ht, comp, type, data);
else
}
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
glTexImage3D(target, level, storage_fmt, width, height, depth, 0, comp, type, data);
allocated |= 1<<level;
allocate(level);
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
if(ARB_direct_state_access)
glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, comp, type, data);
else
}
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
glTexImage2D(face, level, storage_fmt, s, s, 0, comp, type, data);
if(level==0)
allocate(level);
PixelComponents comp = get_components(storage_fmt);
- DataType type = get_component_type(storage_fmt);
+ GLenum type = get_gl_type(get_component_type(storage_fmt));
glTexSubImage2D(face, level, x, y, wd, ht, comp, type, data);
if(auto_gen_mipmap && level==0)