Module: Mittsu::OpenGLHelper
- Included in:
- SpritePlugin
- Defined in:
- lib/mittsu/renderers/opengl/opengl_helper.rb
Class Method Summary collapse
- .mark_uniforms_lights_needs_update(uniforms, value) ⇒ Object
- .painter_sort_stable(a, b) ⇒ Object
- .refresh_uniforms_lambert(uniforms, material) ⇒ Object
- .refresh_uniforms_lights(uniforms, lights) ⇒ Object
- .refresh_uniforms_shadow(uniforms, lights) ⇒ Object
- .reverse_painter_sort_stable(a, b) ⇒ Object
- .set_color_linear(array, offset, color, intensity) ⇒ Object
Instance Method Summary collapse
- #array_to_ptr(data, size, format) ⇒ Object
- #array_to_ptr_easy(data) ⇒ Object
- #glBufferData_easy(target, data, usage) ⇒ Object
- #glCreateBuffer ⇒ Object
- #glCreateFramebuffer ⇒ Object
- #glCreateRenderbuffer ⇒ Object
- #glCreateTexture ⇒ Object
- #glCreateVertexArray ⇒ Object
- #glGetParameter(pname) ⇒ Object
Class Method Details
.mark_uniforms_lights_needs_update(uniforms, value) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 65 def mark_uniforms_lights_needs_update(uniforms, value) uniforms['ambientLightColor'].needs_update = value uniforms['directionalLightColor'].needs_update = value uniforms['directionalLightDirection'].needs_update = value uniforms['pointLightColor'].needs_update = value uniforms['pointLightPosition'].needs_update = value uniforms['pointLightDistance'].needs_update = value uniforms['pointLightDecay'].needs_update = value uniforms['spotLightColor'].needs_update = value uniforms['spotLightPosition'].needs_update = value uniforms['spotLightDistance'].needs_update = value uniforms['spotLightDirection'].needs_update = value uniforms['spotLightAngleCos'].needs_update = value uniforms['spotLightExponent'].needs_update = value uniforms['spotLightDecay'].needs_update = value uniforms['hemisphereLightSkyColor'].needs_update = value uniforms['hemisphereLightGroundColor'].needs_update = value uniforms['hemisphereLightDirection'].needs_update = value end |
.painter_sort_stable(a, b) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 138 def painter_sort_stable(a, b) if a.object.render_order != b.object.render_order a.object.render_order <=> b.object.render_order elsif a.material.id != b.material.id a.material.id <=> b.material.id elsif a.z != b.z a.z <=> b.z else a.object.id <=> b.object.id end end |
.refresh_uniforms_lambert(uniforms, material) ⇒ Object
129 130 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 129 def refresh_uniforms_lambert(uniforms, material) end |
.refresh_uniforms_lights(uniforms, lights) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 105 def refresh_uniforms_lights(uniforms, lights) uniforms['ambientLightColor'].value = lights[:ambient].value uniforms['directionalLightColor'].value = lights[:directional].colors uniforms['directionalLightDirection'].value = lights[:directional].positions uniforms['pointLightColor'].value = lights[:point].colors uniforms['pointLightPosition'].value = lights[:point].positions uniforms['pointLightDistance'].value = lights[:point].distances uniforms['pointLightDecay'].value = lights[:point].decays uniforms['spotLightColor'].value = lights[:spot].colors uniforms['spotLightPosition'].value = lights[:spot].positions uniforms['spotLightDistance'].value = lights[:spot].distances uniforms['spotLightDirection'].value = lights[:spot].directions uniforms['spotLightAngleCos'].value = lights[:spot].angles_cos uniforms['spotLightExponent'].value = lights[:spot].exponents uniforms['spotLightDecay'].value = lights[:spot].decays uniforms['hemisphereLightSkyColor'].value = lights[:hemi].sky_colors uniforms['hemisphereLightGroundColor'].value = lights[:hemi].ground_colors uniforms['hemisphereLightDirection'].value = lights[:hemi].positions end |
.refresh_uniforms_shadow(uniforms, lights) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 89 def refresh_uniforms_shadow(uniforms, lights) if uniforms['shadowMatrix'] lights.select(&:cast_shadow).select { |light| light.is_a?(SpotLight) || (light.is_a?(DirectionalLight) && !light.shadow_cascade) }.each_with_index { |light, i| uniforms['shadowMap'].value[i] = light.shadow_map uniforms['shadowMapSize'].value[i] = light.shadow_map_size uniforms['shadowMatrix'].value[i] = light.shadow_matrix uniforms['shadowDarkness'].value[i] = light.shadow_darkness uniforms['shadowBias'].value[i] = light.shadow_bias } end end |
.reverse_painter_sort_stable(a, b) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 150 def reverse_painter_sort_stable(a, b) if a.object.render_order != b.object.render_order a.object.render_order <=> b.object.render_order elsif a.z != b.z b.z <=> a.z else b.id <=> a.id end end |
.set_color_linear(array, offset, color, intensity) ⇒ Object
132 133 134 135 136 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 132 def set_color_linear(array, offset, color, intensity) array[offset] = color.r * intensity array[offset + 1] = color.g * intensity array[offset + 2] = color.b * intensity end |
Instance Method Details
#array_to_ptr(data, size, format) ⇒ Object
47 48 49 50 51 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 47 def array_to_ptr(data, size, format) ptr = Fiddle::Pointer.malloc(size) ptr[0,size] = data.pack(format * data.length) ptr end |
#array_to_ptr_easy(data) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 33 def array_to_ptr_easy(data) if data.first.is_a?(Float) size_of_element = Fiddle::SIZEOF_FLOAT format_of_element = 'F' # data.map!{ |d| d.nil? ? 0.0 : d } else size_of_element = Fiddle::SIZEOF_INT format_of_element = 'L' # data.map!{ |d| d.nil? ? 0 : d } end size = data.length * size_of_element array_to_ptr(data, size, format_of_element) end |
#glBufferData_easy(target, data, usage) ⇒ Object
53 54 55 56 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 53 def glBufferData_easy(target, data, usage) ptr = array_to_ptr_easy(data) glBufferData(target, ptr.size, ptr, usage) end |
#glCreateBuffer ⇒ Object
3 4 5 6 7 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 3 def glCreateBuffer @_b ||= ' '*8 glGenBuffers(1, @_b) @_b.unpack('L')[0] end |
#glCreateFramebuffer ⇒ Object
21 22 23 24 25 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 21 def glCreateFramebuffer @_b ||= ' '*8 glGenFramebuffers(1, @_b) @_b.unpack('L')[0] end |
#glCreateRenderbuffer ⇒ Object
27 28 29 30 31 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 27 def glCreateRenderbuffer @_b ||= ' '*8 glGenRenderbuffers(1, @_b) @_b.unpack('L')[0] end |
#glCreateTexture ⇒ Object
9 10 11 12 13 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 9 def glCreateTexture @_b ||= ' '*8 glGenTextures(1, @_b) @_b.unpack('L')[0] end |
#glCreateVertexArray ⇒ Object
15 16 17 18 19 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 15 def glCreateVertexArray @_b ||= ' '*8 glGenVertexArrays(1, @_b) @_b.unpack('L')[0] end |
#glGetParameter(pname) ⇒ Object
58 59 60 61 62 |
# File 'lib/mittsu/renderers/opengl/opengl_helper.rb', line 58 def glGetParameter(pname) @_b ||= ' '*8 glGetIntegerv(pname, @_b) @_b.unpack('L')[0] end |