| 1 |
// By Emil Ernerfeldt 2018 |
| 2 |
// LICENSE: |
| 3 |
// This software is dual-licensed to the public domain and under the following |
| 4 |
// license: you are granted a perpetual, irrevocable license to copy, modify, |
| 5 |
// publish, and distribute this file as you see fit. |
| 6 |
// WHAT: |
| 7 |
// This is a software renderer for Dear ImGui. |
| 8 |
// It is decently fast, but has a lot of room for optimization. |
| 9 |
// The goal was to get something fast and decently accurate in not too many lines of code. |
| 10 |
// LIMITATIONS: |
| 11 |
// * It is not pixel-perfect, but it is good enough for must use cases. |
| 12 |
// * It does not support texture scaling for the sake of performance. |
| 13 |
#pragma once |
| 14 |
#include "imgui.h" // IMGUI_IMPL_API |
| 15 |
#ifndef IMGUI_DISABLE |
| 16 |
|
| 17 |
#include <cstdint> |
| 18 |
|
| 19 |
struct SDL_Window; |
| 20 |
struct ImDrawData; |
| 21 |
|
| 22 |
struct SWTexture |
| 23 |
{ |
| 24 |
uint32_t* pixels; |
| 25 |
int width; |
| 26 |
int height; |
| 27 |
bool managed, isAlpha; |
| 28 |
|
| 29 |
SWTexture(uint32_t* pix, int w, int h, bool a=false): |
| 30 |
pixels(pix), |
| 31 |
width(w), |
| 32 |
height(h), |
| 33 |
managed(false), |
| 34 |
isAlpha(a) {} |
| 35 |
SWTexture(int w, int h, bool a=false): |
| 36 |
width(w), |
| 37 |
height(h), |
| 38 |
managed(true), |
| 39 |
isAlpha(a) { |
| 40 |
pixels=new uint32_t[width*height]; |
| 41 |
memset(pixels,0,width*height*sizeof(uint32_t)); |
| 42 |
} |
| 43 |
~SWTexture() { |
| 44 |
if (managed) delete[] pixels; |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
IMGUI_IMPL_API bool ImGui_ImplSW_Init(SDL_Window* win); |
| 49 |
IMGUI_IMPL_API void ImGui_ImplSW_Shutdown(); |
| 50 |
IMGUI_IMPL_API void ImGui_ImplSW_NewFrame(); |
| 51 |
IMGUI_IMPL_API void ImGui_ImplSW_RenderDrawData(ImDrawData* draw_data); |
| 52 |
|
| 53 |
// Called by Init/NewFrame/Shutdown |
| 54 |
IMGUI_IMPL_API bool ImGui_ImplSW_CreateDeviceObjects(); |
| 55 |
IMGUI_IMPL_API void ImGui_ImplSW_DestroyDeviceObjects(); |
| 56 |
|
| 57 |
// for Dear ImGui 1.92+ |
| 58 |
IMGUI_IMPL_API void ImGui_ImplSW_UpdateTexture(ImTextureData* tex); |
| 59 |
|
| 60 |
#endif // #ifndef IMGUI_DISABLE |