sdl2_vulkan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12364f364aa12cf244696414abe0c1de4a48d4b249dcea75cfe2639d469ca9f5
4
+ data.tar.gz: 31be4a9e97e422033390ee8f254dcf63e39d69da5ae91ee77eecf32dc7d52e82
5
+ SHA512:
6
+ metadata.gz: 4719162f233e81629c0c0f0d4114d13758c7136f914cc782b64e0b8222dc4035fc264bfbd396142ace0dc5e48f7d7359228df8424d5902b19328f2b122c491dd
7
+ data.tar.gz: 77f3ea8a98994aa402dbecf4a0592a81617bc7cdfaa394b8e576adfcf671f71c27da75aa81f8d4a70737b1dab83c44b6287a2491267c4998e0a353403801a9ef
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.0
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sdl2_vulkan.gemspec
6
+ gemspec
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sdl2_vulkan (0.1.0)
5
+ ruby-sdl2 (~> 0.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.11.3)
11
+ rake (10.5.0)
12
+ rake-compiler (1.0.4)
13
+ rake
14
+ ruby-sdl2 (0.3.4)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.16)
21
+ minitest (~> 5.0)
22
+ rake (~> 10.0)
23
+ rake-compiler
24
+ sdl2_vulkan!
25
+
26
+ BUNDLED WITH
27
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Colin MacKenzie IV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # `sdl2_vulkan`
2
+
3
+ Adds on to the [`ruby-sdl2`](https://github.com/ohai/ruby-sdl2) gem to expose
4
+ SDL2's Vulkan functions to Ruby in order to make it possible to present Vulkan
5
+ swapchain images to SDL2 windows.
6
+
7
+ Requires SDL v2.0.8 or higher, which is when Vulkan support was added to SDL.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'sdl2_vulkan'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install sdl2_vulkan
24
+
25
+ ## Usage
26
+
27
+ See [sdl2_vulkan_test.rb#L11-L24](https://github.com/sinisterchipmunk/sdl2_vulkan/tree/master/test/sdl2_vulkan_test.rb#L11-L24) for usage.
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sinisterchipmunk/sdl2_vulkan.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ require "rake/extensiontask"
11
+
12
+ task :build => :compile
13
+
14
+ Rake::ExtensionTask.new("sdl2_vulkan") do |ext|
15
+ ext.lib_dir = "lib/sdl2_vulkan"
16
+ end
17
+
18
+ task :default => [:clobber, :compile, :test]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sdl2_vulkan"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,49 @@
1
+ require 'mkmf'
2
+
3
+ # helpers "borrowed" from ruby-sdl2
4
+ def add_cflags(str)
5
+ $CFLAGS += " " + str
6
+ end
7
+
8
+ def add_libs(str)
9
+ $LOCAL_LIBS += " " + str
10
+ end
11
+
12
+ def run_config_program(*args)
13
+ IO.popen([*args], "r") do |io|
14
+ io.gets.chomp
15
+ end
16
+ end
17
+
18
+ def sdl2config_with_command
19
+ sdl2_config = with_config('sdl2-config', 'sdl2-config')
20
+ add_cflags(run_config_program(sdl2_config, "--cflags"))
21
+ add_libs(run_config_program(sdl2_config, "--libs"))
22
+ end
23
+
24
+ def sdl2config_on_mingw
25
+ have_library("mingw32")
26
+ have_library("SDL2")
27
+ add_libs("-mwindows")
28
+ end
29
+
30
+ case RbConfig::CONFIG["arch"]
31
+ when /mingw/
32
+ sdl2config_on_mingw
33
+ else
34
+ sdl2config_with_command
35
+ end
36
+
37
+ require 'fiddle'
38
+ %w(
39
+ SIZEOF_VOIDP SIZEOF_CHAR SIZEOF_SHORT SIZEOF_INT SIZEOF_LONG SIZEOF_LONG_LONG
40
+ SIZEOF_FLOAT SIZEOF_DOUBLE SIZEOF_SIZE_T SIZEOF_SSIZE_T SIZEOF_PTRDIFF_T
41
+ SIZEOF_INTPTR_T SIZEOF_UINTPTR_T
42
+ ).each do |const_name|
43
+ if Fiddle.constants.include?(const_name.to_sym)
44
+ $CFLAGS << " -DHAVE_#{const_name}=1 -D#{const_name}=#{Fiddle.const_get(const_name.to_sym)}"
45
+ end
46
+ end
47
+
48
+ have_header("SDL_vulkan.h")
49
+ create_makefile("sdl2_vulkan/sdl2_vulkan")
@@ -0,0 +1,133 @@
1
+ #include "sdl2_vulkan.h"
2
+
3
+ // from ruby-sdl2
4
+ typedef struct Window {
5
+ SDL_Window* window;
6
+ int num_renderers;
7
+ int max_renderers;
8
+ struct Renderer** renderers;
9
+ } Window;
10
+
11
+ VALUE rb_mSDL2 = Qnil,
12
+ rb_cWindow = Qnil,
13
+ rb_mFlags = Qnil,
14
+ rb_mVulkan = Qnil;
15
+
16
+ /*
17
+ * Loads the Vulkan library. If `path` is given, it will be used; otherwise
18
+ * the library will be searched for dynamically. Raises an error if the
19
+ * library could not be loaded.
20
+ */
21
+ static VALUE Vulkan_load_library(int argc, VALUE *argv, VALUE self) {
22
+ const char *path = NULL;
23
+ if (argc > 0 && !NIL_P(argv[0])) path = StringValuePtr(argv[0]);
24
+ int result = SDL_Vulkan_LoadLibrary(path);
25
+ if (result != 0) rb_raise(rb_eRuntimeError, "Failed to load Vulkan library: %s", SDL_GetError());
26
+ return self;
27
+ }
28
+
29
+ /*
30
+ * Unloads the Vulkan library.
31
+ */
32
+ static VALUE Vulkan_unload_library(VALUE self) {
33
+ SDL_Vulkan_UnloadLibrary();
34
+ return self;
35
+ }
36
+
37
+ /*
38
+ * Returns an integer value which is the memory address of the
39
+ * vkGetInstanceProcAddr function. The integer value will need to be converted
40
+ * into something more useful, for instance using
41
+ * [Fiddle](https://github.com/ruby/fiddle). Returns `nil` if the address
42
+ * would be NULL.
43
+ */
44
+ static VALUE Vulkan_get_vk_get_instance_proc_addr(VALUE self) {
45
+ return PTR2NUM(SDL_Vulkan_GetVkGetInstanceProcAddr());
46
+ }
47
+
48
+ /*
49
+ * Returns an array of Vulkan extension names. Raises an error if they could
50
+ * not be retrieved.
51
+ */
52
+ static VALUE Window_get_instance_extension_names(VALUE self) {
53
+ Window *window_data = NULL;
54
+ Data_Get_Struct(self, Window, window_data);
55
+ if (window_data == NULL || window_data->window == NULL)
56
+ rb_raise(rb_eArgError, "Not a window");
57
+
58
+ unsigned int count = 0;
59
+ if (!SDL_Vulkan_GetInstanceExtensions(window_data->window, &count, NULL))
60
+ rb_raise(rb_eRuntimeError, "Could not query number of extensions");
61
+
62
+ const char **extension_names = malloc(count * sizeof(const char *));
63
+ if (!SDL_Vulkan_GetInstanceExtensions(window_data->window, &count, extension_names)) {
64
+ free(extension_names);
65
+ rb_raise(rb_eRuntimeError, "Could not query extension names");
66
+ }
67
+
68
+ VALUE ary = rb_ary_new();
69
+ for (unsigned int i = 0; i < count; i++) {
70
+ rb_ary_push(ary, rb_str_new2(extension_names[i]));
71
+ }
72
+ free(extension_names);
73
+ return ary;
74
+ }
75
+
76
+ /*
77
+ * Creates a Vulkan drawing surface for this window. The `instance` argument
78
+ * should be a number which represents the memory address of the `VkInstance`
79
+ * (which is a pointer type).
80
+ *
81
+ * Raises a runtime error if the operation fails.
82
+ *
83
+ * Returns a number representing the memory address of the created surface.
84
+ *
85
+ */
86
+ static VALUE Window_create_surface(VALUE self, VALUE instance_addr) {
87
+ Window *window_data = NULL;
88
+ Data_Get_Struct(self, Window, window_data);
89
+ if (window_data == NULL || window_data->window == NULL)
90
+ rb_raise(rb_eArgError, "Not a window");
91
+
92
+ VkInstance instance = (VkInstance) NUM2PTR(instance_addr);
93
+ VkSurfaceKHR surface;
94
+ if (!SDL_Vulkan_CreateSurface(window_data->window, instance, &surface))
95
+ rb_raise(rb_eRuntimeError, "Failed to create drawing surface");
96
+
97
+ return PTR2NUM(surface);
98
+ }
99
+
100
+ /*
101
+ * Returns an array containing `[width, height]` which are the drawable
102
+ * dimensions of window in pixels.
103
+ */
104
+ static VALUE Window_get_drawable_size(VALUE self) {
105
+ Window *window_data = NULL;
106
+ Data_Get_Struct(self, Window, window_data);
107
+ if (window_data == NULL || window_data->window == NULL)
108
+ rb_raise(rb_eArgError, "Not a window");
109
+
110
+ int width = 0;
111
+ int height = 0;
112
+ SDL_Vulkan_GetDrawableSize(window_data->window, &width, &height);
113
+
114
+ VALUE ary = rb_ary_new();
115
+ rb_ary_push(ary, INT2NUM(width));
116
+ rb_ary_push(ary, INT2NUM(height));
117
+ return ary;
118
+ }
119
+
120
+ void Init_sdl2_vulkan(void) {
121
+ rb_mSDL2 = rb_define_module("SDL2");
122
+ rb_cWindow = rb_const_get(rb_mSDL2, rb_intern("Window"));
123
+ rb_mFlags = rb_const_get(rb_cWindow, rb_intern("Flags"));
124
+ rb_mVulkan = rb_define_module_under(rb_mSDL2, "Vulkan");
125
+
126
+ rb_define_const(rb_mFlags, "VULKAN", INT2NUM(SDL_WINDOW_VULKAN));
127
+ rb_define_singleton_method(rb_mVulkan, "load_library", Vulkan_load_library, -1);
128
+ rb_define_singleton_method(rb_mVulkan, "vk_get_instance_proc_addr", Vulkan_get_vk_get_instance_proc_addr, 0);
129
+ rb_define_singleton_method(rb_mVulkan, "unload_library", Vulkan_unload_library, 0);
130
+ rb_define_method(rb_cWindow, "vk_instance_extensions", Window_get_instance_extension_names, 0);
131
+ rb_define_method(rb_cWindow, "vk_create_surface", Window_create_surface, 1);
132
+ rb_define_method(rb_cWindow, "vk_drawable_size", Window_get_drawable_size, 0);
133
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef SDL2_VULKAN_H
2
+ #define SDL2_VULKAN_H 1
3
+
4
+ #include "ruby.h"
5
+ #include "SDL2/SDL_vulkan.h"
6
+
7
+ #if SIZEOF_VOIDP == SIZEOF_LONG
8
+ # define PTR2NUM(x) (LONG2NUM((long)(x)))
9
+ # define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
10
+ #else
11
+ # define PTR2NUM(x) (LL2NUM((LONG_LONG)(x)))
12
+ # define NUM2PTR(x) ((void*)(NUM2ULL(x)))
13
+ #endif
14
+
15
+ #endif /* SDL2_VULKAN_H */
@@ -0,0 +1,3 @@
1
+ require 'sdl2'
2
+ require "sdl2_vulkan/version"
3
+ require "sdl2_vulkan/sdl2_vulkan"
@@ -0,0 +1,3 @@
1
+ module Sdl2Vulkan
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sdl2_vulkan/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sdl2_vulkan"
8
+ spec.version = Sdl2Vulkan::VERSION
9
+ spec.authors = ["Colin MacKenzie IV"]
10
+ spec.email = ["sinisterchipmunk@gmail.com"]
11
+
12
+ spec.summary = %q{Adds on to ruby-sdl2 to expose Vulkan functions}
13
+ spec.homepage = "https://github.com/sinisterchipmunk/ruby-sdl2_vulkan"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/sinisterchipmunk/ruby-sdl2_vulkan"
23
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+ spec.extensions = ["ext/sdl2_vulkan/extconf.rb"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rake-compiler"
42
+ spec.add_development_dependency "minitest", "~> 5.0"
43
+ spec.add_dependency 'ruby-sdl2', '~> 0.3'
44
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sdl2_vulkan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Colin MacKenzie IV
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-sdl2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ description:
84
+ email:
85
+ - sinisterchipmunk@gmail.com
86
+ executables: []
87
+ extensions:
88
+ - ext/sdl2_vulkan/extconf.rb
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - ext/sdl2_vulkan/extconf.rb
101
+ - ext/sdl2_vulkan/sdl2_vulkan.c
102
+ - ext/sdl2_vulkan/sdl2_vulkan.h
103
+ - lib/sdl2_vulkan.rb
104
+ - lib/sdl2_vulkan/version.rb
105
+ - sdl2_vulkan.gemspec
106
+ homepage: https://github.com/sinisterchipmunk/ruby-sdl2_vulkan
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ allowed_push_host: https://rubygems.org
111
+ homepage_uri: https://github.com/sinisterchipmunk/ruby-sdl2_vulkan
112
+ source_code_uri: https://github.com/sinisterchipmunk/ruby-sdl2_vulkan
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.7.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Adds on to ruby-sdl2 to expose Vulkan functions
133
+ test_files: []