359 {
360
361 Shader *vertexShader = $(self->
device, loadShader,
"Renderer.vert", &(SDL_GPUShaderCreateInfo) {
362 .stage = SDL_GPU_SHADERSTAGE_VERTEX,
363 .num_uniform_buffers = 1,
364 });
365
366 Shader *fragmentShader = $(self->
device, loadShader,
"Renderer.frag", &(SDL_GPUShaderCreateInfo) {
367 .stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
368 .num_samplers = 1,
369 });
370
371 const SDL_GPUVertexBufferDescription vertexBufferInfo = {
372 .slot = 0,
374 .input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
375 .instance_step_rate = 0,
376 };
377
378 const SDL_GPUColorTargetDescription colorTarget = {
379 .format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
380 .blend_state = {
381 .enable_blend = true,
382 .color_blend_op = SDL_GPU_BLENDOP_ADD,
383 .alpha_blend_op = SDL_GPU_BLENDOP_ADD,
384 .src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
385 .dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
386 .src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
387 .dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
388 },
389 };
390
391 const SDL_GPUGraphicsPipelineCreateInfo pipelineInfo = {
392 .vertex_shader = vertexShader->shader,
393 .fragment_shader = fragmentShader->shader,
394 .vertex_input_state = {
395 .vertex_buffer_descriptions = &vertexBufferInfo,
396 .num_vertex_buffers = 1,
397 .vertex_attributes = (SDL_GPUVertexAttribute[]) {
398 {
399 .location = 0,
400 .buffer_slot = 0,
401 .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
403 },
404 {
405 .location = 1,
406 .buffer_slot = 0,
407 .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
409 },
410 {
411 .location = 2,
412 .buffer_slot = 0,
413 .format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM,
415 },
416 },
417 .num_vertex_attributes = 3,
418 },
419 .primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
420 .rasterizer_state = {
421 .fill_mode = SDL_GPU_FILLMODE_FILL,
422 .cull_mode = SDL_GPU_CULLMODE_NONE,
423 .front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
424 },
425 .target_info = {
426 .color_target_descriptions = &colorTarget,
427 .num_color_targets = 1,
428 },
429 };
430
431 self->pipeline = $(self->
device, createGraphicsPipeline, &pipelineInfo);
432
433 release(vertexShader);
434 release(fragmentShader);
435
436 self->sampler = $(self->
device, createSampler, &(
const SDL_GPUSamplerCreateInfo) {
437 .min_filter = SDL_GPU_FILTER_LINEAR,
438 .mag_filter = SDL_GPU_FILTER_LINEAR,
439 .mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR,
440 .address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
441 .address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
442 .address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
443 });
444
445 const Uint8 white[4] = { 255, 255, 255, 255 };
446
447 self->white = $(self->
device, createTexture, &(
const SDL_GPUTextureCreateInfo) {
448 .type = SDL_GPU_TEXTURETYPE_2D,
449 .format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
450 .usage = SDL_GPU_TEXTUREUSAGE_SAMPLER,
451 .width = 1,
452 .height = 1,
453 .layer_count_or_depth = 1,
454 .num_levels = 1,
455 }, white);
456}