max_index(0)
{ }
-Batch &Batch::append(uint i)
+Batch &Batch::append(unsigned i)
{
if(indices.empty())
min_index=max_index=i;
return *this;
}
-void Batch::append(const vector<uint> &ind)
+void Batch::append(const vector<unsigned> &ind)
{
indices.reserve(indices.size()+ind.size());
- for(vector<uint>::const_iterator i=ind.begin(); i!=ind.end(); ++i)
+ for(vector<unsigned>::const_iterator i=ind.begin(); i!=ind.end(); ++i)
append(*i);
}
add("indices", &Loader::indices);
}
-void Batch::Loader::indices(const vector<uint> &ind)
+void Batch::Loader::indices(const vector<unsigned> &ind)
{
obj.append(ind);
}
#include <vector>
#include <msp/datafile/objectloader.h>
#include "primitivetype.h"
-#include "types.h"
namespace Msp {
namespace GL {
public:
Loader(Batch &);
private:
- void indices(const std::vector<uint> &);
+ void indices(const std::vector<unsigned> &);
};
private:
PrimitiveType type;
- std::vector<uint> indices;
- uint min_index;
- uint max_index;
+ std::vector<unsigned> indices;
+ unsigned min_index;
+ unsigned max_index;
public:
Batch(PrimitiveType t);
- Batch &append(uint);
- void append(const std::vector<uint> &);
+
+ Batch &append(unsigned);
+ void append(const std::vector<unsigned> &);
PrimitiveType get_type() const { return type; }
unsigned size() const { return indices.size(); }
- const std::vector<uint> &get_indices() const { return indices; }
+ const std::vector<unsigned> &get_indices() const { return indices; }
void draw() const;
void draw_with_buffer(unsigned) const;
};
#ifndef MSP_GL_BUFFER_H_
#define MSP_GL_BUFFER_H_
-#include "types.h"
+#include "gl.h"
namespace Msp {
namespace GL {
--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_GL_TYPES_H_
+#define MSP_GL_TYPES_H_
+
+#include "gl.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,
+ DOUBLE = GL_DOUBLE
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
ExtFunc *get_proc_address(const string &name)
{
#ifndef WIN32
- return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(name.c_str()));
+ return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
#else
return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
#endif
#include <vector>
#include "gl.h"
-#include "types.h"
namespace Msp {
namespace GL {
Attachment &operator=(Texture &);
};
- uint id;
+ unsigned id;
std::vector<Attachment> attachments;
unsigned width;
unsigned height;
del_shaders=ds;
}
-void Program::bind_attribute(uint index, const string &name)
+void Program::bind_attribute(unsigned index, const string &name)
{
static RequireExtension _ext("GL_ARB_vertex_shader");
glBindAttribLocationARB(id, index, name.c_str());
string Program::get_info_log() const
{
- sizei len=get_param(GL_INFO_LOG_LENGTH);
+ GLsizei len=get_param(GL_INFO_LOG_LENGTH);
char log[len+1];
- glGetInfoLogARB(id, len+1, reinterpret_cast<GLsizei *>(&len), log);
+ glGetInfoLogARB(id, len+1, &len, log);
return string(log, len);
}
obj.attach_shader(*new Shader(FRAGMENT_SHADER, src));
}
-void Program::Loader::attribute(uint i, const string &n)
+void Program::Loader::attribute(unsigned i, const string &n)
{
obj.bind_attribute(i, n);
}
#include <string>
#include <msp/datafile/objectloader.h>
#include "gl.h"
-#include "types.h"
namespace Msp {
namespace GL {
class Program
{
private:
- uint id;
+ unsigned id;
std::list<Shader *> shaders;
bool del_shaders;
bool linked;
private:
void vertex_shader(const std::string &);
void fragment_shader(const std::string &);
- void attribute(uint, const std::string &);
+ void attribute(unsigned, const std::string &);
virtual void finish();
};
void detach_shader(Shader &shader);
const std::list<Shader *> &get_shaders() const { return shaders; }
void set_del_shaders(bool);
- void bind_attribute(uint, const std::string &);
+ void bind_attribute(unsigned, const std::string &);
void link();
int get_param(GLenum param) const;
bool get_linked() const { return linked; }
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, id);
}
-void Renderbuffer::storage(PixelFormat fmt, sizei w, sizei h)
+void Renderbuffer::storage(PixelFormat fmt, unsigned w, unsigned h)
{
bind();
width=w;
#define MSP_GL_RENDERBUFFER_H_
#include "pixelformat.h"
-#include "types.h"
namespace Msp {
namespace GL {
class Renderbuffer
{
private:
- uint id;
- sizei width;
- sizei height;
+ unsigned id;
+ unsigned width;
+ unsigned height;
public:
Renderbuffer();
~Renderbuffer();
- uint get_id() const { return id; }
- sizei get_width() const { return width; }
- sizei get_height() const { return height; }
+ unsigned get_id() const { return id; }
+ unsigned get_width() const { return width; }
+ unsigned get_height() const { return height; }
void bind() const;
- void storage(PixelFormat fmt, sizei width, sizei height);
+ void storage(PixelFormat fmt, unsigned width, unsigned height);
};
} // namespace GL
namespace {
vector<Msp::GL::SelectRecord> *select_buf=0;
-vector<Msp::GL::uint> select_buf_int;
+vector<unsigned> select_buf_int;
}
glInitNames();
}
-void push_name(uint n)
+void push_name(unsigned n)
{
glPushName(n);
}
glPopName();
}
-void load_name(uint n)
+void load_name(unsigned n)
{
glLoadName(n);
}
-void parse_select_records(const uint *buf, uint count, vector<SelectRecord> &tbuf)
+void parse_select_records(const unsigned *buf, unsigned count, vector<SelectRecord> &tbuf)
{
- uint i=0;
+ unsigned i=0;
while(count--)
{
SelectRecord record;
- uint n_names=buf[i++];
+ unsigned n_names=buf[i++];
record.min_depth=buf[i++];
record.max_depth=buf[i++];
}
}
-void _parse_internal_select_records(uint count)
+void _parse_internal_select_records(unsigned count)
{
if(!select_buf)
throw InvalidState("No select buffer specified");
#define MSP_GL_SELECT_H_
#include <vector>
-#include "types.h"
namespace Msp {
namespace GL {
struct SelectRecord
{
- uint min_depth;
- uint max_depth;
- std::vector<uint> names;
+ unsigned min_depth;
+ unsigned max_depth;
+ std::vector<unsigned> names;
};
void select_buffer(std::vector<SelectRecord> &);
void init_names();
-void push_name(uint);
+void push_name(unsigned);
void pop_name();
-void load_name(uint);
+void load_name(unsigned);
-void parse_select_records(const uint *buf, uint, std::vector<SelectRecord> &);
+void parse_select_records(const unsigned *buf, unsigned, std::vector<SelectRecord> &);
-void _parse_internal_select_records(uint);
+void _parse_internal_select_records(unsigned);
} // namespace GL
} // namespace Msp
glDeleteObjectARB(id);
}
-void Shader::source(sizei count, const char **str, const int *len)
+void Shader::source(unsigned count, const char **str, const int *len)
{
glShaderSourceARB(id, count, str, len);
}
string Shader::get_info_log() const
{
- sizei len=get_param(GL_INFO_LOG_LENGTH);
+ GLsizei len=get_param(GL_INFO_LOG_LENGTH);
char log[len+1];
- glGetInfoLogARB(id, len+1, reinterpret_cast<GLsizei *>(&len), log);
+ glGetInfoLogARB(id, len+1, &len, log);
return string(log, len);
}
#include <string>
#include "gl.h"
-#include "types.h"
namespace Msp {
namespace GL {
public:
~Shader();
- void source(sizei count, const char **str, const int *len);
+ void source(unsigned count, const char **str, const int *len);
void source(const std::string &str);
void source(const char *str, int len);
void compile();
- uint get_id() const { return id; }
+ unsigned get_id() const { return id; }
bool get_compiled() const { return compiled; }
int get_param(GLenum param) const;
std::string get_info_log() const;
private:
- uint id;
+ unsigned id;
bool compiled;
};
namespace Msp {
namespace GL {
-void stencil_func(Predicate func, int ref, uint mask)
+void stencil_func(Predicate func, int ref, unsigned mask)
{
glStencilFunc(func, ref, mask);
}
#include "gl.h"
#include "predicate.h"
-#include "types.h"
namespace Msp {
namespace GL {
DECR_WRAP = GL_DECR_WRAP
};
-void stencil_func(Predicate func, int ref, uint mask);
+void stencil_func(Predicate func, int ref, unsigned mask);
void stencil_op(StencilOp sfail, StencilOp dfail, StencilOp dpass);
} // namespace GL
namespace Msp {
namespace GL {
-void scissor(int left, int bottom, sizei width, sizei height)
+void scissor(int left, int bottom, unsigned width, unsigned height)
{
glScissor(left, bottom, width, height);
}
#include "gl.h"
#include "predicate.h"
-#include "types.h"
namespace Msp {
namespace GL {
DEPTH_TEST = GL_DEPTH_TEST
};
-void scissor(int left, int bottom, sizei width, sizei height);
+void scissor(int left, int bottom, unsigned width, unsigned height);
void alpha_func(Predicate func, float ref);
#include <istream>
#include <msp/datafile/objectloader.h>
#include "gl.h"
-#include "types.h"
namespace Msp {
namespace GL {
void set_min_filter(TextureFilter f) { parameter(GL_TEXTURE_MIN_FILTER, f); }
void set_mag_filter(TextureFilter f) { parameter(GL_TEXTURE_MAG_FILTER, f); }
GLenum get_target() const { return target; }
- uint get_id() const { return id; }
+ unsigned get_id() const { return id; }
static void unbind();
static void unbind_from(unsigned);
protected:
- uint id;
+ unsigned id;
GLenum target;
Texture();
bind();
}
-void Texture2D::storage(PixelFormat fmt, sizei wd, sizei ht, int brd)
+void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, int brd)
{
if(width>0)
throw InvalidState("Texture storage may only be specified once");
glTexImage2D(target, level, ifmt, width, height, border, fmt, type, data);
}
-void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, DataType type, const void *data)
+void Texture2D::sub_image(int level, int x, int y, unsigned wd, unsigned ht, PixelFormat fmt, DataType type, const void *data)
{
if(width==0)
throw InvalidState("Texture storage has not been specified");
#include <string>
#include <msp/gbase/image.h>
+#include "datatype.h"
#include "pixelformat.h"
#include "texture.h"
private:
PixelFormat ifmt;
- sizei width;
- sizei height;
+ unsigned width;
+ unsigned height;
int border;
public:
Defines the texture storage. This function may only be successfully called
once.
*/
- void storage(PixelFormat fmt, sizei wd, sizei ht, int brd);
+ void storage(PixelFormat fmt, unsigned wd, unsigned ht, int brd);
/**
Uploads an image to the texture. storage() must have been called prior to
Uploads a sub-image into the texture. Unlike full image upload, there are
no constraints on the size of the sub-image.
*/
- void sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, DataType type, const void *data);
+ void sub_image(int level, int x, int y, unsigned wd, unsigned ht, PixelFormat fmt, DataType type, const void *data);
/**
Loads an image from a file and uploads it to the texture. If storage() has
*/
void load_image(const std::string &fn);
- sizei get_width() const { return width; }
- sizei get_height() const { return height; }
+ unsigned get_width() const { return width; }
+ unsigned get_height() const { return height; }
private:
void image(const Graphics::Image &);
bind();
}
-void Texture3D::storage(PixelFormat f, sizei w, sizei h, sizei d, int b)
+void Texture3D::storage(PixelFormat f, unsigned w, unsigned h, unsigned d, int b)
{
if(width>0)
throw InvalidState("Textures may only be created once");
#define MSP_GL_TEXTURE3D_H_
#include <string>
+#include "datatype.h"
#include "pixelformat.h"
#include "texture.h"
{
private:
PixelFormat ifmt;
- sizei width;
- sizei height;
- sizei depth;
+ unsigned width;
+ unsigned height;
+ unsigned depth;
int border;
public:
Texture3D();
- void storage(PixelFormat, sizei, sizei, sizei, int);
+ void storage(PixelFormat, unsigned, unsigned, unsigned, int);
void image(int, PixelFormat, DataType, const void *);
- void sub_image(int, int, int, sizei, sizei, sizei, PixelFormat, DataType, const void *);
+ void sub_image(int, int, int, unsigned, unsigned, unsigned, PixelFormat, DataType, const void *);
void load_image(const std::string &fn, int dp=-1);
- sizei get_width() const { return width; }
- sizei get_height() const { return height; }
- sizei get_depth() const { return depth; }
+ unsigned get_width() const { return width; }
+ unsigned get_height() const { return height; }
+ unsigned get_depth() const { return depth; }
};
} // namespace GL
+++ /dev/null
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#ifndef MSP_GL_TYPES_H_
-#define MSP_GL_TYPES_H_
-
-#include "gl.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,
- DOUBLE = GL_DOUBLE
-};
-
-typedef signed char byte;
-typedef unsigned char ubyte;
-typedef unsigned sizei;
-typedef unsigned uint;
-
-} // namespace GL
-} // namespace Msp
-
-#endif
vbuf->bind();
const float *base=vbuf?0:&data[0];
- uint offset=0;
- uint found=0;
- uint bpv=stride*sizeof(float);
+ unsigned offset=0;
+ unsigned found=0;
+ unsigned bpv=stride*sizeof(float);
for(const unsigned char *c=format.begin(); c!=format.end(); ++c)
{
- uint sz=(*c&3)+1;
- uint t=*c>>2;
+ unsigned sz=(*c&3)+1;
+ unsigned t=*c>>2;
switch(t)
{
case 0:
glArrayElement(i);
}
-void draw_arrays(PrimitiveType mode, int first, sizei count)
+void draw_arrays(PrimitiveType mode, int first, unsigned count)
{
glDrawArrays(mode, first, count);
}
-void draw_elements(PrimitiveType mode, sizei count, DataType type, const void *indices)
+void draw_elements(PrimitiveType mode, unsigned count, DataType type, const void *indices)
{
glDrawElements(mode, count, type, indices);
}
-void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, DataType type, const void *indices)
+void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, DataType type, const void *indices)
{
static RequireVersion _ver(1, 2);
glDrawRangeElements(mode, low, high, count, type, indices);
#include <vector>
#include <msp/core/refptr.h>
#include <msp/datafile/loader.h>
+#include "datatype.h"
#include "primitivetype.h"
-#include "types.h"
#include "vertexarraybuilder.h"
#include "vertexformat.h"
private:
VertexFormat format;
std::vector<float> data;
- uint stride;
- Buffer *vbuf;
- bool own_vbuf;
+ unsigned stride;
+ Buffer *vbuf;
+ bool own_vbuf;
VertexArray(const VertexArray &);
VertexArray &operator=(const VertexArray &);
};
void array_element(int);
-void draw_arrays(PrimitiveType, int, sizei);
-void draw_elements(PrimitiveType, sizei, DataType, const void *);
-void draw_range_elements(PrimitiveType, uint, uint, sizei, DataType, const void *);
+void draw_arrays(PrimitiveType, int, unsigned);
+void draw_elements(PrimitiveType, unsigned, DataType, const void *);
+void draw_range_elements(PrimitiveType, unsigned, unsigned, unsigned, DataType, const void *);
-inline void draw_elements(PrimitiveType mode, sizei count, const unsigned *indices)
+inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned *indices)
{ draw_elements(mode, count, UNSIGNED_INT, indices); }
-inline void draw_elements(PrimitiveType mode, sizei count, const unsigned short *indices)
+inline void draw_elements(PrimitiveType mode, unsigned count, const unsigned short *indices)
{ draw_elements(mode, count, UNSIGNED_SHORT, indices); }
-inline void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, const unsigned short *indices)
+inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned short *indices)
{ draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); }
-inline void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, const unsigned *indices)
+inline void draw_range_elements(PrimitiveType mode, unsigned low, unsigned high, unsigned count, const unsigned *indices)
{ draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); }
} // namespace GL
float *ptr=array.append();
for(const unsigned char *c=array.get_format().begin(); c!=array.get_format().end(); ++c)
{
- uint size=(*c&3)+1;
- uint type=*c>>2;
+ unsigned size=(*c&3)+1;
+ unsigned type=*c>>2;
switch(type)
{
case 0:
case 3:
if(size==1)
{
- union { ubyte c[4]; float f; } u;
- u.c[0]=static_cast<ubyte>(cr*255);
- u.c[1]=static_cast<ubyte>(cg*255);
- u.c[2]=static_cast<ubyte>(cb*255);
- u.c[3]=static_cast<ubyte>(ca*255);
+ union { unsigned char c[4]; float f; } u;
+ u.c[0]=static_cast<unsigned char>(cr*255);
+ u.c[1]=static_cast<unsigned char>(cg*255);
+ u.c[2]=static_cast<unsigned char>(cb*255);
+ u.c[3]=static_cast<unsigned char>(ca*255);
*ptr++=u.f;
}
else
#define MSP_GL_VERTEXBUILDER_H_
#include <map>
-#include "types.h"
namespace Msp {
namespace GL {
void texcoord(float s, float t) { texcoord(s, t, 0, 1); }
void texcoord(float s, float t, float r) { texcoord(s, t, r, 1); }
void texcoord(float s, float t, float r, float q) { ts=s; tt=t; tr=r; tq=q; }
- void color(ubyte r, ubyte g, ubyte b) { color(r, g, b, 255); }
- void color(ubyte r, ubyte g, ubyte b, ubyte a) { color(r/255.f, g/255.f, b/255.f, a/255.f); }
+ void color(unsigned char r, unsigned char g, unsigned char b) { color(r, g, b, 255); }
+ void color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { color(r/255.f, g/255.f, b/255.f, a/255.f); }
void color(float r, float g, float b) { color(r, g, b, 1); }
void color(float r, float g, float b, float a) { cr=r; cg=g; cb=b; ca=a; }
void attrib(unsigned i, float x) { attrib(i, x, 0, 0, 1); }
unsigned VertexFormat::stride() const
{
- uint s=0;
+ unsigned s=0;
for(const unsigned char *i=begin(); i!=end(); ++i)
s+=(*i&3)+1;
return s;
#define MSP_GL_VERTEXFORMAT_H_
#include <istream>
-#include "types.h"
namespace Msp {
namespace GL {
inline VertexFormat operator,(VertexComponent c, unsigned i)
{ return (VertexFormat(c), i); }
-inline uint get_stride(const VertexFormat &f)
+inline unsigned get_stride(const VertexFormat &f)
{ return f.stride(); }
std::istream &operator>>(std::istream &, VertexFormat &);