void PrimitiveBuilder::vertex_(const Vector4 &v)
{
- const VertexFormat &format = array.get_format();
- for(const uint16_t *a=format.begin(); a!=format.end(); ++a)
+ for(VertexAttribute a: array.get_format())
{
- unsigned sem = get_attribute_semantic(*a);
+ unsigned sem = get_attribute_semantic(a);
if(sem<attr.size())
vab.attrib(sem, attr[sem]);
}
void VertexArrayBuilder::vertex_(const Vector4 &vtx)
{
char *ptr = array.append();
- const VertexFormat &format = array.get_format();
- for(const uint16_t *a=format.begin(); a!=format.end(); ++a)
+ for(VertexAttribute a: array.get_format())
{
- unsigned sem = get_attribute_semantic(*a);
- bool integer = is_integer_attribute(*a);
- DataType type = get_attribute_source_type(*a);
- unsigned cc = get_attribute_component_count(*a);
+ unsigned sem = get_attribute_semantic(a);
+ bool integer = is_integer_attribute(a);
+ DataType type = get_attribute_source_type(a);
+ unsigned cc = get_attribute_component_count(a);
if(sem<attr.size())
{
store_attribute<float>(ptr, value, false, cc);
}
- ptr += get_attribute_size(*a);
+ ptr += get_attribute_size(a);
}
}
vector<GLenum> color_bufs;
color_bufs.reserve(format.size());
unsigned i = 0;
- for(const uint16_t *j=format.begin(); j!=format.end(); ++j, ++i)
+ for(FrameAttachment a: format)
{
- GLenum gl_attach_point = get_gl_attachment(static_cast<FrameAttachment>(*j));
+ GLenum gl_attach_point = get_gl_attachment(a);
if(dirty&(1<<i))
{
const Attachment &attch = attachments[i];
if(gl_attach_point!=GL_DEPTH_ATTACHMENT && gl_attach_point!=GL_STENCIL_ATTACHMENT)
color_bufs.push_back(gl_attach_point);
+
+ ++i;
}
if(color_bufs.size()>1)
throw incompatible_data("Framebuffer::attach");
unsigned i = 0;
- for(const uint16_t *j=format.begin(); j!=format.end(); ++j, ++i)
- if(*j==attch)
+ for(FrameAttachment a: format)
+ {
+ if(a==attch)
{
attachments[i].set(tex, level, layer);
dirty |= 1<<i;
check_size();
return;
}
+ ++i;
+ }
throw incompatible_data("Framebuffer::attach");
}
throw invalid_operation("FrameFormat::operator,");
FrameFormat r = *this;
- uint16_t &fa = r.attachments[r.count-1];
- fa = make_typed_attachment(static_cast<FrameAttachment>(fa), pf);
+ FrameAttachment &fa = r.attachments[r.count-1];
+ fa = make_typed_attachment(fa, pf);
return r;
}
throw invalid_operation("FrameFormat::operator,");
FrameFormat r = *this;
- uint16_t &fa = r.attachments[r.count-1];
- fa = make_indexed_attachment(static_cast<FrameAttachment>(fa), index);
+ FrameAttachment &fa = r.attachments[r.count-1];
+ fa = make_indexed_attachment(fa, index);
return r;
}
throw invalid_argument("make_indexed_attachment");
}
-PixelFormat get_attachment_pixelformat(uint16_t fa)
+PixelFormat get_attachment_pixelformat(FrameAttachment fa)
{
PixelComponents comp;
if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
This information is presented for internal documentation purposes only; it is
inadvisable for programs to rely on it.
*/
-enum FrameAttachment
+enum FrameAttachment: std::uint16_t
{
COLOR_ATTACHMENT = 0x0014,
DEPTH_ATTACHMENT = 0xF941,
std::uint8_t count;
std::uint8_t samples;
- std::uint16_t attachments[MAX_ATTACHMENTS];
+ FrameAttachment attachments[MAX_ATTACHMENTS];
public:
FrameFormat();
unsigned size() const { return count; }
bool empty() const { return !count; }
- const std::uint16_t *begin() const { return attachments; }
- const std::uint16_t *end() const { return attachments+count; }
+ const FrameAttachment *begin() const { return attachments; }
+ const FrameAttachment *end() const { return attachments+count; }
int index(FrameAttachment) const;
};
inline FrameAttachment operator,(FrameAttachment fa, unsigned i)
{ return make_indexed_attachment(fa, i); }
-inline unsigned get_attach_point(std::uint16_t fa)
+inline unsigned get_attach_point(FrameAttachment fa)
{ return fa>>10; }
-PixelFormat get_attachment_pixelformat(std::uint16_t);
+PixelFormat get_attachment_pixelformat(FrameAttachment);
GLenum get_gl_attachment(FrameAttachment);
throw invalid_operation("VertexFormat::operator,");
VertexFormat r = *this;
- uint16_t &a = r.attributes[r.count-1];
- a = make_typed_attribute(static_cast<VertexAttribute>(a), t);
+ VertexAttribute &a = r.attributes[r.count-1];
+ a = make_typed_attribute(a, t);
return r;
}
throw invalid_operation("VertexFormat::operator,");
VertexFormat r = *this;
- uint16_t &a = r.attributes[r.count-1];
- a = make_indexed_attribute(static_cast<VertexAttribute>(a), i);
+ VertexAttribute &a = r.attributes[r.count-1];
+ a = make_indexed_attribute(a, i);
return r;
}
unsigned VertexFormat::stride() const
{
unsigned s = 0;
- for(const uint16_t *i=begin(); i!=end(); ++i)
- s += get_attribute_size(*i);
+ for(VertexAttribute a: *this)
+ s += get_attribute_size(a);
return s;
}
{
unsigned sem = get_attribute_semantic(attr);
unsigned offs = 0;
- for(const uint16_t *i=begin(); i!=end(); ++i)
+ for(VertexAttribute a: *this)
{
- if(get_attribute_semantic(*i)==sem)
+ if(get_attribute_semantic(a)==sem)
{
- if(get_attribute_source_type(*i)==get_attribute_source_type(attr) &&
- get_attribute_component_count(*i)>=get_attribute_component_count(attr))
+ if(get_attribute_source_type(a)==get_attribute_source_type(attr) &&
+ get_attribute_component_count(a)>=get_attribute_component_count(attr))
return offs;
else
return -1;
}
else
- offs += get_attribute_size(*i);
+ offs += get_attribute_size(a);
}
return -1;
VertexAttribute make_indexed_attribute(VertexAttribute attr, unsigned index)
{
- unsigned base = attr;
+ VertexAttribute base = attr;
if(get_attribute_semantic(attr)==get_attribute_semantic(TEXCOORD1))
{
if(index>=4)
throw out_of_range("make_indexed_attribute");
}
else if(get_attribute_semantic(attr)==get_attribute_semantic(RAW_ATTRIB1))
- base &= 0x3FF;
+ base = static_cast<VertexAttribute>(base&0x3FF);
else if(get_attribute_semantic(attr)!=get_attribute_semantic(GENERIC1))
throw invalid_argument("make_indexed_attribute");
This information is presented for internal documentation purposes only; it is
inadvisable for programs to rely on it.
*/
-enum VertexAttribute
+enum VertexAttribute: std::uint16_t
{
VERTEX2 = 0x01C2,
VERTEX3 = 0x01C3,
enum { MAX_ATTRIBUTES = 15 };
std::uint8_t count;
- std::uint16_t attributes[MAX_ATTRIBUTES];
+ VertexAttribute attributes[MAX_ATTRIBUTES];
public:
VertexFormat();
bool operator!=(const VertexFormat &other) const { return !(*this==other); }
bool empty() const { return !count; }
- const std::uint16_t *begin() const { return attributes; }
- const std::uint16_t *end() const { return attributes+count; }
+ const VertexAttribute *begin() const { return attributes; }
+ const VertexAttribute *end() const { return attributes+count; }
unsigned stride() const;
int offset(VertexAttribute) const;
};
inline VertexAttribute operator,(VertexAttribute a, unsigned i)
{ return make_indexed_attribute(a, i); }
-inline unsigned get_attribute_semantic(std::uint16_t a)
+inline unsigned get_attribute_semantic(VertexAttribute a)
{ return a>>10; }
-inline DataType get_attribute_source_type(std::uint16_t a)
+inline DataType get_attribute_source_type(VertexAttribute a)
{ return static_cast<DataType>((a&0x70)>>4 | (a&0x180)<<1); }
-inline unsigned get_attribute_component_count(std::uint16_t a)
+inline unsigned get_attribute_component_count(VertexAttribute a)
{ return a&7; }
-inline unsigned get_attribute_size(std::uint16_t a)
+inline unsigned get_attribute_size(VertexAttribute a)
{ return get_attribute_component_count(a)*get_type_size(get_attribute_source_type(a)); }
-inline bool is_integer_attribute(std::uint16_t a)
+inline bool is_integer_attribute(VertexAttribute a)
{ return a&8; }
void operator>>(const LexicalConverter &, VertexAttribute &);
unsigned max_attribs = Limits::get_global().max_vertex_attributes;
- for(const uint16_t *a=fmt.begin(); a!=fmt.end(); ++a)
- if(get_attribute_semantic(*a)>=max_attribs)
+ for(VertexAttribute a: fmt)
+ if(get_attribute_semantic(a)>=max_attribs)
return false;
return true;
void VertexSetup::require_format(const VertexFormat &fmt)
{
bool has_int = false;
- for(const uint16_t *a=fmt.begin(); a!=fmt.end(); ++a)
- has_int = has_int | is_integer_attribute(*a);
+ for(VertexAttribute a: fmt)
+ has_int = has_int | is_integer_attribute(a);
if(has_int)
static Require _req(EXT_gpu_shader4);
}
unsigned offset = 0;
- for(const uint16_t *a=fmt.begin(); a!=fmt.end(); ++a)
+ for(VertexAttribute a: fmt)
{
- unsigned sem = get_attribute_semantic(*a);
- bool integer = is_integer_attribute(*a);
- GLenum type = get_gl_type(get_attribute_source_type(*a));
- unsigned cc = get_attribute_component_count(*a);
+ unsigned sem = get_attribute_semantic(a);
+ bool integer = is_integer_attribute(a);
+ GLenum type = get_gl_type(get_attribute_source_type(a));
+ unsigned cc = get_attribute_component_count(a);
if(direct)
{
if(integer)
glVertexAttribDivisor(sem, divisor);
glEnableVertexAttribArray(sem);
}
- offset += get_attribute_size(*a);
+ offset += get_attribute_size(a);
}
if(!direct)
glBindVertexArray(id);
glBindBuffer(GL_ARRAY_BUFFER, 0);
- for(const uint16_t *a=vertex_format.begin(); a!=vertex_format.end(); ++a)
+ for(VertexAttribute a: vertex_format)
{
- unsigned sem = get_attribute_semantic(*a);
+ unsigned sem = get_attribute_semantic(a);
glDisableVertexAttribArray(sem);
glVertexAttribPointer(sem, 1, GL_FLOAT, false, 0, 0);
}
- for(const uint16_t *a=inst_format.begin(); a!=inst_format.end(); ++a)
+ for(VertexAttribute a: inst_format)
{
- unsigned sem = get_attribute_semantic(*a);
+ unsigned sem = get_attribute_semantic(a);
glDisableVertexAttribArray(sem);
glVertexAttribPointer(sem, 1, GL_FLOAT, false, 0, 0);
}
{
textures.reserve(f.size());
unsigned samples = f.get_samples();
- for(const uint16_t *i=f.begin(); i!=f.end(); ++i)
+ for(FrameAttachment a: f)
{
- FrameAttachment fa = static_cast<FrameAttachment>(*i);
- PixelFormat pf = get_attachment_pixelformat(*i);
+ PixelFormat pf = get_attachment_pixelformat(a);
if(samples>1)
{
Texture2DMultisample *tex2d_ms = new Texture2DMultisample;
tex2d_ms->storage(pf, width, height, samples);
- fbo.attach(fa, *tex2d_ms);
+ fbo.attach(a, *tex2d_ms);
textures.push_back(tex2d_ms);
}
else
{
Texture2D *tex2d = new Texture2D;
tex2d->storage(pf, width, height, 1);
- fbo.attach(fa, *tex2d);
+ fbo.attach(a, *tex2d);
textures.push_back(tex2d);
}
}
{
#ifdef DEBUG
fbo.set_debug_name(name+" [FBO]");
- const FrameFormat &fmt = fbo.get_format();
unsigned i = 0;
- for(const uint16_t *j=fmt.begin(); j!=fmt.end(); ++i, ++j)
+ for(FrameAttachment a: fbo.get_format())
{
- unsigned attach_pt = get_attach_point(static_cast<FrameAttachment>(*j));
+ unsigned attach_pt = get_attach_point(a);
string tex_name;
if(attach_pt==get_attach_point(DEPTH_ATTACHMENT))
else
tex_name = Msp::format("%s/color%d", name, attach_pt);
- textures[i]->set_debug_name(tex_name+".tex2d");
+ textures[i++]->set_debug_name(tex_name+".tex2d");
}
#else
(void)name;