Thread Tools Display Modes
08-28-24, 01:19 AM   #1
tna0y
A Kobold Labourer
Join Date: Aug 2024
Posts: 1
Rendering a framebuffer

I am currently developing an addon that runs Doom inside WoW. It consists of two main parts: the addon containing the game and a CPU emulator.

Currently, the game runs at 2-4 FPS, depending on the hardware, and a significant portion of that time is spent rendering the framebuffer for each frame.

The game uses a 256-color palette and returns a buffer that is (W*H*1) bytes long. I have not found a better way than creating (W*H) "pixel" textures and setting them in a loop. While the loop itself is not extremely optimized, the majority of the time is spent on pixel:SetColorTexture

Lua Code:
  1. -- Renders the frame from the given framebuffer address.
  2. -- @param framebuffer_addr The address of the framebuffer to render.
  3. function Frame:RenderFrame(framebuffer_addr)
  4.     local read4 = self.CPU.memory:Read(4)
  5.     for x = 0, 320-1, 4 do
  6.         for y = 0, 200-1 do
  7.             local offset = y * 320 + x
  8.             local data = read4(framebuffer_addr + offset)
  9.  
  10.             for i=0,3 do
  11.                 local data_loc = data % 0x100
  12.                 local color = self.vga_to_rgb[data_loc]
  13.                 local pixel = self.pixels[offset + i + 1]
  14.                 if data_loc ~= pixel.color then
  15.                     pixel:SetColorTexture(unpack(color))
  16.                     pixel.color = data_loc
  17.                 end
  18.                 data = bit.rshift(data, 8)
  19.             end
  20.         end
  21.     end
  22. end

Please see the full source code on GitHub.

Could there be a faster way to achieve the desired result of rendering the framebuffer?

Current ideas:

* Pre-generate 256*256 2-pixel (2x1) textures to reduce the number of texture modification calls by half.
* I could potentially generate a BLP-compatible string pretty effectively, but there doesn’t seem to be a way to load a texture from a string.
  Reply With Quote

WoWInterface » Developer Discussions » Graphics Help » Rendering a framebuffer

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off