mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-27 16:29:02 +08:00
WIP Backends: SDLRenderer3: transform vertices manually.
This commit is contained in:
parent
8d5c79096f
commit
bbf2cd28b1
@ -53,7 +53,8 @@ struct ImGui_ImplSDLRenderer3_Data
|
|||||||
{
|
{
|
||||||
SDL_Renderer* Renderer; // Main viewport's renderer
|
SDL_Renderer* Renderer; // Main viewport's renderer
|
||||||
SDL_Texture* FontTexture;
|
SDL_Texture* FontTexture;
|
||||||
ImVector<SDL_FColor> ColorBuffer;
|
ImVector<SDL_FColor> ColorBuffer; // Transformed color buffer
|
||||||
|
ImVector<ImVec2> PosBuffer; // Transformed pos buffer (for multi-viewports only)
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
ImGui_ImplSDLRenderer3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
};
|
};
|
||||||
@ -216,13 +217,32 @@ void ImGui_ImplSDLRenderer3_RenderDrawData(ImDrawData* draw_data, SDL_Renderer*
|
|||||||
SDL_SetRenderClipRect(renderer, &r);
|
SDL_SetRenderClipRect(renderer, &r);
|
||||||
|
|
||||||
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, pos));
|
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, pos));
|
||||||
|
int xy_stride = (int)sizeof(ImDrawVert);
|
||||||
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, uv));
|
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, uv));
|
||||||
const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.19+
|
const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, col)); // SDL 2.0.19+
|
||||||
|
|
||||||
|
// FIXME-OPT: Transform position manually
|
||||||
|
// FIXME-OPT: Note that SDL_RenderGeometryRaw() does another transform for colors..
|
||||||
|
if (draw_data->DisplayPos.x != 0.0f || draw_data->DisplayPos.y != 0.0f)
|
||||||
|
{
|
||||||
|
const float off_x = draw_data->DisplayPos.x;
|
||||||
|
const float off_y = draw_data->DisplayPos.y;
|
||||||
|
bd->PosBuffer.resize(pcmd->ElemCount);
|
||||||
|
const ImDrawVert* p_in = vtx_buffer + pcmd->VtxOffset;
|
||||||
|
ImVec2* p_out = bd->PosBuffer.Data;
|
||||||
|
for (int remaining = pcmd->ElemCount; remaining > 0; remaining--, p_out++, p_in++)
|
||||||
|
{
|
||||||
|
p_out->x = p_in->pos.x - off_x;
|
||||||
|
p_out->y = p_in->pos.y - off_y;
|
||||||
|
}
|
||||||
|
xy = (const float*)bd->PosBuffer.Data;
|
||||||
|
xy_stride = (int)sizeof(ImVec2);
|
||||||
|
}
|
||||||
|
|
||||||
// Bind texture, Draw
|
// Bind texture, Draw
|
||||||
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
||||||
SDL_RenderGeometryRaw8BitColor(renderer, bd->ColorBuffer, tex,
|
SDL_RenderGeometryRaw8BitColor(renderer, bd->ColorBuffer, tex,
|
||||||
xy, (int)sizeof(ImDrawVert),
|
xy, xy_stride,
|
||||||
color, (int)sizeof(ImDrawVert),
|
color, (int)sizeof(ImDrawVert),
|
||||||
uv, (int)sizeof(ImDrawVert),
|
uv, (int)sizeof(ImDrawVert),
|
||||||
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
||||||
|
Loading…
Reference in New Issue
Block a user