Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
3.8 kB · 111 lines
C++
at android
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112#include "PipelineBuilder.h"#include "../GPU.h"
PipelineBuilder& PipelineBuilder::Shaders(Shader* vertShader, Shader* fragShader){ this->vertShader = vertShader; this->fragShader = fragShader; return *this;}
PipelineBuilder& PipelineBuilder::Format(SDL_GPUTextureFormat format){ this->format = format; return *this;}
PipelineBuilder& PipelineBuilder::FormatSwapchain(){ this->format = GPU::GetSwapchainFormat(); return *this;}
PipelineBuilder& PipelineBuilder::Blend(SDL_GPUColorTargetBlendState blendState){ this->blendState = blendState; return *this;}
PipelineBuilder& PipelineBuilder::BlendPremultiplied(){ blendState = {}; blendState.alpha_blend_op = SDL_GPU_BLENDOP_ADD; blendState.color_blend_op = SDL_GPU_BLENDOP_ADD; blendState.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE; blendState.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE; blendState.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.enable_blend = true; return *this;}
PipelineBuilder& PipelineBuilder::BlendAlpha(){ blendState = {}; blendState.alpha_blend_op = SDL_GPU_BLENDOP_ADD; blendState.color_blend_op = SDL_GPU_BLENDOP_ADD; blendState.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE; blendState.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA; blendState.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.enable_blend = true; return *this;}
PipelineBuilder& PipelineBuilder::BlendErase(){ blendState = {}; blendState.alpha_blend_op = SDL_GPU_BLENDOP_ADD; blendState.color_blend_op = SDL_GPU_BLENDOP_ADD; blendState.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ZERO; blendState.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ZERO; blendState.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.enable_blend = true; return *this;}
PipelineBuilder& PipelineBuilder::BlendAlphaKeepColor(){ blendState = {}; blendState.alpha_blend_op = SDL_GPU_BLENDOP_ADD; blendState.color_blend_op = SDL_GPU_BLENDOP_ADD; blendState.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE; blendState.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ZERO; blendState.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; blendState.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE; blendState.enable_blend = true; return *this;}
PipelineBuilder& PipelineBuilder::Vertex(SDL_GPUVertexInputState vertexInputState){ this->vertexInputState = vertexInputState; return *this;}
PipelineBuilder& PipelineBuilder::Primitive(SDL_GPUPrimitiveType primitiveType){ this->primitiveType = primitiveType; return *this;}
GraphicsPipeline* PipelineBuilder::Build(){
SDL_GPUColorTargetDescription colorTargetDesciption = {}; colorTargetDesciption.format = format; colorTargetDesciption.blend_state = blendState; SDL_GPUGraphicsPipelineTargetInfo targetInfo = {}; targetInfo.num_color_targets = 1; targetInfo.color_target_descriptions = &colorTargetDesciption; SDL_GPUGraphicsPipelineCreateInfo createInfo = {}; createInfo.vertex_shader = vertShader->Get(); createInfo.fragment_shader = fragShader->Get(); createInfo.target_info = targetInfo; createInfo.vertex_input_state = vertexInputState; createInfo.primitive_type = primitiveType;
SDL_GPUGraphicsPipeline* pipeline = SDL_CreateGPUGraphicsPipeline(GPU::GetDevice(), &createInfo); return new GraphicsPipeline(pipeline);}