385 {
386
387 Shader *vertexShader = $(self->
device, loadShader,
"Renderer.vert", &(SDL_GPUShaderCreateInfo) {
388 .stage = SDL_GPU_SHADERSTAGE_VERTEX,
389 .num_uniform_buffers = 1,
390 });
391
392 Shader *fragmentShader = $(self->
device, loadShader,
"Renderer.frag", &(SDL_GPUShaderCreateInfo) {
393 .stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
394 .num_samplers = 1,
395 });
396
397 const SDL_GPUVertexBufferDescription vertexBufferInfo = {
398 .slot = 0,
400 .input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
401 .instance_step_rate = 0,
402 };
403
404 const SDL_GPUColorTargetDescription colorTarget = {
405 .format = $(self->
device, getSwapchainTextureFormat),
406 .blend_state = {
407 .enable_blend = true,
408 .color_blend_op = SDL_GPU_BLENDOP_ADD,
409 .alpha_blend_op = SDL_GPU_BLENDOP_ADD,
410 .src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
411 .dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
412 .src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
413 .dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
414 },
415 };
416
417 const SDL_GPUGraphicsPipelineCreateInfo pipelineInfo = {
418 .vertex_shader = vertexShader->shader,
419 .fragment_shader = fragmentShader->shader,
420 .vertex_input_state = {
421 .vertex_buffer_descriptions = &vertexBufferInfo,
422 .num_vertex_buffers = 1,
423 .vertex_attributes = (SDL_GPUVertexAttribute[]) {
424 {
425 .location = 0,
426 .buffer_slot = 0,
427 .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
429 },
430 {
431 .location = 1,
432 .buffer_slot = 0,
433 .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
435 },
436 {
437 .location = 2,
438 .buffer_slot = 0,
439 .format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM,
441 },
442 },
443 .num_vertex_attributes = 3,
444 },
445 .primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
446 .rasterizer_state = {
447 .fill_mode = SDL_GPU_FILLMODE_FILL,
448 .cull_mode = SDL_GPU_CULLMODE_NONE,
449 .front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
450 },
451 .target_info = {
452 .color_target_descriptions = &colorTarget,
453 .num_color_targets = 1,
454 },
455 };
456
457 self->pipeline = $(self->
device, createGraphicsPipeline, &pipelineInfo);
458
459 release(vertexShader);
460 release(fragmentShader);
461
462 self->sampler = $(self->
device, createSampler, &(
const SDL_GPUSamplerCreateInfo) {
463 .min_filter = SDL_GPU_FILTER_LINEAR,
464 .mag_filter = SDL_GPU_FILTER_LINEAR,
465 .mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR,
466 .address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
467 .address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
468 .address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
469 });
470
471 const Uint8 white[4] = { 255, 255, 255, 255 };
472
473 self->white = $(self->
device, createTexture, &(
const SDL_GPUTextureCreateInfo) {
474 .type = SDL_GPU_TEXTURETYPE_2D,
475 .format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
476 .usage = SDL_GPU_TEXTUREUSAGE_SAMPLER,
477 .width = 1,
478 .height = 1,
479 .layer_count_or_depth = 1,
480 .num_levels = 1,
481 }, white);
482}