mirror of
https://github.com/KhronosGroup/Vulkan-Hpp
synced 2024-11-29 07:01:08 +00:00
Merge pull request #41 from mtavenrath/readme
Update README.md with tiny code samples on how to use the new C++ obj…
This commit is contained in:
commit
766f69993c
50
README.md
50
README.md
@ -143,30 +143,29 @@ vk::createImage(device, &ci, allocator, &image));
|
|||||||
|
|
||||||
|
|
||||||
# Enhancements beyond the API
|
# Enhancements beyond the API
|
||||||
While mapping the Vulkan API to C++ without adding new functions is already a big help, one can do even more by adding new functionality. For example several C++ developers tend to use std::string and std::vector in their code, therefore we have added some more optional convenience features:
|
To provide a more object oriented feeling we're providing classes for each handle which include all Vulkan functions where the first
|
||||||
|
parameter matches the handle. In addition to this we made a few changes to the signatures of the member functions
|
||||||
* Use <code>std::string</code> instead of <code>const char *</code> for strings
|
* <code>(count, T*)</code> has been replaced by <code>std::vector<T></code>
|
||||||
* Use <code>std::vector</code> instead of <code>(count, ptr)</code> for sized arrays
|
* <code>const char *</code> has been replaced by <std::string>
|
||||||
* Throw exceptions instead of error return values (in progress)
|
* vk::Result return values have been replaced by exceptions.
|
||||||
* Return handles/vectors where applicable, i.e. for the create* functions
|
* Functions with a single output value do return this value instead
|
||||||
|
|
||||||
As example let's examine the device extension property enumeration in Vulkan:
|
|
||||||
|
|
||||||
|
Here are a few code examples:
|
||||||
<pre>
|
<pre>
|
||||||
<code>
|
<code>
|
||||||
uint32_t count;
|
try {
|
||||||
VK_VERIFY(vk::enumerateDeviceExtensionProperties(physicalDevice, layerName.c_str(), &count, nullptr));
|
vk::Instance i = ...;
|
||||||
|
std::vector<vk::PhysicalDevice> physicalDevices = i.enumeratePhysicalDevices();
|
||||||
|
vk::FormatProperties formatProperties = physicalDevices[0].getFormatProperties(vk::Format::eR8G8B8A8Unorm);
|
||||||
|
|
||||||
std::vector<vk::ExtensionProperties> properties(count);
|
vk::CommandBuffer commandBuffer = ...;
|
||||||
VK_VERIFY(vk::enumerateDeviceExtensionProperties(physicalDevice, layerName.c_str(), &count, properties.data()));
|
vk::Buffer buffer = ...;
|
||||||
</code>
|
commandBuffer.updateBuffer(buffer, 0, {some values}); // update buffer with std::vector
|
||||||
</pre>
|
}
|
||||||
|
catch (vk::Exception e)
|
||||||
Luckily the official Khronos-provided vk.xml has enough information to figure out which pair of values represents a sized array or strings, so that it is possible to generate a function which allows you to write the following line of code instead:
|
{
|
||||||
|
std::cerr << "Vulkan failure: " << e.what() << std::endl;
|
||||||
<pre>
|
}
|
||||||
<code>
|
|
||||||
std::vector<ExtensionProperties> properties = vk::enumerateDeviceExtensionProperties(physicalDevice, layerName);
|
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@ -195,3 +194,14 @@ before this line:
|
|||||||
* Update submodules: git submodule update --init --recursive
|
* Update submodules: git submodule update --init --recursive
|
||||||
* Use CMake to generate a solution or makefile for your favourite build environment
|
* Use CMake to generate a solution or makefile for your favourite build environment
|
||||||
* Launch the build
|
* Launch the build
|
||||||
|
|
||||||
|
# Providing Pull Requests
|
||||||
|
|
||||||
|
NVIDIA is happy to review and consider pull requests for merging into the main tree of vkcpp for bug fixes and features. Before providing a pull request to NVIDIA, please note the following:
|
||||||
|
|
||||||
|
* A pull request provided to this repo by a developer constitutes permission from the developer for NVIDIA to merge the provided
|
||||||
|
changes or any NVIDIA modified version of these changes to the repo. NVIDIA may remove or change the code at any time and in any
|
||||||
|
way deemed appropriate. Due to the required paperwork please refrain from providing pull requests for simple changes and file an issue
|
||||||
|
describing a bug or the desired change instead.
|
||||||
|
* Not all pull requests can be or will be accepted. NVIDIA will close pull requests that it does not intend to merge.
|
||||||
|
* The modified files and any new files must include the unmodified NVIDIA copyright header seen at the top of all shipping files.
|
Loading…
Reference in New Issue
Block a user