CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Common/Draw2D.h
Views: 1401
#pragma once12#include "GPU/GPU.h"3#include "Common/GPU/Shader.h"45// For framebuffer copies and similar things that just require passthrough.6struct Draw2DVertex {7float x;8float y;9float u;10float v;11};1213enum Draw2DShader {14DRAW2D_COPY_COLOR,15DRAW2D_COPY_DEPTH,16DRAW2D_ENCODE_R16_TO_DEPTH,17DRAW2D_565_TO_DEPTH,18DRAW2D_565_TO_DEPTH_DESWIZZLE,19DRAW2D_COPY_COLOR_RECT2LIN,20};2122inline RasterChannel Draw2DSourceChannel(Draw2DShader shader) {23switch (shader) {24case DRAW2D_COPY_DEPTH:25return RASTER_DEPTH;26case DRAW2D_COPY_COLOR:27case DRAW2D_ENCODE_R16_TO_DEPTH:28case DRAW2D_565_TO_DEPTH:29case DRAW2D_565_TO_DEPTH_DESWIZZLE:30default:31return RASTER_COLOR;32}33}3435struct Draw2DPipelineInfo {36const char *tag;37RasterChannel readChannel;38RasterChannel writeChannel;39Slice<SamplerDef> samplers;40};4142extern const UniformDef g_draw2Duniforms[5];4344struct Draw2DPipeline {45Draw::Pipeline *pipeline;46Draw2DPipelineInfo info;47char *code;48void Release() {49pipeline->Release();50delete[] code;51delete this;52}53};5455class ShaderWriter;5657class Draw2D {58public:59Draw2D(Draw::DrawContext *draw) : draw_(draw) {}60void DeviceLost();61void DeviceRestore(Draw::DrawContext *draw);6263Draw2DPipeline *Create2DPipeline(std::function<Draw2DPipelineInfo(ShaderWriter &)> generate);6465void DrawStrip2D(Draw::Texture *tex, const Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DPipeline *pipeline, float texW = 0.0f, float texH = 0.0f, int scaleFactor = 0);6667void Blit(Draw2DPipeline *pipeline, float srcX1, float srcY1, float srcX2, float srcY2, float dstX1, float dstY1, float dstX2, float dstY2, float srcWidth, float srcHeight, float dstWidth, float dstHeight, bool linear, int scaleFactor);68void Ensure2DResources();6970private:71Draw::DrawContext *draw_;7273Draw::SamplerState *draw2DSamplerLinear_ = nullptr;74Draw::SamplerState *draw2DSamplerNearest_ = nullptr;75Draw::ShaderModule *draw2DVs_ = nullptr;76};777879