class Roglew::Texture2dContext

TODO refactor this to only exist by using RenderContext#create_texture2d

Attributes

level[RW]

Public Class Methods

new(texture, deferred, target, level, &block) click to toggle source
Calls superclass method
# File lib/roglew/texture2d_context.rb, line 10
def initialize(texture, deferred, target, level, &block)
  @target, @level = target, level

  load_version_modules texture.handle.version
  load_extensions texture.handle.loaded_extensions

  super(texture, deferred, &block)
end

Public Instance Methods

border_color(r, g, b, a) click to toggle source
# File lib/roglew/texture2d_context.rb, line 31
def border_color(r, g, b, a) parameter(GL::TEXTURE_BORDER_COLOR, r, g, b, a) end
generate_mipmapEXT() click to toggle source
# File lib/roglew/extensions/GL_EXT_framebuffer_object.rb, line 60
def generate_mipmapEXT
  glGenerateMipmapEXT(@target)
end
mag_filter=(v) click to toggle source
# File lib/roglew/texture2d_context.rb, line 32
def mag_filter=(v) parameter(GL::TEXTURE_MAG_FILTER, v) end
min_filter=(v) click to toggle source
# File lib/roglew/texture2d_context.rb, line 33
def min_filter=(v) parameter(GL::TEXTURE_MIN_FILTER, v) end
parameter(pname, *values) click to toggle source
# File lib/roglew/texture2d_context.rb, line 19
def parameter(pname, *values)
  tex_parameter(@target, pname, *values)
end
tex_image_2d(width, height, internalFormat, format, type, data = nil) click to toggle source
# File lib/roglew/texture2d_context.rb, line 23
def tex_image_2d(width, height, internalFormat, format, type, data = nil)
  glTexImage2D(@target, @level, internalFormat, width, height, 0, format, type, data)
end
tex_subimage_2d(x, y, width, height, format, type, data = nil) click to toggle source
# File lib/roglew/texture2d_context.rb, line 27
def tex_subimage_2d(x, y, width, height, format, type, data = nil)
  glTexSubImage2D(@target, @level, x, y, width, height, format, type, data)
end
wrap_s=(v) click to toggle source
# File lib/roglew/texture2d_context.rb, line 34
def wrap_s=(v) parameter(GL::TEXTURE_WRAP_S, v) end
wrap_t=(v) click to toggle source
# File lib/roglew/texture2d_context.rb, line 35
def wrap_t=(v) parameter(GL::TEXTURE_WRAP_T, v) end

Private Instance Methods

bind() click to toggle source
# File lib/roglew/texture2d_context.rb, line 87
def bind
  handle.glBindTexture(@target, texture.id)
end
check_current() click to toggle source
# File lib/roglew/texture2d_context.rb, line 91
def check_current
  raise RenderContextError unless handle.current?
end
load_extensions(extensions) click to toggle source
# File lib/roglew/texture2d_context.rb, line 95
def load_extensions(extensions)
  c = singleton_class
  extensions.each do |ext|
    next unless Object.const_defined?(ext)
    mod = Object.const_get(ext)
    next unless mod.const_defined?(:Texture2dContext)
    c.send(:include, mod.const_get(:Texture2dContext))
  end
end
load_version_modules(version) click to toggle source
# File lib/roglew/texture2d_context.rb, line 105
def load_version_modules(version)
  version = version[0] * 10 + version[1]
  [
    version >= 11 && version <= 30, #1
    version >= 12,                  #2
    version >= 14 && version <= 30, #3
    version >= 14,                  #4
    version >= 33,                  #5
    version >= 43                   #6
  ].each_with_index
    .select { |cond, _| cond }
    .map { |_, index| self.class.const_get("Parameters#{index+1}") }
    .each { |mod| singleton_class.send(:include, mod) }
end
unbind() click to toggle source
# File lib/roglew/texture2d_context.rb, line 120
def unbind
  handle.glBindTexture(@target, 0)
end