Skip to content

Commit

Permalink
Initial support for remote textures
Browse files Browse the repository at this point in the history
For now limited to a single texture which is actually used
for the font Atlas. With this we do not need to regenerate the
texture.png every time we change the configuration of the fonts.
  • Loading branch information
ktf committed Mar 10, 2023
1 parent 43cf03f commit a8e04e6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
3 changes: 2 additions & 1 deletion DebugGUI/src/DebugGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void default_error_callback(int, const char*);

void* initGUI(const char* name, decltype(default_error_callback) = nullptr);
bool pollGUI(void *context, std::function<void(void)> guiCallback);
void getFrameRaw(void *data, void **raw_data, int *size);
void getFrameRaw(void *data, void **raw_data, int *size,
bool includeTextures = false);
bool pollGUIPreRender(void* context, float delta);
void* pollGUIRender(std::function<void(void)> guiCallback);
void pollGUIPostRender(void* context, void* draw_data);
Expand Down
38 changes: 36 additions & 2 deletions DebugGUI/src/DebugGUIHeadless.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ struct __attribute__((packed)) FrameInfo {
int vtx_count = 0;
int idx_count = 0;
int cmd_count = 0;
int txt_count = 0; // How many textures are there
};

struct __attribute__((packed)) vtxContainer {
float posX, posY, uvX, uvY;
int col;
};

// Texture information
struct __attribute__((packed)) txtHeader {
int width, height; /// Size of the texture, in pixels
int format; /// Format of the texture, 0 = RGBA, 1 = RGB, 2 = Luminance
int size; /// Size in bytes of the texture
int id; /// Id of the texture
};

struct __attribute__((packed)) cmdContainer {
int list_id;
int cmd_id;
Expand All @@ -32,12 +41,12 @@ struct __attribute__((packed)) cmdContainer {
// ready to be sent and its size.
// the returned buffer must be freed by the caller.
/// FIXME: document actual schema of the format
void getFrameRaw(void *data, void **raw_data, int *size) {
void getFrameRaw(void *data, void **raw_data, int *size, bool includeTextures) {
auto *draw_data = (ImDrawData *)data;
FrameInfo frameInfo;

// compute sizes
int buffer_size = sizeof(int) * 3;
int buffer_size = sizeof(int) * 4;
for (int cmd_id = 0; cmd_id < draw_data->CmdListsCount; ++cmd_id) {
const auto cmd_list = draw_data->CmdLists[cmd_id];

Expand All @@ -51,6 +60,14 @@ void getFrameRaw(void *data, void **raw_data, int *size) {
buffer_size += cmd_list->CmdBuffer.size() * (sizeof(cmdContainer));
}

// For now this only includes the font atlas in RGBA32 format
if (includeTextures) {
frameInfo.txt_count += 1;
ImGuiIO &io = ImGui::GetIO();
ImFontAtlas *atlas = io.Fonts;
buffer_size += (sizeof(txtHeader)) + atlas->TexWidth * atlas->TexHeight * 4;
}

void *local_data_base = (char *)malloc(buffer_size);
char *ptr = (char *)local_data_base;

Expand Down Expand Up @@ -99,6 +116,23 @@ void getFrameRaw(void *data, void **raw_data, int *size) {
idxBase += cmd_list->IdxBuffer.size();
}

// For now we only include the font atlas
if (includeTextures) {
ImGuiIO &io = ImGui::GetIO();
ImFontAtlas *atlas = io.Fonts;
txtHeader header;
header.width = atlas->TexWidth;
header.height = atlas->TexHeight;
header.format = 0;
header.size = atlas->TexWidth * atlas->TexHeight * 4;

header.id = 0;
memcpy(ptr, &header, sizeof(txtHeader));
ptr += sizeof(txtHeader);
memcpy(ptr, atlas->TexPixelsRGBA32, header.size);
ptr += header.size;
}

*size = buffer_size;
*raw_data = local_data_base;
}
Expand Down
41 changes: 23 additions & 18 deletions remote/remote.html

Large diffs are not rendered by default.

0 comments on commit a8e04e6

Please sign in to comment.