opengl 0.9.0-x64-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - checksums.yaml.gz.sig +3 -0
 - data.tar.gz.sig +0 -0
 - data/.autotest +29 -0
 - data/.gemtest +0 -0
 - data/.gitignore +6 -0
 - data/.travis.yml +19 -0
 - data/History.rdoc +77 -0
 - data/MIT-LICENSE +18 -0
 - data/Manifest.txt +138 -0
 - data/README.rdoc +102 -0
 - data/Rakefile +60 -0
 - data/examples/NeHe/NeHe.png +0 -0
 - data/examples/NeHe/crate.png +0 -0
 - data/examples/NeHe/glass.png +0 -0
 - data/examples/NeHe/nehe_lesson02.rb +117 -0
 - data/examples/NeHe/nehe_lesson03.rb +123 -0
 - data/examples/NeHe/nehe_lesson04.rb +132 -0
 - data/examples/NeHe/nehe_lesson05.rb +182 -0
 - data/examples/NeHe/nehe_lesson06.rb +186 -0
 - data/examples/NeHe/nehe_lesson07.rb +240 -0
 - data/examples/NeHe/nehe_lesson08.rb +255 -0
 - data/examples/NeHe/nehe_lesson09.rb +203 -0
 - data/examples/NeHe/nehe_lesson11.rb +176 -0
 - data/examples/NeHe/nehe_lesson12.rb +203 -0
 - data/examples/NeHe/nehe_lesson16.rb +211 -0
 - data/examples/NeHe/nehe_lesson19.rb +209 -0
 - data/examples/NeHe/nehe_lesson36.rb +308 -0
 - data/examples/NeHe/particle.png +0 -0
 - data/examples/NeHe/star.png +0 -0
 - data/examples/NeHe/tim.png +0 -0
 - data/examples/OrangeBook/3Dlabs-License.txt +33 -0
 - data/examples/OrangeBook/brick.frag +36 -0
 - data/examples/OrangeBook/brick.rb +378 -0
 - data/examples/OrangeBook/brick.vert +41 -0
 - data/examples/OrangeBook/particle.frag +17 -0
 - data/examples/OrangeBook/particle.rb +408 -0
 - data/examples/OrangeBook/particle.vert +38 -0
 - data/examples/README +16 -0
 - data/examples/RedBook/aapoly.rb +143 -0
 - data/examples/RedBook/aargb.rb +121 -0
 - data/examples/RedBook/accanti.rb +164 -0
 - data/examples/RedBook/accpersp.rb +217 -0
 - data/examples/RedBook/alpha.rb +125 -0
 - data/examples/RedBook/alpha3D.rb +160 -0
 - data/examples/RedBook/bezcurve.rb +107 -0
 - data/examples/RedBook/bezmesh.rb +139 -0
 - data/examples/RedBook/checker.rb +126 -0
 - data/examples/RedBook/clip.rb +97 -0
 - data/examples/RedBook/colormat.rb +137 -0
 - data/examples/RedBook/cube.rb +71 -0
 - data/examples/RedBook/depthcue.rb +101 -0
 - data/examples/RedBook/dof.rb +206 -0
 - data/examples/RedBook/double.rb +107 -0
 - data/examples/RedBook/drawf.rb +93 -0
 - data/examples/RedBook/feedback.rb +147 -0
 - data/examples/RedBook/fog.rb +168 -0
 - data/examples/RedBook/font.rb +153 -0
 - data/examples/RedBook/hello.rb +81 -0
 - data/examples/RedBook/image.rb +139 -0
 - data/examples/RedBook/jitter.rb +207 -0
 - data/examples/RedBook/light.rb +155 -0
 - data/examples/RedBook/lines.rb +130 -0
 - data/examples/RedBook/list.rb +113 -0
 - data/examples/RedBook/material.rb +276 -0
 - data/examples/RedBook/mipmap.rb +158 -0
 - data/examples/RedBook/model.rb +115 -0
 - data/examples/RedBook/movelight.rb +134 -0
 - data/examples/RedBook/pickdepth.rb +181 -0
 - data/examples/RedBook/planet.rb +110 -0
 - data/examples/RedBook/quadric.rb +160 -0
 - data/examples/RedBook/robot.rb +117 -0
 - data/examples/RedBook/select.rb +198 -0
 - data/examples/RedBook/smooth.rb +97 -0
 - data/examples/RedBook/stencil.rb +165 -0
 - data/examples/RedBook/stroke.rb +169 -0
 - data/examples/RedBook/surface.rb +168 -0
 - data/examples/RedBook/teaambient.rb +134 -0
 - data/examples/RedBook/teapots.rb +184 -0
 - data/examples/RedBook/tess.rb +185 -0
 - data/examples/RedBook/texbind.rb +149 -0
 - data/examples/RedBook/texgen.rb +171 -0
 - data/examples/RedBook/texturesurf.rb +130 -0
 - data/examples/RedBook/varray.rb +161 -0
 - data/examples/RedBook/wrap.rb +150 -0
 - data/examples/misc/OGLBench.rb +338 -0
 - data/examples/misc/anisotropic.rb +196 -0
 - data/examples/misc/fbo_test.rb +357 -0
 - data/examples/misc/font-glut.rb +47 -0
 - data/examples/misc/glfwtest.rb +30 -0
 - data/examples/misc/plane.rb +161 -0
 - data/examples/misc/readpixel.rb +66 -0
 - data/examples/misc/sdltest.rb +36 -0
 - data/examples/misc/trislam.rb +829 -0
 - data/ext/opengl/common.h +428 -0
 - data/ext/opengl/conv.h +244 -0
 - data/ext/opengl/extconf.rb +47 -0
 - data/ext/opengl/funcdef.h +313 -0
 - data/ext/opengl/gl-1.0-1.1.c +3075 -0
 - data/ext/opengl/gl-1.2.c +155 -0
 - data/ext/opengl/gl-1.3.c +443 -0
 - data/ext/opengl/gl-1.4.c +348 -0
 - data/ext/opengl/gl-1.5.c +224 -0
 - data/ext/opengl/gl-2.0.c +667 -0
 - data/ext/opengl/gl-2.1.c +57 -0
 - data/ext/opengl/gl-3.0.c +493 -0
 - data/ext/opengl/gl-enums.c +4873 -0
 - data/ext/opengl/gl-enums.h +14588 -0
 - data/ext/opengl/gl-error.c +112 -0
 - data/ext/opengl/gl-error.h +28 -0
 - data/ext/opengl/gl-ext-3dfx.c +27 -0
 - data/ext/opengl/gl-ext-arb.c +875 -0
 - data/ext/opengl/gl-ext-ati.c +41 -0
 - data/ext/opengl/gl-ext-ext.c +889 -0
 - data/ext/opengl/gl-ext-gremedy.c +41 -0
 - data/ext/opengl/gl-ext-nv.c +680 -0
 - data/ext/opengl/gl-types.h +67 -0
 - data/ext/opengl/gl.c +220 -0
 - data/ext/opengl/gl_buffer.c +177 -0
 - data/ext/opengl/opengl.c +7 -0
 - data/lib/gl.rb +1 -0
 - data/lib/opengl.rb +53 -0
 - data/lib/opengl/2.0/opengl.so +0 -0
 - data/lib/opengl/2.1/opengl.so +0 -0
 - data/lib/opengl/test_case.rb +86 -0
 - data/test/dummy.xorg.conf +140 -0
 - data/test/test_gl.rb +38 -0
 - data/test/test_gl_10_11.rb +1363 -0
 - data/test/test_gl_12.rb +71 -0
 - data/test/test_gl_13.rb +221 -0
 - data/test/test_gl_14.rb +218 -0
 - data/test/test_gl_15.rb +258 -0
 - data/test/test_gl_20.rb +417 -0
 - data/test/test_gl_21.rb +436 -0
 - data/test/test_gl_ext_arb.rb +508 -0
 - data/test/test_gl_ext_ati.rb +28 -0
 - data/test/test_gl_ext_ext.rb +608 -0
 - data/test/test_gl_ext_gremedy.rb +29 -0
 - data/test/test_gl_ext_nv.rb +349 -0
 - data/test/test_opengl_buffer.rb +120 -0
 - data/utils/README +6 -0
 - data/utils/enumgen.rb +108 -0
 - data/utils/extlistgen.rb +90 -0
 - metadata +319 -0
 - metadata.gz.sig +1 -0
 
| 
         @@ -0,0 +1,67 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /*
         
     | 
| 
      
 2 
     | 
    
         
            +
             * Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
         
     | 
| 
      
 3 
     | 
    
         
            +
             *
         
     | 
| 
      
 4 
     | 
    
         
            +
             * This program is distributed under the terms of the MIT license.
         
     | 
| 
      
 5 
     | 
    
         
            +
             * See the included MIT-LICENSE file for the terms of this license.
         
     | 
| 
      
 6 
     | 
    
         
            +
             *
         
     | 
| 
      
 7 
     | 
    
         
            +
             * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
         
     | 
| 
      
 8 
     | 
    
         
            +
             * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 9 
     | 
    
         
            +
             * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         
     | 
| 
      
 10 
     | 
    
         
            +
             * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         
     | 
| 
      
 11 
     | 
    
         
            +
             * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         
     | 
| 
      
 12 
     | 
    
         
            +
             * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         
     | 
| 
      
 13 
     | 
    
         
            +
             * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
      
 14 
     | 
    
         
            +
             */
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            /* GL types - define if system GLheaders are not recent
         
     | 
| 
      
 17 
     | 
    
         
            +
               Note: must be included before gl-enums.h */
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            #if HAVE_STDINT_H
         
     | 
| 
      
 20 
     | 
    
         
            +
            #include <stdint.h>
         
     | 
| 
      
 21 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            #ifndef HAVE_TYPE_INT64_T
         
     | 
| 
      
 24 
     | 
    
         
            +
            typedef __int64 int64_t;
         
     | 
| 
      
 25 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 26 
     | 
    
         
            +
            #ifndef HAVE_TYPE_UINT64_T
         
     | 
| 
      
 27 
     | 
    
         
            +
            typedef unsigned __int64 uint64_t;
         
     | 
| 
      
 28 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            #if HAVE_INTTYPES_H
         
     | 
| 
      
 31 
     | 
    
         
            +
            #include <inttypes.h>
         
     | 
| 
      
 32 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            /* GL base */
         
     | 
| 
      
 35 
     | 
    
         
            +
            #ifndef GL_VERSION_1_5
         
     | 
| 
      
 36 
     | 
    
         
            +
            typedef ptrdiff_t GLintptr;
         
     | 
| 
      
 37 
     | 
    
         
            +
            typedef ptrdiff_t GLsizeiptr;
         
     | 
| 
      
 38 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            #ifndef GL_VERSION_2_0
         
     | 
| 
      
 41 
     | 
    
         
            +
            typedef char GLchar;
         
     | 
| 
      
 42 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            /* new GL types introduced by ARB extensions */
         
     | 
| 
      
 45 
     | 
    
         
            +
            #ifndef GL_ARB_half_float_pixel
         
     | 
| 
      
 46 
     | 
    
         
            +
            typedef unsigned short GLhalfARB;
         
     | 
| 
      
 47 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            #ifndef GL_ARB_shader_objects
         
     | 
| 
      
 50 
     | 
    
         
            +
            typedef char GLcharARB;
         
     | 
| 
      
 51 
     | 
    
         
            +
            typedef unsigned int GLhandleARB;
         
     | 
| 
      
 52 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            #ifndef GL_ARB_vertex_buffer_object
         
     | 
| 
      
 55 
     | 
    
         
            +
            typedef ptrdiff_t GLintptrARB;
         
     | 
| 
      
 56 
     | 
    
         
            +
            typedef ptrdiff_t GLsizeiptrARB;
         
     | 
| 
      
 57 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            /* new GL types introduced by other extensions */
         
     | 
| 
      
 60 
     | 
    
         
            +
            #ifndef GL_NV_half_float
         
     | 
| 
      
 61 
     | 
    
         
            +
            typedef unsigned short GLhalfNV;
         
     | 
| 
      
 62 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            #ifndef GL_EXT_timer_query
         
     | 
| 
      
 65 
     | 
    
         
            +
            typedef int64_t GLint64EXT;
         
     | 
| 
      
 66 
     | 
    
         
            +
            typedef uint64_t GLuint64EXT;
         
     | 
| 
      
 67 
     | 
    
         
            +
            #endif
         
     | 
    
        data/ext/opengl/gl.c
    ADDED
    
    | 
         @@ -0,0 +1,220 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /*
         
     | 
| 
      
 2 
     | 
    
         
            +
             * Copyright (C) 1999 - 2005 Yoshi <yoshi@giganet.net>
         
     | 
| 
      
 3 
     | 
    
         
            +
             * Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
         
     | 
| 
      
 4 
     | 
    
         
            +
             * Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
         
     | 
| 
      
 5 
     | 
    
         
            +
             *
         
     | 
| 
      
 6 
     | 
    
         
            +
             * This program is distributed under the terms of the MIT license.
         
     | 
| 
      
 7 
     | 
    
         
            +
             * See the included MIT-LICENSE file for the terms of this license.
         
     | 
| 
      
 8 
     | 
    
         
            +
             *
         
     | 
| 
      
 9 
     | 
    
         
            +
             * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
         
     | 
| 
      
 10 
     | 
    
         
            +
             * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 11 
     | 
    
         
            +
             * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         
     | 
| 
      
 12 
     | 
    
         
            +
             * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         
     | 
| 
      
 13 
     | 
    
         
            +
             * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         
     | 
| 
      
 14 
     | 
    
         
            +
             * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         
     | 
| 
      
 15 
     | 
    
         
            +
             * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
      
 16 
     | 
    
         
            +
             */
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            #include "common.h"
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            static VALUE module;
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            void gl_init_enums(VALUE);
         
     | 
| 
      
 23 
     | 
    
         
            +
            void gl_init_functions_1_0__1_1(VALUE);
         
     | 
| 
      
 24 
     | 
    
         
            +
            void gl_init_functions_1_2(VALUE);
         
     | 
| 
      
 25 
     | 
    
         
            +
            void gl_init_functions_1_3(VALUE);
         
     | 
| 
      
 26 
     | 
    
         
            +
            void gl_init_functions_1_4(VALUE);
         
     | 
| 
      
 27 
     | 
    
         
            +
            void gl_init_functions_1_5(VALUE);
         
     | 
| 
      
 28 
     | 
    
         
            +
            void gl_init_functions_2_0(VALUE);
         
     | 
| 
      
 29 
     | 
    
         
            +
            void gl_init_functions_2_1(VALUE);
         
     | 
| 
      
 30 
     | 
    
         
            +
            void gl_init_functions_3_0(VALUE);
         
     | 
| 
      
 31 
     | 
    
         
            +
            void gl_init_functions_ext_3dfx(VALUE);
         
     | 
| 
      
 32 
     | 
    
         
            +
            void gl_init_functions_ext_arb(VALUE);
         
     | 
| 
      
 33 
     | 
    
         
            +
            void gl_init_functions_ext_ati(VALUE);
         
     | 
| 
      
 34 
     | 
    
         
            +
            void gl_init_functions_ext_ext(VALUE);
         
     | 
| 
      
 35 
     | 
    
         
            +
            void gl_init_functions_ext_gremedy(VALUE);
         
     | 
| 
      
 36 
     | 
    
         
            +
            void gl_init_functions_ext_nv(VALUE);
         
     | 
| 
      
 37 
     | 
    
         
            +
            void gl_init_buffer(void);
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            static int opengl_version[2]; /* major, minor */
         
     | 
| 
      
 40 
     | 
    
         
            +
            static char *opengl_extensions = NULL;
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            /* Returns current OpenGL version as major, minor or 0,0 if
         
     | 
| 
      
 43 
     | 
    
         
            +
             * unknown (context not yet initialised etc.) The version is
         
     | 
| 
      
 44 
     | 
    
         
            +
             * cached for subsequent calls.
         
     | 
| 
      
 45 
     | 
    
         
            +
             */
         
     | 
| 
      
 46 
     | 
    
         
            +
            const int *GetOpenglVersion(void)
         
     | 
| 
      
 47 
     | 
    
         
            +
            {
         
     | 
| 
      
 48 
     | 
    
         
            +
            	if (opengl_version[0]==0) { /* not cached, query */
         
     | 
| 
      
 49 
     | 
    
         
            +
            		const char *vstr = (const char *) glGetString(GL_VERSION);
         
     | 
| 
      
 50 
     | 
    
         
            +
            		CHECK_GLERROR_FROM("glGetString");
         
     | 
| 
      
 51 
     | 
    
         
            +
            		if (vstr)
         
     | 
| 
      
 52 
     | 
    
         
            +
            			sscanf( vstr, "%d.%d", &opengl_version[0], &opengl_version[1] );
         
     | 
| 
      
 53 
     | 
    
         
            +
            	}
         
     | 
| 
      
 54 
     | 
    
         
            +
            	return opengl_version;
         
     | 
| 
      
 55 
     | 
    
         
            +
            }
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            /* Checks if OpenGL version is at least the same or higher than
         
     | 
| 
      
 58 
     | 
    
         
            +
             * major.minor
         
     | 
| 
      
 59 
     | 
    
         
            +
             */
         
     | 
| 
      
 60 
     | 
    
         
            +
            GLboolean CheckOpenglVersion(int major, int minor)
         
     | 
| 
      
 61 
     | 
    
         
            +
            {
         
     | 
| 
      
 62 
     | 
    
         
            +
            	const int *version;
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            	version = GetOpenglVersion();
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            	if (version[0]>major || (version[0]==major && version[1] >=minor))
         
     | 
| 
      
 67 
     | 
    
         
            +
            		return GL_TRUE;
         
     | 
| 
      
 68 
     | 
    
         
            +
            	else
         
     | 
| 
      
 69 
     | 
    
         
            +
            		return GL_FALSE;
         
     | 
| 
      
 70 
     | 
    
         
            +
            }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            /* Returns supported OpenGL extensions as char* or NULL
         
     | 
| 
      
 73 
     | 
    
         
            +
             * if unknown (context not yet initialised etc.) The list is
         
     | 
| 
      
 74 
     | 
    
         
            +
             * cached for subsequent calls.
         
     | 
| 
      
 75 
     | 
    
         
            +
             */
         
     | 
| 
      
 76 
     | 
    
         
            +
            const char *GetOpenglExtensions(void)
         
     | 
| 
      
 77 
     | 
    
         
            +
            {
         
     | 
| 
      
 78 
     | 
    
         
            +
            	if (opengl_extensions == NULL) {
         
     | 
| 
      
 79 
     | 
    
         
            +
            		const char *estr = (const char *) glGetString(GL_EXTENSIONS);
         
     | 
| 
      
 80 
     | 
    
         
            +
            		CHECK_GLERROR_FROM("glGetString");
         
     | 
| 
      
 81 
     | 
    
         
            +
            		if (estr) {
         
     | 
| 
      
 82 
     | 
    
         
            +
            			long len = strlen(estr);
         
     | 
| 
      
 83 
     | 
    
         
            +
            			opengl_extensions = ALLOC_N(GLchar,len+1+1); /* terminating null and added space */
         
     | 
| 
      
 84 
     | 
    
         
            +
            			strcpy(opengl_extensions,estr);
         
     | 
| 
      
 85 
     | 
    
         
            +
            			opengl_extensions[len] = ' '; /* add space char for easy searchs */
         
     | 
| 
      
 86 
     | 
    
         
            +
            			opengl_extensions[len+1] = '\0';
         
     | 
| 
      
 87 
     | 
    
         
            +
            		}
         
     | 
| 
      
 88 
     | 
    
         
            +
            	}
         
     | 
| 
      
 89 
     | 
    
         
            +
            	return opengl_extensions;	
         
     | 
| 
      
 90 
     | 
    
         
            +
            }
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            /* Checks if extension is supported by the current OpenGL implementation
         
     | 
| 
      
 93 
     | 
    
         
            +
             */
         
     | 
| 
      
 94 
     | 
    
         
            +
            GLboolean CheckExtension(const char *name)
         
     | 
| 
      
 95 
     | 
    
         
            +
            {
         
     | 
| 
      
 96 
     | 
    
         
            +
            	const char *extensions;
         
     | 
| 
      
 97 
     | 
    
         
            +
            	char *name_tmp;
         
     | 
| 
      
 98 
     | 
    
         
            +
            	long name_len;
         
     | 
| 
      
 99 
     | 
    
         
            +
            	GLboolean res;
         
     | 
| 
      
 100 
     | 
    
         
            +
            	
         
     | 
| 
      
 101 
     | 
    
         
            +
            	extensions = GetOpenglExtensions();
         
     | 
| 
      
 102 
     | 
    
         
            +
            	
         
     | 
| 
      
 103 
     | 
    
         
            +
            	if(extensions==NULL)
         
     | 
| 
      
 104 
     | 
    
         
            +
            		return GL_FALSE;
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
            	/* add trailing space */
         
     | 
| 
      
 107 
     | 
    
         
            +
            	name_len = strlen(name);
         
     | 
| 
      
 108 
     | 
    
         
            +
            	name_tmp = ALLOC_N(GLchar,name_len+1+1); /* terminating null and added space */
         
     | 
| 
      
 109 
     | 
    
         
            +
            	strcpy(name_tmp,name);
         
     | 
| 
      
 110 
     | 
    
         
            +
            	name_tmp[name_len] = ' '; /* add space char for search */
         
     | 
| 
      
 111 
     | 
    
         
            +
            	name_tmp[name_len+1] = '\0';
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            	if (strstr(extensions,name_tmp))
         
     | 
| 
      
 114 
     | 
    
         
            +
            		res = GL_TRUE;
         
     | 
| 
      
 115 
     | 
    
         
            +
            	else
         
     | 
| 
      
 116 
     | 
    
         
            +
            		res = GL_FALSE;
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
            	xfree(name_tmp);
         
     | 
| 
      
 119 
     | 
    
         
            +
            	return res;	
         
     | 
| 
      
 120 
     | 
    
         
            +
            }
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
            /* wrapper for CheckOpenglVersion and CheckExtension, also used by macros
         
     | 
| 
      
 123 
     | 
    
         
            +
             */
         
     | 
| 
      
 124 
     | 
    
         
            +
            GLboolean CheckVersionExtension(const char *name)
         
     | 
| 
      
 125 
     | 
    
         
            +
            {
         
     | 
| 
      
 126 
     | 
    
         
            +
            	if (name && name[0] && name[0]>='0' && name[0]<='9') { /* GL version query */
         
     | 
| 
      
 127 
     | 
    
         
            +
            		int major,minor;
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
            		if (sscanf( name, "%d.%d", &major, &minor ) != 2)
         
     | 
| 
      
 130 
     | 
    
         
            +
            				return GL_FALSE;
         
     | 
| 
      
 131 
     | 
    
         
            +
            	
         
     | 
| 
      
 132 
     | 
    
         
            +
            		return (CheckOpenglVersion(major,minor));
         
     | 
| 
      
 133 
     | 
    
         
            +
            	} else {
         
     | 
| 
      
 134 
     | 
    
         
            +
            		return (CheckExtension(name));
         
     | 
| 
      
 135 
     | 
    
         
            +
            	}
         
     | 
| 
      
 136 
     | 
    
         
            +
            }
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
            /* Checks if given OpenGL version or extension is available
         
     | 
| 
      
 139 
     | 
    
         
            +
             */
         
     | 
| 
      
 140 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 141 
     | 
    
         
            +
            IsAvailable(obj,arg1)
         
     | 
| 
      
 142 
     | 
    
         
            +
            VALUE obj,arg1;
         
     | 
| 
      
 143 
     | 
    
         
            +
            {
         
     | 
| 
      
 144 
     | 
    
         
            +
            	char *name = NULL;
         
     | 
| 
      
 145 
     | 
    
         
            +
            	VALUE s;
         
     | 
| 
      
 146 
     | 
    
         
            +
            	GLboolean res;
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
            	s = rb_funcall(arg1, rb_intern("to_s"), 0);
         
     | 
| 
      
 149 
     | 
    
         
            +
            	name = RSTRING_PTR(s);
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
            	res = CheckVersionExtension(name);
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
            	return GLBOOL2RUBY(res);
         
     | 
| 
      
 154 
     | 
    
         
            +
            }
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
            /* Checks whether non-zero buffer of type $buffer is bound
         
     | 
| 
      
 157 
     | 
    
         
            +
             * - this affects several functions that pass data from/to OpenGL.
         
     | 
| 
      
 158 
     | 
    
         
            +
             */
         
     | 
| 
      
 159 
     | 
    
         
            +
            GLint CheckBufferBinding(GLint buffer)
         
     | 
| 
      
 160 
     | 
    
         
            +
            {
         
     | 
| 
      
 161 
     | 
    
         
            +
            	GLint result = 0;
         
     | 
| 
      
 162 
     | 
    
         
            +
            	
         
     | 
| 
      
 163 
     | 
    
         
            +
            	/* check if the buffer functionality is supported */
         
     | 
| 
      
 164 
     | 
    
         
            +
            	switch(buffer) {
         
     | 
| 
      
 165 
     | 
    
         
            +
            		case GL_ARRAY_BUFFER_BINDING:
         
     | 
| 
      
 166 
     | 
    
         
            +
            		case GL_ELEMENT_ARRAY_BUFFER_BINDING:
         
     | 
| 
      
 167 
     | 
    
         
            +
            			if (!CheckOpenglVersion(1,5))
         
     | 
| 
      
 168 
     | 
    
         
            +
            				return 0;
         
     | 
| 
      
 169 
     | 
    
         
            +
            			break;
         
     | 
| 
      
 170 
     | 
    
         
            +
            		case GL_PIXEL_PACK_BUFFER_BINDING:
         
     | 
| 
      
 171 
     | 
    
         
            +
            		case GL_PIXEL_UNPACK_BUFFER_BINDING:
         
     | 
| 
      
 172 
     | 
    
         
            +
            			if (!CheckOpenglVersion(2,1))
         
     | 
| 
      
 173 
     | 
    
         
            +
            				return 0;
         
     | 
| 
      
 174 
     | 
    
         
            +
            			break;
         
     | 
| 
      
 175 
     | 
    
         
            +
            		default:
         
     | 
| 
      
 176 
     | 
    
         
            +
            			rb_raise(rb_eRuntimeError,"Internal Error: buffer type '%i' does not exist", buffer);
         
     | 
| 
      
 177 
     | 
    
         
            +
            			break;
         
     | 
| 
      
 178 
     | 
    
         
            +
            	}
         
     | 
| 
      
 179 
     | 
    
         
            +
            	glGetIntegerv(buffer,&result);
         
     | 
| 
      
 180 
     | 
    
         
            +
            	CHECK_GLERROR_FROM("glGetIntegerv");
         
     | 
| 
      
 181 
     | 
    
         
            +
            	return result;
         
     | 
| 
      
 182 
     | 
    
         
            +
            }
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
            DLLEXPORT void Init_gl()
         
     | 
| 
      
 185 
     | 
    
         
            +
            {
         
     | 
| 
      
 186 
     | 
    
         
            +
              VALUE mOpenGL = rb_path2class("OpenGL");
         
     | 
| 
      
 187 
     | 
    
         
            +
            	VALUE version = rb_const_get(mOpenGL, rb_intern("VERSION"));
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
              gl_init_buffer();
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
            	module = rb_define_module("Gl");
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
              /* TODO remove */
         
     | 
| 
      
 194 
     | 
    
         
            +
            	rb_define_const(module, "BINDINGS_VERSION", version);
         
     | 
| 
      
 195 
     | 
    
         
            +
            	rb_define_const(module, "RUBY_OPENGL_VERSION", version);
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
            	gl_init_error(module);
         
     | 
| 
      
 198 
     | 
    
         
            +
            	gl_init_enums(module);
         
     | 
| 
      
 199 
     | 
    
         
            +
            	gl_init_functions_1_0__1_1(module);
         
     | 
| 
      
 200 
     | 
    
         
            +
            	gl_init_functions_1_2(module);
         
     | 
| 
      
 201 
     | 
    
         
            +
            	gl_init_functions_1_3(module);
         
     | 
| 
      
 202 
     | 
    
         
            +
            	gl_init_functions_1_4(module);
         
     | 
| 
      
 203 
     | 
    
         
            +
            	gl_init_functions_1_5(module);
         
     | 
| 
      
 204 
     | 
    
         
            +
            	gl_init_functions_2_0(module);
         
     | 
| 
      
 205 
     | 
    
         
            +
            	gl_init_functions_2_1(module);
         
     | 
| 
      
 206 
     | 
    
         
            +
            	gl_init_functions_3_0(module);
         
     | 
| 
      
 207 
     | 
    
         
            +
            	gl_init_functions_ext_3dfx(module);
         
     | 
| 
      
 208 
     | 
    
         
            +
            	gl_init_functions_ext_arb(module);
         
     | 
| 
      
 209 
     | 
    
         
            +
            	gl_init_functions_ext_ati(module);
         
     | 
| 
      
 210 
     | 
    
         
            +
            	gl_init_functions_ext_ext(module);
         
     | 
| 
      
 211 
     | 
    
         
            +
            	gl_init_functions_ext_gremedy(module);
         
     | 
| 
      
 212 
     | 
    
         
            +
            	gl_init_functions_ext_nv(module);
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
      
 214 
     | 
    
         
            +
            	rb_define_module_function(module, "is_available?", IsAvailable, 1);
         
     | 
| 
      
 215 
     | 
    
         
            +
            	rb_define_module_function(module, "is_supported?", IsAvailable, 1);
         
     | 
| 
      
 216 
     | 
    
         
            +
            	rb_define_module_function(module, "extension_available?", IsAvailable, 1);
         
     | 
| 
      
 217 
     | 
    
         
            +
            	rb_define_module_function(module, "extension_supported?", IsAvailable, 1);
         
     | 
| 
      
 218 
     | 
    
         
            +
            	rb_define_module_function(module, "version_available?", IsAvailable, 1);
         
     | 
| 
      
 219 
     | 
    
         
            +
            	rb_define_module_function(module, "version_supported?", IsAvailable, 1);
         
     | 
| 
      
 220 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,177 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include "common.h"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            static GLvoid * (APIENTRY * fptr_glMapBuffer)(GLenum,GLenum);
         
     | 
| 
      
 4 
     | 
    
         
            +
            static GLboolean (APIENTRY * fptr_glUnmapBuffer)(GLenum);
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            struct buffer {
         
     | 
| 
      
 7 
     | 
    
         
            +
            	GLenum target;
         
     | 
| 
      
 8 
     | 
    
         
            +
            	void *ptr;
         
     | 
| 
      
 9 
     | 
    
         
            +
            	GLsizeiptr len;
         
     | 
| 
      
 10 
     | 
    
         
            +
            };
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            static void
         
     | 
| 
      
 13 
     | 
    
         
            +
            buffer_free(void *ptr) {
         
     | 
| 
      
 14 
     | 
    
         
            +
            	struct buffer *buf = ptr;
         
     | 
| 
      
 15 
     | 
    
         
            +
            	LOAD_GL_FUNC(glUnmapBuffer, "1.5");
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            	if (buf->ptr != NULL)
         
     | 
| 
      
 18 
     | 
    
         
            +
            		fptr_glUnmapBuffer(buf->target);
         
     | 
| 
      
 19 
     | 
    
         
            +
            }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            static size_t
         
     | 
| 
      
 22 
     | 
    
         
            +
            buffer_memsize(const void *ptr) {
         
     | 
| 
      
 23 
     | 
    
         
            +
            	const struct buffer *buf = ptr;
         
     | 
| 
      
 24 
     | 
    
         
            +
            	return sizeof(struct buffer) + (size_t)buf->len;
         
     | 
| 
      
 25 
     | 
    
         
            +
            }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            static const rb_data_type_t buffer_type = {
         
     | 
| 
      
 28 
     | 
    
         
            +
            	"OpenGL/buffer",
         
     | 
| 
      
 29 
     | 
    
         
            +
            	{ NULL, buffer_free, buffer_memsize, },
         
     | 
| 
      
 30 
     | 
    
         
            +
            };
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            VALUE
         
     | 
| 
      
 33 
     | 
    
         
            +
            rb_gl_buffer_s_map(VALUE klass, VALUE _target, VALUE _access) {
         
     | 
| 
      
 34 
     | 
    
         
            +
            	struct buffer *buf = ALLOC(struct buffer);
         
     | 
| 
      
 35 
     | 
    
         
            +
            	LOAD_GL_FUNC(glMapBuffer, "1.5");
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            	buf->target = RUBY2GLENUM(_target);
         
     | 
| 
      
 38 
     | 
    
         
            +
            	buf->len		= 0;
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            	buf->ptr = fptr_glMapBuffer(buf->target, RUBY2GLENUM(_access));
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            	if (buf->ptr == NULL) {
         
     | 
| 
      
 43 
     | 
    
         
            +
            		xfree(buf);
         
     | 
| 
      
 44 
     | 
    
         
            +
            		CHECK_GLERROR_FROM("glMapBuffer");
         
     | 
| 
      
 45 
     | 
    
         
            +
            	}
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            	return TypedData_Wrap_Struct(klass, &buffer_type, buf);
         
     | 
| 
      
 48 
     | 
    
         
            +
            }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 51 
     | 
    
         
            +
            rb_gl_buffer_addr(VALUE self) {
         
     | 
| 
      
 52 
     | 
    
         
            +
            	struct buffer *buf;
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            	TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            	return SIZET2NUM((size_t)buf->ptr);
         
     | 
| 
      
 57 
     | 
    
         
            +
            }
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 60 
     | 
    
         
            +
            rb_gl_buffer_length(VALUE self) {
         
     | 
| 
      
 61 
     | 
    
         
            +
            	struct buffer *buf;
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            	TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            	return RETCONV_GLsizeiptr(buf->len);
         
     | 
| 
      
 66 
     | 
    
         
            +
            }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 69 
     | 
    
         
            +
            rb_gl_buffer_read(int argc, VALUE *argv, VALUE self) {
         
     | 
| 
      
 70 
     | 
    
         
            +
            	struct buffer *buf;
         
     | 
| 
      
 71 
     | 
    
         
            +
            	VALUE _length, _offset;
         
     | 
| 
      
 72 
     | 
    
         
            +
            	GLsizeiptr offset, length;
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            	TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
            	rb_scan_args(argc, argv, "02", &_length, &_offset);
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            	if (buf->len == 0 && NIL_P(_length))
         
     | 
| 
      
 79 
     | 
    
         
            +
            		rb_raise(rb_eArgError, "length must be provided for unbounded buffer");
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
            	length = NUM2SIZET(_length);
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
            	if (NIL_P(_offset)) {
         
     | 
| 
      
 84 
     | 
    
         
            +
            		offset = 0;
         
     | 
| 
      
 85 
     | 
    
         
            +
            	} else {
         
     | 
| 
      
 86 
     | 
    
         
            +
            		offset = NUM2SIZET(_offset);
         
     | 
| 
      
 87 
     | 
    
         
            +
            	}
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
            	if (buf->len != 0 && length + offset > buf->len)
         
     | 
| 
      
 90 
     | 
    
         
            +
            		rb_raise(rb_eArgError, "read to %lu past end of buffer %lu",
         
     | 
| 
      
 91 
     | 
    
         
            +
            				(unsigned long)(length + offset), (unsigned long)buf->len);
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            	return rb_str_new((char *)buf->ptr + offset, length);
         
     | 
| 
      
 94 
     | 
    
         
            +
            }
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 97 
     | 
    
         
            +
            rb_gl_buffer_target(VALUE self) {
         
     | 
| 
      
 98 
     | 
    
         
            +
            	struct buffer *buf;
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            	TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
            	return RETCONV_GLenum(buf->target);
         
     | 
| 
      
 103 
     | 
    
         
            +
            }
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 106 
     | 
    
         
            +
            rb_gl_buffer_unmap(VALUE self) {
         
     | 
| 
      
 107 
     | 
    
         
            +
            	struct buffer *buf;
         
     | 
| 
      
 108 
     | 
    
         
            +
            	LOAD_GL_FUNC(glUnmapBuffer, "1.5");
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            	TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
            	if (!buf->ptr)
         
     | 
| 
      
 113 
     | 
    
         
            +
            		return self;
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
            	fptr_glUnmapBuffer(buf->target);
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
            	CHECK_GLERROR_FROM("glUnmapBuffer");
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
            	buf->ptr = NULL;
         
     | 
| 
      
 120 
     | 
    
         
            +
            	buf->len = 0;
         
     | 
| 
      
 121 
     | 
    
         
            +
            	buf->target = 0;
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
            	return self;
         
     | 
| 
      
 124 
     | 
    
         
            +
            }
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
            static VALUE
         
     | 
| 
      
 127 
     | 
    
         
            +
            rb_gl_buffer_write(int argc, VALUE *argv, VALUE self) {
         
     | 
| 
      
 128 
     | 
    
         
            +
            	struct buffer *buf;
         
     | 
| 
      
 129 
     | 
    
         
            +
            	VALUE _data, _offset;
         
     | 
| 
      
 130 
     | 
    
         
            +
            	GLsizeiptr offset;
         
     | 
| 
      
 131 
     | 
    
         
            +
            	long length;
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
            	TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            	if (!buf->ptr)
         
     | 
| 
      
 136 
     | 
    
         
            +
            		rb_raise(rb_eArgError, "write to unmapped buffer");
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
            	rb_scan_args(argc, argv, "11", &_data, &_offset);
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
            	if (NIL_P(_data))
         
     | 
| 
      
 141 
     | 
    
         
            +
            		rb_raise(rb_eArgError, "cannot write nil to buffer");
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
            	_data = rb_String(_data);
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
            	length = RSTRING_LEN(_data);
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
            	if (NIL_P(_offset)) {
         
     | 
| 
      
 148 
     | 
    
         
            +
            		offset = 0;
         
     | 
| 
      
 149 
     | 
    
         
            +
            	} else {
         
     | 
| 
      
 150 
     | 
    
         
            +
            		offset = NUM2SIZET(_offset);
         
     | 
| 
      
 151 
     | 
    
         
            +
            	}
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
            	if (buf->len != 0 && length + offset > buf->len)
         
     | 
| 
      
 154 
     | 
    
         
            +
            		rb_raise(rb_eArgError, "write to %lu past end of buffer %lu",
         
     | 
| 
      
 155 
     | 
    
         
            +
            				(unsigned long)(length + offset), (unsigned long)buf->len);
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
            	memcpy((char *)buf->ptr + offset, RSTRING_PTR(_data), RSTRING_LEN(_data));
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
            	return self;
         
     | 
| 
      
 160 
     | 
    
         
            +
            }
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
            void
         
     | 
| 
      
 163 
     | 
    
         
            +
            gl_init_buffer(void) {
         
     | 
| 
      
 164 
     | 
    
         
            +
            	VALUE mOpenGL = rb_path2class("OpenGL");
         
     | 
| 
      
 165 
     | 
    
         
            +
            	VALUE cBuffer = rb_define_class_under(mOpenGL, "Buffer", rb_cObject);
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
            	rb_undef_alloc_func(cBuffer);
         
     | 
| 
      
 168 
     | 
    
         
            +
            	rb_define_singleton_method(cBuffer, "map", rb_gl_buffer_s_map, 2);
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
            	rb_define_method(cBuffer, "addr", rb_gl_buffer_addr, 0);
         
     | 
| 
      
 171 
     | 
    
         
            +
            	rb_define_method(cBuffer, "length", rb_gl_buffer_length, 0);
         
     | 
| 
      
 172 
     | 
    
         
            +
            	rb_define_method(cBuffer, "read", rb_gl_buffer_read, -1);
         
     | 
| 
      
 173 
     | 
    
         
            +
            	rb_define_method(cBuffer, "target", rb_gl_buffer_target, 0);
         
     | 
| 
      
 174 
     | 
    
         
            +
            	rb_define_method(cBuffer, "unmap", rb_gl_buffer_unmap, 0);
         
     | 
| 
      
 175 
     | 
    
         
            +
            	rb_define_method(cBuffer, "write", rb_gl_buffer_write, -1);
         
     | 
| 
      
 176 
     | 
    
         
            +
            }
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     |