9 #define FRONTFACE 0x0404
10 #define BACKFACE 0x0405
16 #define GREATER 0x0204
17 #define NOTEQUAL 0x0205
24 #define REPLACE 0x1E01
27 #define INCR_WRAP 0x8507
28 #define DECR_WRAP 0x8508
42 void init(
void *param1,
void *param2);
49 void Depth(
bool flag);
50 void Blend(
bool flag);
69 void Color(
bool flag);
72 void StencilFunc(
int op,
int ref,
unsigned int mask);
73 void StencilOp(
int stencil_fail,
int zfail,
int zpass);
75 void DrawText(
const char *str,
float x,
float y);
81 void DrawArray(
primitive_t primitive,
int start_index,
int start_vertex,
unsigned int num_index,
int num_verts);
82 void DrawArrayTri(
int start_index,
int start_vertex,
unsigned int num_index,
int num_verts);
83 void DrawArrayTriStrip(
int start_index,
int start_vertex,
unsigned int num_index,
int num_verts);
84 void DrawArrayLineStrip(
int start_index,
int start_vertex,
unsigned int num_index,
int num_verts);
85 void DrawArrayLine(
int start_index,
int start_vertex,
unsigned int num_index,
int num_verts);
86 void DrawArrayPoint(
int start_index,
int start_vertex,
unsigned int num_index,
int num_verts);
107 int LoadTexture(
int width,
int height,
int components,
int format,
void *bytes,
bool clamp,
int anisotropic);
108 int LoadTextureArray(
int width,
int height,
int components,
int format,
void **bytes,
bool clamp,
int num_layer);
114 int CreateFramebuffer(
int width,
int height,
unsigned int &fbo,
unsigned int &quad_tex,
unsigned int &depth_tex,
unsigned int &normal_depth,
int multisample,
bool twoattach);
128 VkInstance CreateInstance();
129 void CreateDeviceAndQueue(VkInstance instance, VkDevice* outputDevice, VkQueue* outputQueue,
int* outputQueueIndex, VkPhysicalDevice* outputPhysicalDevice);
130 void FindPhysicalDeviceWithGraphicsQueue(
const vector<VkPhysicalDevice>& physicalDevices, VkPhysicalDevice* outputDevice,
int* outputGraphicsQueueIndex);
131 void CreateSwapchainImageViews(VkDevice device, VkFormat format,
const int count,
const VkImage* images, VkImageView* imageViews);
132 void CreateFramebuffers(VkDevice device, VkRenderPass renderPass,
const int width,
const int height,
const int count,
const VkImageView* imageViews, VkFramebuffer* framebuffers);
133 void CreateSwapchain(VkPhysicalDevice physicalDevice, VkDevice device, VkSurfaceKHR surface,
const int surfaceWidth,
const int surfaceHeight,
const int backbufferCount, VkFormat* swapchainFormat, VkSwapchainKHR &swapchain);
134 void GetSwapchainFormatAndColorspace(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, SwapchainFormatColorSpace &result);
136 void AllocateBuffer(VkDevice device,
const int size,
const VkBufferUsageFlagBits bits, VkBuffer &buffer);
137 int AllocateMemory(VkDeviceMemory &deviceMemory,
const vector<MemoryTypeInfo>& memoryInfos, VkDevice device,
const int size,
const uint32_t memoryBits,
unsigned int memoryProperties,
bool* isHostCoherent =
nullptr);
139 void CreateSurface(VkInstance instance, HWND hwnd, VkSurfaceKHR &surface);
140 void CreateTexture(
int width,
int height,
int components,
int format,
unsigned char *image_data,
bool clamp);
141 void CreateSampler();
142 void CreateDescriptors();
143 void LoadShader(VkDevice device,
const void* shaderContents,
const size_t size, VkShaderModule &shader);
145 void render_cmdbuffer(VkCommandBuffer commandBuffer,
int width,
int height);
147 void CreatePipeline(VkDevice device, VkRenderPass renderPass, VkPipelineLayout layout, VkShaderModule vertexShader, VkShaderModule fragmentShader, VkPipeline &pipeline);
148 void CreatePipelineStateObject();
149 void CreateMeshBuffers(VkCommandBuffer uploadCommandBuffer);
150 void CreateRenderPass(VkDevice device, VkFormat swapchainFormat, VkRenderPass &rp);
151 void SetupDebugCallback(VkInstance instance, VkDebugReportCallbackEXT &fp);
175 ID3D11Device *device;
176 ID3D11DeviceContext *context;
177 IDXGISwapChain *swapchain;
178 ID3D11Texture2D *back_buffer;
179 ID3D11Texture2D *depth_buffer;
180 ID3D11RenderTargetView *render_target;
181 ID3D11DepthStencilView *depth_view;
190 ID3D11RasterizerState *render_state;
191 ID3D11RasterizerState *render_state_wireframe;
195 IDirect3DDevice9 *device;
196 D3DPRESENT_PARAMETERS d3dpp;
197 LPDIRECT3DVERTEXDECLARATION9 vertex_decl;
202 unsigned char clear_r;
203 unsigned char clear_g;
204 unsigned char clear_b;
210 static const int QUEUE_SLOT_COUNT = 3;
212 VkInstance vk_instance = VK_NULL_HANDLE;
213 VkDevice vk_device = VK_NULL_HANDLE;
216 VkSemaphore renderingCompleteSemaphore;
217 VkSemaphore imageAcquiredSemaphore;
218 VkDebugReportCallbackEXT callback;
221 VkDeviceMemory deviceMemory_ = VK_NULL_HANDLE;
222 VkBuffer vertexBuffer_ = VK_NULL_HANDLE;
223 VkBuffer indexBuffer_ = VK_NULL_HANDLE;
225 VkDeviceMemory uploadMemory_ = VK_NULL_HANDLE;
226 VkBuffer uploadBuffer_ = VK_NULL_HANDLE;
228 VkShaderModule vertexShader_ = VK_NULL_HANDLE;
229 VkShaderModule fragmentShader_ = VK_NULL_HANDLE;
231 VkPipeline pipeline_ = VK_NULL_HANDLE;
232 VkPipelineLayout pipelineLayout_ = VK_NULL_HANDLE;
234 VkDeviceMemory deviceImageMemory_ = VK_NULL_HANDLE;
235 VkImage Image_ = VK_NULL_HANDLE;
236 VkImageView ImageView_ = VK_NULL_HANDLE;
238 VkDeviceMemory uploadImageMemory_ = VK_NULL_HANDLE;
239 VkBuffer uploadImageBuffer_ = VK_NULL_HANDLE;
241 VkDescriptorPool descriptorPool_ = VK_NULL_HANDLE;
242 VkDescriptorSet descriptorSet_ = VK_NULL_HANDLE;
243 VkDescriptorSetLayout descriptorSetLayout_ = VK_NULL_HANDLE;
245 VkSampler sampler_ = VK_NULL_HANDLE;
247 VkViewport viewport_;
249 VkSwapchainKHR swapchain_ = VK_NULL_HANDLE;
250 VkPhysicalDevice physicalDevice_ = VK_NULL_HANDLE;
251 VkQueue queue_ = VK_NULL_HANDLE;
253 VkSurfaceKHR surface_ = VK_NULL_HANDLE;
255 VkFence frameFences_[QUEUE_SLOT_COUNT];
256 VkImage swapchainImages_[QUEUE_SLOT_COUNT];
257 VkImageView swapChainImageViews_[QUEUE_SLOT_COUNT];
258 VkFramebuffer framebuffer_[QUEUE_SLOT_COUNT];
260 VkRenderPass renderPass_ = VK_NULL_HANDLE;
262 int queueFamilyIndex_ = -1;
264 VkCommandPool commandPool_;
265 VkCommandBuffer commandBuffers_[QUEUE_SLOT_COUNT];
266 VkCommandBuffer setupCommandBuffer_;
267 uint32_t currentBackBuffer_ = 0;
276 int init(
Graphics *gfx,
char *vertex_file,
char *geometry_file,
char *fragment_file);
287 ID3D11InputLayout *layout;
288 ID3D11VertexShader *vertex_shader;
289 ID3D11PixelShader *fragment_shader;
292 IDirect3DVertexShader9 *vertex_shader;
293 IDirect3DPixelShader9 *pixel_shader;
295 LPD3DXCONSTANTTABLE uniform_vs;
296 LPD3DXCONSTANTTABLE uniform_ps;