Skip to content

Commit

Permalink
Do not allocate memory in DX9 implementation of ImGui_CreateTextureRG…
Browse files Browse the repository at this point in the history
…BA()
  • Loading branch information
danielkrupinski committed Apr 28, 2021
1 parent 28828ab commit 874d787
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Osiris/imgui/imgui_impl_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX9_RenderDrawData() in the .h file so you can call it yourself.
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.

#include <memory>

#include "imgui.h"
#include "imgui_impl_dx9.h"

Expand Down Expand Up @@ -289,19 +287,18 @@ void* ImGui_CreateTextureRGBA(int width, int height, const unsigned char* data)
return nullptr;
}

const auto buffer = std::make_unique_for_overwrite<std::uint32_t[]>(width * height);
std::memcpy(buffer.get(), data, width * height * 4);
for (int y = 0; y < height; ++y) {
const auto dest = reinterpret_cast<std::uint32_t*>((unsigned char*)lockedRect.pBits + lockedRect.Pitch * y);
std::memcpy(dest, data + width * 4 * y, width * 4);

for (int i = 0; i < width * height; ++i) {
// RGBA --> BGRA
auto color = buffer[i];
color = (color & 0xFF00FF00) | ((color & 0xFF0000) >> 16) | ((color & 0xFF) << 16);
buffer[i] = color;
for (int i = 0; i < width; ++i) {
// RGBA --> BGRA
auto color = dest[i];
color = (color & 0xFF00FF00) | ((color & 0xFF0000) >> 16) | ((color & 0xFF) << 16);
dest[i] = color;
}
}

for (int y = 0; y < height; ++y)
std::memcpy((unsigned char*)lockedRect.pBits + lockedRect.Pitch * y, buffer.get() + width * y, width * 4);

tempTexture->UnlockRect(0);

IDirect3DTexture9* texture;
Expand Down

0 comments on commit 874d787

Please sign in to comment.