update Dear ImGui to 1.92.0, part 2
TODO: - testing - testing - testing - additional testing - extra testing and of course: - testing
This commit is contained in:
parent
11ecbebcdc
commit
ee7087b7a5
36 changed files with 245 additions and 741 deletions
116
extern/imgui_software_renderer/imgui_sw.cpp
vendored
116
extern/imgui_software_renderer/imgui_sw.cpp
vendored
|
|
@ -17,7 +17,6 @@
|
|||
struct ImGui_ImplSW_Data
|
||||
{
|
||||
SDL_Window* Window;
|
||||
SWTexture* FontTexture;
|
||||
|
||||
ImGui_ImplSW_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
|
@ -537,7 +536,7 @@ static void paint_draw_cmd(const PaintTarget &target,
|
|||
const ImDrawCmd &pcmd,
|
||||
const ImVec2& white_uv)
|
||||
{
|
||||
const SWTexture* texture = (const SWTexture*)(pcmd.TextureId);
|
||||
const SWTexture* texture = (const SWTexture*)(pcmd.GetTexID());
|
||||
IM_ASSERT(texture);
|
||||
|
||||
for (unsigned int i = 0; i + 3 <= pcmd.ElemCount;) {
|
||||
|
|
@ -647,7 +646,7 @@ static void paint_imgui(uint32_t *pixels, ImDrawData *drawData, int fb_width, in
|
|||
|
||||
bool ImGui_ImplSW_Init(SDL_Window* win) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuiIO& platform_io = ImGui::GetPlatformIO();
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
IM_ASSERT(io.BackendRendererUserData == nullptr);
|
||||
|
||||
if (SDL_HasWindowSurface(win)==SDL_FALSE) {
|
||||
|
|
@ -677,17 +676,22 @@ void ImGui_ImplSW_Shutdown() {
|
|||
IM_DELETE(bd);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSW_NewFrame() {
|
||||
void ImGui_ImplSW_NewFrame() {
|
||||
ImGui_ImplSW_Data* bd = ImGui_ImplSW_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplSW_RenderDrawData(ImDrawData* draw_data) {
|
||||
ImGui_ImplSW_Data* bd = ImGui_ImplSW_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr);
|
||||
|
||||
// update textures if needed
|
||||
if (draw_data->Textures!=NULL) {
|
||||
for (ImTextureData* i: *draw_data->Textures) {
|
||||
if (i->Status!=ImTextureStatus_OK) ImGui_ImplSW_UpdateTexture(i);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface* surf = SDL_GetWindowSurface(bd->Window);
|
||||
if (!surf) return;
|
||||
|
||||
|
|
@ -704,38 +708,84 @@ void ImGui_ImplSW_RenderDrawData(ImDrawData* draw_data) {
|
|||
|
||||
/// CREATE OBJECTS
|
||||
|
||||
bool ImGui_ImplSW_CreateFontsTexture() {
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
ImGui_ImplSW_Data* bd = ImGui_ImplSW_GetBackendData();
|
||||
|
||||
// Load default font (embedded in code):
|
||||
uint8_t *tex_data;
|
||||
int font_width, font_height;
|
||||
io.Fonts->GetTexDataAsAlpha8(&tex_data, &font_width, &font_height);
|
||||
SWTexture* texture = new SWTexture((uint32_t*)tex_data,font_width,font_height,true);
|
||||
io.Fonts->SetTexID((ImTextureID)texture);
|
||||
bd->FontTexture = texture;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplSW_DestroyFontsTexture() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplSW_Data* bd = ImGui_ImplSW_GetBackendData();
|
||||
if (bd->FontTexture)
|
||||
{
|
||||
delete bd->FontTexture;
|
||||
io.Fonts->SetTexID(0);
|
||||
bd->FontTexture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGui_ImplSW_CreateDeviceObjects() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplSW_DestroyDeviceObjects() {
|
||||
ImGui_ImplSW_DestroyFontsTexture();
|
||||
}
|
||||
|
||||
void ImGui_ImplSW_UpdateTexture(ImTextureData* tex) {
|
||||
if (tex->Status==ImTextureStatus_WantCreate) {
|
||||
SWTexture* t=new SWTexture(tex->Width,tex->Height,tex->Format==ImTextureFormat_Alpha8);
|
||||
memcpy(t->pixels,tex->GetPixels(),tex->GetSizeInBytes());
|
||||
|
||||
tex->SetTexID((ImTextureID)t);
|
||||
tex->SetStatus(ImTextureStatus_OK);
|
||||
} else if (tex->Status==ImTextureStatus_WantUpdates) {
|
||||
SWTexture* t=(SWTexture*)tex->GetTexID();
|
||||
|
||||
// we don't support format changes (this should not happen)
|
||||
assert(t->isAlpha==(tex->Format==ImTextureFormat_Alpha8));
|
||||
|
||||
if (t->width!=tex->Width || t->height!=tex->Height) {
|
||||
// width/height changed; recreate texture
|
||||
SWTexture* newTex=new SWTexture(tex->Width,tex->Height,tex->Format==ImTextureFormat_Alpha8);
|
||||
|
||||
// copy previous texture to new one
|
||||
int i_y=0;
|
||||
int i_y1=0;
|
||||
if (t->isAlpha) {
|
||||
for (int i=0; i<t->height; i++) {
|
||||
unsigned char* dataOld=(unsigned char*)t->pixels;
|
||||
unsigned char* dataNew=(unsigned char*)newTex->pixels;
|
||||
memcpy(&dataNew[i_y1],&dataOld[i_y],t->width);
|
||||
i_y1+=newTex->width;
|
||||
i_y+=t->width;
|
||||
}
|
||||
} else {
|
||||
for (int i=0; i<t->height; i++) {
|
||||
uint32_t* dataOld=t->pixels;
|
||||
uint32_t* dataNew=newTex->pixels;
|
||||
memcpy(&dataNew[i_y1],&dataOld[i_y],t->width*sizeof(uint32_t));
|
||||
i_y1+=newTex->width;
|
||||
i_y+=t->width;
|
||||
}
|
||||
}
|
||||
|
||||
// delete previous texture and change texture ID
|
||||
tex->SetTexID((ImTextureID)newTex);
|
||||
delete t;
|
||||
t=newTex;
|
||||
}
|
||||
|
||||
// update region
|
||||
if (t->isAlpha) {
|
||||
unsigned char* data=(unsigned char*)t->pixels;
|
||||
int i_y=t->width*tex->UpdateRect.y;
|
||||
for (int i=tex->UpdateRect.y; i<tex->UpdateRect.y+tex->UpdateRect.w; i++) {
|
||||
memcpy(&data[i_y],tex->GetPixelsAt(tex->UpdateRect.x,i),tex->UpdateRect.w);
|
||||
i_y+=t->width;
|
||||
}
|
||||
} else {
|
||||
uint32_t* data=t->pixels;
|
||||
int i_y=t->width*tex->UpdateRect.y;
|
||||
for (int i=tex->UpdateRect.y; i<tex->UpdateRect.y+tex->UpdateRect.w; i++) {
|
||||
memcpy(&data[i_y],tex->GetPixelsAt(tex->UpdateRect.x,i),tex->UpdateRect.w*sizeof(uint32_t));
|
||||
i_y+=t->width;
|
||||
}
|
||||
}
|
||||
|
||||
tex->SetStatus(ImTextureStatus_OK);
|
||||
} else if (tex->Status==ImTextureStatus_WantDestroy && tex->UnusedFrames>0) {
|
||||
SWTexture* t=(SWTexture*)tex->GetTexID();
|
||||
delete t;
|
||||
|
||||
tex->SetTexID(ImTextureID_Invalid);
|
||||
tex->SetStatus(ImTextureStatus_Destroyed);
|
||||
} else {
|
||||
// ????????
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue