Skip to content

Commit

Permalink
Fix initializers with context instance
Browse files Browse the repository at this point in the history
Crystal compiler must have changed how mixins with initialize are handled.
  • Loading branch information
icy-arctic-fox committed Jul 3, 2022
1 parent ad3cef4 commit 51a7053
Show file tree
Hide file tree
Showing 27 changed files with 79 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/gloop/attribute.cr
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ module Gloop
@[GLFunction("glGetVertexAttribiv", enum: "GL_VERTEX_ATTRIB_ARRAY_RELATIVE_OFFSET", version: "4.3")]
attribute_parameter VertexAttribRelativeOffset, relative_offset : UInt32

# Context associated with the attribute reference.
private getter context : Context

# Index of the attribute.
getter index : UInt32

Expand Down
6 changes: 2 additions & 4 deletions src/gloop/attributes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module Gloop
include Indexable(Attribute)
include Parameters

def_context_initializer

# Retrieves the maximum number of attributes a vertex array can have.
#
# - OpenGL function: `glGetIntegerv`
Expand All @@ -22,10 +24,6 @@ module Gloop
@[GLFunction("glGetIntegerv", enum: "GL_MAX_VERTEX_ATTRIBS", version: "3.0")]
parameter MaxVertexAttribs, size

# Creates a references to the attributes for the bound vertex array.
def initialize(@context : Context)
end

# Retrieves an attribute from the vertex array.
def unsafe_fetch(index : Int)
Attribute.new(@context, index.to_u32!)
Expand Down
2 changes: 1 addition & 1 deletion src/gloop/buffer/bind_target.cr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module Gloop
@[GLFunction("glGetNamedBufferParameteriv", enum: "GL_BUFFER_USAGE", version: "2.0")]
buffer_target_parameter BufferUsage, usage : Usage

# Retrieves the context for this target.
# Context for this target.
getter context : Context

# Target this binding refers to.
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/buffer/map.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ module Gloop
@[GLFunction("glGetNamedBufferParameteriv", enum: "GL_BUFFER_ACCESS_FLAGS", version: "4.5")]
buffer_parameter BufferAccessFlags, access_mask : AccessMask

# Context associated with the buffer mapping.
private getter context : Context

# Name of the buffer.
private getter name : Name

Expand Down
3 changes: 3 additions & 0 deletions src/gloop/buffer/target_map.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ module Gloop
@[GLFunction("glGetBufferParameteriv", enum: "GL_BUFFER_ACCESS_FLAGS", version: "2.0")]
buffer_target_parameter BufferAccessFlags, access_mask : AccessMask

# Context associated with the mapping.
private getter context : Context

# Buffer binding target.
private getter target : Target

Expand Down
2 changes: 2 additions & 0 deletions src/gloop/buffers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Gloop
struct Buffers
include Contextual

def_context_initializer

# Defines a method that returns a buffer binding target for the specified target.
#
# The *target* should be a symbol that refers to an enum value in `Buffer::Target`.
Expand Down
6 changes: 4 additions & 2 deletions src/gloop/capability.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ module Gloop
end
end

# Context associated with the attribute reference.
private getter context : Context

# Creates a reference to an OpenGL capability for a context.
def initialize(context : Context, @value : Enum)
initialize(context)
def initialize(@context : Context, @value : Enum)
end

# Enables this capability.
Expand Down
20 changes: 16 additions & 4 deletions src/gloop/contextual.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module Gloop
# This module defines an initializer that takes a `Context`.
# It exposes a private `#gl` method for calling OpenGL function in the context.
module Contextual
# Creates the instance for the given OpenGL context.
def initialize(@context : Context)
end
# Context associated with the object.
private abstract def context : Context

# Proxies OpenGL function calls to the context.
#
# See: `Context#gl`.
@[AlwaysInline]
private def gl
@context.gl
context.gl
end

# Defines getters and setters for a value associated with the context.
Expand Down Expand Up @@ -51,5 +51,17 @@ module Gloop
@@%mutex.synchronize { @@%storage[@context] = value }
end
end

# Defines an initializer method and getter that accepts a context.
#
# Additionally, this method defines a getter to retrieve the context.
# This implements the abstract `context` method from this module.
private macro def_context_initializer
private getter context : ::Gloop::Context

# Creates a resource associated with a context.
def initialize(@context : ::Gloop::Context)
end
end
end
end
2 changes: 2 additions & 0 deletions src/gloop/debug.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Gloop
self_capability DebugOutput, version: "4.3"
capability DebugOutputSynchronous, sync, version: "4.3"

def_context_initializer

# Sends a debug message to OpenGL's debug message queue.
#
# See: `Message#insert`
Expand Down
2 changes: 2 additions & 0 deletions src/gloop/debug/message_iterator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Gloop
include Iterator(Message)
include Parameters

def_context_initializer

# Retrieves the size of the next logged message in bytes.
#
# Returns nil if the message log is empty.
Expand Down
2 changes: 2 additions & 0 deletions src/gloop/extension_list.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Gloop
include Indexable(Extension)
include Parameters

def_context_initializer

# Retrieves the number of extensions.
#
# - OpenGL function: `glGetIntegerv`
Expand Down
2 changes: 1 addition & 1 deletion src/gloop/object.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Gloop
@name.zero?
end

# Retrieves the context for this instance.
# Context the object belongs to.
getter context : Context

# Unique identifier of this object.
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/object_list.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Gloop
include Contextual
include Indexable(T)

# Context associated with the objects.
private getter context : Context

# Creates a list of objects from the same context with their names.
def initialize(@context : Context, @names : Slice(Object::Name))
end
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/program/uniform_location.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module Gloop
# :nodoc:
alias Float64ValueBuffer = StaticArray(Float64, 16)

# Context associated with the uniform.
private getter context : Context

# Location of the uniform.
getter location : Int32

Expand Down
3 changes: 3 additions & 0 deletions src/gloop/program/uniforms.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module Gloop
(value - 1) unless value.zero?
end

# Context associated with the uniforms.
private getter context : Context

# Name of the program the uniforms are from.
private getter name

Expand Down
2 changes: 2 additions & 0 deletions src/gloop/shading_language_version_list.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Gloop
include Indexable(String)
include Parameters

def_context_initializer

# Retrieves the number of supported GLSL versions.
#
# - OpenGL function: `glGetIntegerv`
Expand Down
2 changes: 1 addition & 1 deletion src/gloop/texture/bind_target.cr
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ module Gloop
gl.tex_parameter_i_uiv(to_unsafe, LibGL::TextureParameterName::TextureBorderColor, components.to_unsafe)
end

# Retrieves the context for this target.
# Context for this target.
getter context : Context

# Target this binding refers to.
Expand Down
2 changes: 2 additions & 0 deletions src/gloop/textures.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Gloop
include Contextual
include Parameters

def_context_initializer

# Defines a method that returns a texture binding target for the specified target.
#
# The *target* should be an enum value in `Texture::Target`.
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/uniform_location.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module Gloop
# Location of the uniform.
getter location : Int32

# Context associated with the uniform location.
private getter context : Context

# Creates a reference to an active uniform.
def initialize(@context : Context, @location : Int32)
end
Expand Down
2 changes: 2 additions & 0 deletions src/gloop/uniforms.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Gloop
struct Uniforms
include Contextual

def_context_initializer

# References a uniform in the current program by its location.
def [](location : Int32) : UniformLocation
UniformLocation.new(@context, location)
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/vertex_array/attribute.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ module Gloop
@[GLFunction("glGetVertexArrayIndexed64iv", enum: "GL_VERTEX_BINDING_OFFSET", version: "4.5")]
array_attribute_parameter LibGL::GetPName::VertexBindingOffset, offset : Int64

# Context associated with the attribute.
private getter context : Context

# Name of the vertex array.
private getter name : Name

Expand Down
3 changes: 3 additions & 0 deletions src/gloop/vertex_array/attributes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module Gloop
@[GLFunction("glGetIntegerv", enum: "GL_MAX_VERTEX_ATTRIBS", version: "3.0")]
parameter MaxVertexAttribs, size

# Context associated with the attributes.
private getter context : Context

# Creates a references to the attributes for a vertex array.
def initialize(@context : Context, @name : Name)
end
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/vertex_array/binding.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module Gloop
@[GLFunction("glGetVertexArrayIndexediv", enum: "GL_VERTEX_BINDING_DIVISOR", version: "4.5")]
array_attribute_parameter LibGL::GetPName::VertexBindingDivisor, divisor : UInt32

# Context associated with the binding.
private getter context : Context

# Name of the vertex array.
private getter name : Name

Expand Down
3 changes: 3 additions & 0 deletions src/gloop/vertex_array/bindings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module Gloop
@[GLFunction("glGetIntegerv", enum: "GL_MAX_VERTEX_ATTRIB_BINDINGS", version: "4.3")]
parameter MaxVertexAttribBindings, size

# Context associated with the binding slots.
private getter context : Context

# Creates a references to the binding slots.
def initialize(@context : Context, @name : Name)
end
Expand Down
6 changes: 2 additions & 4 deletions src/gloop/vertex_array/current.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module Gloop
include Contextual
include Parameters

def_context_initializer

# Retrieves the name of the currently bound vertex array.
#
# - OpenGL function: `glGetIntegerv`
Expand All @@ -22,10 +24,6 @@ module Gloop
@[GLFunction("glGetIntegerv", enum: "GL_VERTEX_ARRAY_BINDING", version: "3.0")]
protected parameter VertexArrayBinding, name : Name

# Creates a reference to the currently bound vertex array.
def initialize(@context : Context)
end

# Checks if there is a vertex array currently bound.
def bound?
!name.zero?
Expand Down
3 changes: 3 additions & 0 deletions src/gloop/vertex_array/current_binding.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module Gloop
@[GLFunction("glGetIntegeri_v", enum: "GL_VERTEX_BINDING_DIVISOR", version: "4.3")]
index_parameter VertexBindingDivisor, divisor : UInt32

# Context associated with the binding.
private getter context : Context

# Index of this binding slot.
getter index : UInt32

Expand Down
6 changes: 2 additions & 4 deletions src/gloop/vertex_array/current_bindings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Gloop
include Indexable(CurrentBinding)
include Parameters

def_context_initializer

# Retrieves the maximum number of attributes a vertex array can have.
#
# - OpenGL function: `glGetIntegerv`
Expand All @@ -23,10 +25,6 @@ module Gloop
@[GLFunction("glGetIntegerv", enum: "GL_MAX_VERTEX_ATTRIB_BINDINGS", version: "4.3")]
parameter MaxVertexAttribBindings, size

# Creates a references to the binding slots.
def initialize(@context : Context)
end

# Retrieves a binding slot from the vertex array.
def unsafe_fetch(index : Int)
CurrentBinding.new(@context, index.to_u32!)
Expand Down

0 comments on commit 51a7053

Please sign in to comment.