2 * Copyright 2017 Jacob Lifshay
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #ifndef PIPELINE_PIPELINE_H_
24 #define PIPELINE_PIPELINE_H_
28 #include "llvm_wrapper/llvm_wrapper.h"
36 Pipeline(const Pipeline
&) = delete;
37 Pipeline
&operator=(const Pipeline
&) = delete;
40 typedef std::uintptr_t Handle
;
43 constexpr Pipeline() noexcept
46 virtual ~Pipeline() = default;
47 static std::unique_ptr
<Pipeline
> move_from_handle(Handle pipeline
) noexcept
49 return std::unique_ptr
<Pipeline
>(from_handle(pipeline
));
51 static Pipeline
*from_handle(Handle pipeline
) noexcept
53 return reinterpret_cast<Pipeline
*>(pipeline
);
57 inline Pipeline::Handle
to_handle(Pipeline
*pipeline
) noexcept
59 return reinterpret_cast<Pipeline::Handle
>(pipeline
);
62 inline Pipeline::Handle
move_to_handle(std::unique_ptr
<Pipeline
> pipeline
) noexcept
64 return to_handle(pipeline
.release());
67 class Graphics_pipeline final
: public Pipeline
70 #warning finish adding draw function parameters
71 typedef void (*Vertex_shader_function
)(std::uint32_t vertex_start_index
,
72 std::uint32_t vertex_count
,
73 std::uint32_t instance_id
,
77 const Vertex_shader_function
get_vertex_shader_function() const noexcept
79 return vertex_shader_function
;
81 #warning finish implementing Graphics_pipeline::make
82 static std::unique_ptr
<Graphics_pipeline
> make();
83 static std::unique_ptr
<Graphics_pipeline
> move_from_handle(Handle pipeline
) noexcept
85 return std::unique_ptr
<Graphics_pipeline
>(from_handle(pipeline
));
87 static Graphics_pipeline
*from_handle(Handle pipeline
) noexcept
89 auto *retval
= reinterpret_cast<Pipeline
*>(pipeline
);
90 assert(!retval
|| dynamic_cast<Graphics_pipeline
*>(retval
));
91 return static_cast<Graphics_pipeline
*>(retval
);
95 Graphics_pipeline(std::shared_ptr
<void> state
,
96 Vertex_shader_function vertex_shader_function
) noexcept
97 : state(std::move(state
)),
98 vertex_shader_function(vertex_shader_function
)
103 std::shared_ptr
<void> state
;
104 Vertex_shader_function vertex_shader_function
;
107 inline Pipeline::Handle
to_handle(Graphics_pipeline
*pipeline
) noexcept
109 return to_handle(static_cast<Pipeline
*>(pipeline
));
112 inline Pipeline::Handle
move_to_handle(std::unique_ptr
<Graphics_pipeline
> pipeline
) noexcept
114 return to_handle(pipeline
.release());
119 #endif // PIPELINE_PIPELINE_H_