void OpenGLFramebuffer::resize_system(unsigned w, unsigned h)
{
- Framebuffer *self = static_cast<Framebuffer *>(this);
- self->width = w;
- self->height = h;
+ Framebuffer &self = *static_cast<Framebuffer *>(this);
+ self.width = w;
+ self.height = h;
}
void OpenGLFramebuffer::update(unsigned mask) const
{
- const FrameFormat &format = static_cast<const Framebuffer *>(this)->format;
+ const Framebuffer &self = *static_cast<const Framebuffer *>(this);
+
vector<GLenum> color_bufs;
- color_bufs.reserve(format.size());
+ color_bufs.reserve(self.format.size());
unsigned i = 0;
- for(FrameAttachment a: format)
+ for(FrameAttachment a: self.format)
{
GLenum gl_attach_point = get_gl_attachment(a);
if(mask&(1<<i))
{
- const Framebuffer::Attachment &attch = static_cast<const Framebuffer *>(this)->attachments[i];
+ const Framebuffer::Attachment &attch = self.attachments[i];
if(attch.tex)
{
if(ARB_direct_state_access)
void OpenGLPipelineState::apply(unsigned mask) const
{
- const PipelineState *self = static_cast<const PipelineState *>(this);
+ const PipelineState &self = *static_cast<const PipelineState *>(this);
if(mask&PipelineState::FRAMEBUFFER)
{
- const Framebuffer *framebuffer = self->framebuffer;
+ const Framebuffer *framebuffer = self.framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer ? framebuffer->id : 0);
if(framebuffer)
{
if(mask&(PipelineState::VIEWPORT|PipelineState::FRAMEBUFFER))
{
- if(const Rect *viewport = self->viewport)
+ if(const Rect *viewport = self.viewport)
glViewport(viewport->left, viewport->bottom, viewport->width, viewport->height);
- else if(const Framebuffer *framebuffer = self->framebuffer)
+ else if(const Framebuffer *framebuffer = self.framebuffer)
glViewport(0, 0, framebuffer->get_width(), framebuffer->get_height());
}
if(mask&PipelineState::SCISSOR)
{
- if(const Rect *scissor = self->scissor)
+ if(const Rect *scissor = self.scissor)
{
glEnable(GL_SCISSOR_TEST);
glScissor(scissor->left, scissor->bottom, scissor->width, scissor->height);
if(mask&PipelineState::SHPROG)
{
- glUseProgram(self->shprog ? self->shprog->id : 0);
+ glUseProgram(self.shprog ? self.shprog->id : 0);
- unsigned ncd = (self->shprog ? self->shprog->get_n_clip_distances() : 0);
+ unsigned ncd = (self.shprog ? self.shprog->get_n_clip_distances() : 0);
if(ncd!=n_clip_distances)
{
for(unsigned i=0; (i<ncd || i<n_clip_distances); ++i)
if(mask&PipelineState::UNIFORMS)
{
- for(const PipelineState::BoundUniformBlock &u: self->uniform_blocks)
+ for(const PipelineState::BoundUniformBlock &u: self.uniform_blocks)
if(u.changed || mask==~0U)
{
if(u.block)
glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, u.block->get_buffer()->id, u.block->get_offset(), u.block->get_data_size());
bound_uniform_blocks[u.binding] = 1;
}
- else if(self->shprog)
+ else if(self.shprog)
{
const char *data = static_cast<const char *>(u.block->get_data_pointer());
- for(const Program::UniformCall &call: self->shprog->uniform_calls)
+ for(const Program::UniformCall &call: self.shprog->uniform_calls)
call.func(call.location, call.size, data+call.location*16);
}
}
if(mask&PipelineState::TEXTURES)
{
- for(const PipelineState::BoundTexture &t: self->textures)
+ for(const PipelineState::BoundTexture &t: self.textures)
if(t.changed || mask==~0U)
{
if(t.texture && t.sampler)
if(mask&PipelineState::VERTEX_SETUP)
{
- const VertexSetup *vertex_setup = self->vertex_setup;
+ const VertexSetup *vertex_setup = self.vertex_setup;
glBindVertexArray(vertex_setup ? vertex_setup->id : 0);
if(vertex_setup)
{
if(mask&PipelineState::FACE_CULL)
{
- glFrontFace(self->front_face==CLOCKWISE ? GL_CW : GL_CCW);
+ glFrontFace(self.front_face==CLOCKWISE ? GL_CW : GL_CCW);
- if(self->face_cull!=NO_CULL && self->front_face!=NON_MANIFOLD)
+ if(self.face_cull!=NO_CULL && self.front_face!=NON_MANIFOLD)
{
glEnable(GL_CULL_FACE);
- glCullFace(self->face_cull==CULL_FRONT ? GL_FRONT : GL_BACK);
+ glCullFace(self.face_cull==CULL_FRONT ? GL_FRONT : GL_BACK);
}
else
glDisable(GL_CULL_FACE);
if(mask&PipelineState::DEPTH_TEST)
{
- const DepthTest *depth_test = self->depth_test;
+ const DepthTest *depth_test = self.depth_test;
if(depth_test && depth_test->enabled)
{
glEnable(GL_DEPTH_TEST);
if(mask&PipelineState::STENCIL_TEST)
{
- const StencilTest *stencil_test = self->stencil_test;
+ const StencilTest *stencil_test = self.stencil_test;
if(stencil_test && stencil_test->enabled)
{
glEnable(GL_STENCIL_TEST);
if(mask&PipelineState::BLEND)
{
- const Blend *blend = self->blend;
+ const Blend *blend = self.blend;
if(blend && blend->enabled)
{
glEnable(GL_BLEND);
}
last_applied = this;
- self->changes &= ~mask;
+ self.changes &= ~mask;
}
void OpenGLPipelineState::clear()
void OpenGLSampler::update(unsigned mask) const
{
- const Sampler *self = static_cast<const Sampler *>(this);
+ const Sampler &self = *static_cast<const Sampler *>(this);
if(mask&Sampler::MIN_FILTER)
- glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, get_gl_filter(self->min_filter));
+ glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, get_gl_filter(self.min_filter));
if(mask&Sampler::MAG_FILTER)
- glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, get_gl_filter(self->mag_filter));
+ glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, get_gl_filter(self.mag_filter));
if(mask&Sampler::MAX_ANISOTROPY)
- glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, self->max_anisotropy);
+ glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, self.max_anisotropy);
if(mask&Sampler::WRAP_S)
- glSamplerParameteri(id, GL_TEXTURE_WRAP_S, get_gl_wrap(self->wrap_s));
+ glSamplerParameteri(id, GL_TEXTURE_WRAP_S, get_gl_wrap(self.wrap_s));
if(mask&Sampler::WRAP_T)
- glSamplerParameteri(id, GL_TEXTURE_WRAP_T, get_gl_wrap(self->wrap_t));
+ glSamplerParameteri(id, GL_TEXTURE_WRAP_T, get_gl_wrap(self.wrap_t));
if(mask&Sampler::WRAP_R)
- glSamplerParameteri(id, GL_TEXTURE_WRAP_R, get_gl_wrap(self->wrap_r));
+ glSamplerParameteri(id, GL_TEXTURE_WRAP_R, get_gl_wrap(self.wrap_r));
if(mask&Sampler::BORDER_COLOR)
- glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, &self->border_color.r);
+ glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, &self.border_color.r);
if(mask&Sampler::COMPARE)
{
- glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, (self->compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
- if(self->compare)
- glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, get_gl_predicate(self->cmp_func));
+ glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, (self.compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
+ if(self.compare)
+ glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, get_gl_predicate(self.cmp_func));
}
}
void OpenGLTexture1D::allocate()
{
- unsigned width = static_cast<const Texture1D *>(this)->width;
- unsigned levels = static_cast<const Texture1D *>(this)->levels;
+ const Texture1D &self = *static_cast<const Texture1D *>(this);
if(!id)
create();
if(ARB_texture_storage)
{
if(ARB_direct_state_access)
- glTextureStorage1D(id, levels, gl_fmt, width);
+ glTextureStorage1D(id, self.levels, gl_fmt, self.width);
else
{
bind_scratch();
- glTexStorage1D(target, levels, gl_fmt, width);
+ glTexStorage1D(target, self.levels, gl_fmt, self.width);
}
}
else
{
bind_scratch();
- glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.levels-1);
GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
- for(unsigned i=0; i<levels; ++i)
+ for(unsigned i=0; i<self.levels; ++i)
{
- unsigned lv_size = static_cast<const Texture1D *>(this)->get_level_size(i);
+ unsigned lv_size = self.get_level_size(i);
glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0);
}
}
if(!id)
return 0;
- unsigned width = static_cast<const Texture1D *>(this)->width;
- unsigned levels = static_cast<const Texture1D *>(this)->levels;
+ const Texture1D &self = *static_cast<const Texture1D *>(this);
- size_t level_size = width*get_pixel_size(storage_fmt);
+ size_t level_size = self.width*get_pixel_size(storage_fmt);
size_t total_size = level_size;
- for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
total_size += level_size;
return total_size;
}
void OpenGLTexture2D::allocate()
{
- unsigned width = static_cast<const Texture2D *>(this)->width;
- unsigned height = static_cast<const Texture2D *>(this)->height;
- unsigned levels = static_cast<const Texture2D *>(this)->levels;
+ const Texture2D &self = *static_cast<const Texture2D *>(this);
if(!id)
create();
if(ARB_texture_storage)
{
if(ARB_direct_state_access)
- glTextureStorage2D(id, levels, gl_fmt, width, height);
+ glTextureStorage2D(id, self.levels, gl_fmt, self.width, self.height);
else
{
bind_scratch();
- glTexStorage2D(target, levels, gl_fmt, width, height);
+ glTexStorage2D(target, self.levels, gl_fmt, self.width, self.height);
}
}
else
{
bind_scratch();
- glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.levels-1);
GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
- for(unsigned i=0; i<levels; ++i)
+ for(unsigned i=0; i<self.levels; ++i)
{
- auto lv_size = static_cast<const Texture2D *>(this)->get_level_size(i);
+ auto lv_size = self.get_level_size(i);
glTexImage2D(target, i, gl_fmt, lv_size.x, lv_size.y, 0, comp, type, 0);
}
}
if(!id)
return 0;
- unsigned width = static_cast<const Texture2D *>(this)->width;
- unsigned height = static_cast<const Texture2D *>(this)->height;
- unsigned levels = static_cast<const Texture2D *>(this)->levels;
+ const Texture2D &self = *static_cast<const Texture2D *>(this);
- size_t level_size = width*height*get_pixel_size(format);
+ size_t level_size = self.width*self.height*get_pixel_size(format);
size_t total_size = level_size;
- for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
total_size += level_size;
return total_size;
}
void OpenGLTexture2DMultisample::allocate()
{
- unsigned width = static_cast<const Texture2DMultisample *>(this)->width;
- unsigned height = static_cast<const Texture2DMultisample *>(this)->height;
- unsigned samples = static_cast<const Texture2DMultisample *>(this)->samples;
+ const Texture2DMultisample &self = *static_cast<const Texture2DMultisample *>(this);
if(!id)
create();
if(ARB_texture_storage_multisample)
{
if(ARB_direct_state_access)
- glTextureStorage2DMultisample(id, samples, gl_fmt, width, height, false);
+ glTextureStorage2DMultisample(id, self.samples, gl_fmt, self.width, self.height, false);
else
{
bind_scratch();
- glTexStorage2DMultisample(target, samples, gl_fmt, width, height, false);
+ glTexStorage2DMultisample(target, self.samples, gl_fmt, self.width, self.height, false);
}
}
else
{
bind_scratch();
- glTexImage2DMultisample(target, samples, gl_fmt, width, height, false);
+ glTexImage2DMultisample(target, self.samples, gl_fmt, self.width, self.height, false);
}
apply_swizzle();
}
size_t OpenGLTexture2DMultisample::get_data_size() const
{
- unsigned width = static_cast<const Texture2DMultisample *>(this)->width;
- unsigned height = static_cast<const Texture2DMultisample *>(this)->height;
- unsigned samples = static_cast<const Texture2DMultisample *>(this)->samples;
- return width*height*get_pixel_size(format)*samples;
+ const Texture2DMultisample &self = *static_cast<const Texture2DMultisample *>(this);
+ return self.width*self.height*get_pixel_size(format)*self.samples;
}
} // namespace GL
void OpenGLTexture3D::allocate()
{
- unsigned width = static_cast<const Texture3D *>(this)->width;
- unsigned height = static_cast<const Texture3D *>(this)->height;
- unsigned depth = static_cast<const Texture3D *>(this)->depth;
- unsigned levels = static_cast<const Texture3D *>(this)->levels;
+ const Texture3D &self = *static_cast<const Texture3D *>(this);
if(!id)
create();
if(ARB_texture_storage)
{
if(ARB_direct_state_access)
- glTextureStorage3D(id, levels, gl_fmt, width, height, depth);
+ glTextureStorage3D(id, self.levels, gl_fmt, self.width, self.height, self.depth);
else
{
bind_scratch();
- glTexStorage3D(target, levels, gl_fmt, width, height, depth);
+ glTexStorage3D(target, self.levels, gl_fmt, self.width, self.height, self.depth);
}
}
else
bind_scratch();
GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
- for(unsigned i=0; i<levels; ++i)
+ for(unsigned i=0; i<self.levels; ++i)
{
- auto lv_size = static_cast<const Texture3D *>(this)->get_level_size(i);
+ auto lv_size = self.get_level_size(i);
glTexImage3D(target, i, gl_fmt, lv_size.x, lv_size.y, lv_size.z, 0, comp, type, 0);
}
- glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.levels-1);
}
apply_swizzle();
if(!id)
return 0;
- unsigned width = static_cast<const Texture3D *>(this)->width;
- unsigned height = static_cast<const Texture3D *>(this)->height;
- unsigned depth = static_cast<const Texture3D *>(this)->depth;
- unsigned levels = static_cast<const Texture3D *>(this)->levels;
+ const Texture3D &self = *static_cast<const Texture3D *>(this);
- size_t level_size = width*height*depth*get_pixel_size(format);
+ size_t level_size = self.width*self.height*self.depth*get_pixel_size(format);
size_t total_size = level_size;
- for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
total_size += level_size;
return total_size;
}
void OpenGLTextureCube::allocate()
{
- unsigned size = static_cast<const TextureCube *>(this)->size;
- unsigned levels = static_cast<const TextureCube *>(this)->levels;
+ const TextureCube &self = *static_cast<const TextureCube *>(this);
if(!id)
create();
if(ARB_texture_storage)
{
if(ARB_direct_state_access)
- glTextureStorage2D(id, levels, gl_fmt, size, size);
+ glTextureStorage2D(id, self.levels, gl_fmt, self.size, self.size);
else
{
bind_scratch();
- glTexStorage2D(target, levels, gl_fmt, size, size);
+ glTexStorage2D(target, self.levels, gl_fmt, self.size, self.size);
}
}
else
bind_scratch();
GLenum comp = get_gl_components(get_components(storage_fmt));
GLenum type = get_gl_type(get_component_type(storage_fmt));
- for(unsigned i=0; i<levels; ++i)
+ for(unsigned i=0; i<self.levels; ++i)
{
unsigned lv_size = static_cast<const TextureCube *>(this)->get_level_size(i);
for(unsigned j=0; j<6; ++j)
glTexImage2D(get_gl_cube_face(j), i, gl_fmt, lv_size, lv_size, 0, comp, type, 0);
}
- glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.levels-1);
}
apply_swizzle();
if(!id)
return 0;
- unsigned size = static_cast<const TextureCube *>(this)->size;
- unsigned levels = static_cast<const TextureCube *>(this)->levels;
+ const TextureCube &self = *static_cast<const TextureCube *>(this);
- size_t level_size = size*size*get_pixel_size(storage_fmt);
+ size_t level_size = self.size*self.size*get_pixel_size(storage_fmt);
size_t total_size = level_size;
- for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
total_size += level_size;
return total_size;
}
{
static bool direct = ARB_direct_state_access && ARB_vertex_attrib_binding;
+ const VertexSetup &self = *static_cast<const VertexSetup *>(this);
+
if(mask&VertexSetup::VERTEX_ARRAY)
- update_vertex_array(*static_cast<const VertexSetup *>(this)->vertex_array, 0, 0, direct);
+ update_vertex_array(*self.vertex_array, 0, 0, direct);
if(mask&VertexSetup::INSTANCE_ARRAY)
- update_vertex_array(*static_cast<const VertexSetup *>(this)->inst_array, 1, 1, direct);
+ update_vertex_array(*self.inst_array, 1, 1, direct);
if(mask&VertexSetup::INDEX_BUFFER)
{
- unsigned buf_id = static_cast<const VertexSetup *>(this)->index_buffer->id;
+ unsigned buf_id = self.index_buffer->id;
if(direct)
glVertexArrayElementBuffer(id, buf_id);
else
}
else
{
+ const VertexSetup &self = *static_cast<const VertexSetup *>(this);
+
glBindVertexArray(id);
glBindBuffer(GL_ARRAY_BUFFER, 0);
- for(VertexAttribute a: static_cast<const VertexSetup *>(this)->vertex_format)
+ for(VertexAttribute a: self.vertex_format)
if(!is_padding(a))
{
unsigned sem = get_attribute_semantic(a);
glDisableVertexAttribArray(sem);
glVertexAttribPointer(sem, 1, GL_FLOAT, false, 0, 0);
}
- for(VertexAttribute a: static_cast<const VertexSetup *>(this)->inst_format)
+ for(VertexAttribute a: self.inst_format)
if(!is_padding(a))
{
unsigned sem = get_attribute_semantic(a);