Make CHelloTriangle in C++ to simplify Utils

The point of CHelloTriangle is to use the C version of NXT, so having
the code C++ is still ok.
This commit is contained in:
Corentin Wallez 2017-06-16 18:51:14 -04:00 committed by Corentin Wallez
parent 6aef6833b7
commit 931e6e82fd
4 changed files with 76 additions and 98 deletions

View File

@ -21,7 +21,7 @@ nxtRenderPass renderpass;
nxtFramebuffer framebuffer;
void init() {
device = CreateNXTDevice();
device = CreateCppNXTDevice().Release();
{
nxtQueueBuilder builder = nxtDeviceCreateQueueBuilder(device);
@ -35,7 +35,7 @@ void init() {
"void main() {\n"
" gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n"
"}\n";
nxtShaderModule vsModule = CreateShaderModule(device, NXT_SHADER_STAGE_VERTEX, vs);
nxtShaderModule vsModule = CreateShaderModule(nxt::Device(device), nxt::ShaderStage::Vertex, vs).Release();
const char* fs =
"#version 450\n"
@ -43,7 +43,7 @@ void init() {
"void main() {\n"
" fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n";
nxtShaderModule fsModule = CreateShaderModule(device, NXT_SHADER_STAGE_FRAGMENT, fs);
nxtShaderModule fsModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, fs).Release();
{
nxtRenderPassBuilder builder = nxtDeviceCreateRenderPassBuilder(device);

View File

@ -34,8 +34,9 @@ add_library(utils STATIC ${UTILS_SOURCES})
target_link_libraries(utils nxt_backend nxt_wire shaderc nxtcpp nxt)
SetCXX14(utils)
add_executable(CHelloTriangle HelloTriangle.c)
add_executable(CHelloTriangle CHelloTriangle.cpp)
target_link_libraries(CHelloTriangle utils)
SetCXX14(CHelloTriangle)
add_executable(CppHelloTriangle HelloTriangle.cpp)
target_link_libraries(CppHelloTriangle utils)

View File

@ -271,7 +271,6 @@ nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, const void* da
return buffer;
}
extern "C" {
bool InitUtils(int argc, const char** argv) {
for (int i = 0; i < argc; i++) {
if (std::string("-b") == argv[i] || std::string("--backend") == argv[i]) {
@ -318,14 +317,6 @@ extern "C" {
return true;
}
nxtDevice CreateNXTDevice() {
return CreateCppNXTDevice().Release();
}
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source) {
return CreateShaderModule(device, static_cast<nxt::ShaderStage>(stage), source).Release();
}
void DoSwapBuffers() {
if (cmdBufType == CmdBufType::Terrible) {
c2sBuf->Flush();
@ -352,4 +343,3 @@ extern "C" {
GLFWwindow* GetGLFWWindow() {
return window;
}
}

View File

@ -12,11 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <nxt/nxt.h>
#include <nxt/nxtcpp.h>
#if defined(__cplusplus)
extern "C" {
#endif
bool InitUtils(int argc, const char** argv);
void DoSwapBuffers();
bool ShouldQuit();
@ -24,18 +21,8 @@ extern "C" {
struct GLFWwindow;
struct GLFWwindow* GetGLFWWindow();
#if defined(__cplusplus)
}
#endif
// Yuck
#if defined(__cplusplus)
#include <nxt/nxtcpp.h>
nxt::Device CreateCppNXTDevice();
nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderStage stage, const char* source);
void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderPass, nxt::Framebuffer* framebuffer);
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, const void* data, uint32_t size, nxt::BufferUsageBit usage);
#else
nxtDevice CreateNXTDevice();
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source);
#endif