Skip to content

Commit

Permalink
adding an buffering hit histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
steveschnepp committed Oct 16, 2023
1 parent d2155e1 commit 219ec69
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ddraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,14 @@ class Direct3D7Patched : public IDirect3D7
HRESULT STDMETHODCALLTYPE EvictManagedTextures();
};

void ddraw_buffer_histogram(Direct3DDevicePatched *device);

/* Implementation of the wrapper */
HRESULT Direct3DDevicePatched::BeginScene() { WRAP("%s:%d \t%s\n", __FILE__, __LINE__, __FUNCTION__);
return mWrapped->BeginScene(); }
HRESULT Direct3DDevicePatched::EndScene() { WRAP("%s:%d \t%s\n", __FILE__, __LINE__, __FUNCTION__);
ddraw_buffer_flush_if_needed(this);
ddraw_buffer_histogram(this);
return mWrapped->EndScene(); }

HRESULT Direct3DDevicePatched::GetCaps(D3DDEVICEDESC7 *desc) { WRAP("%s:%d \t%s\n", __FILE__, __LINE__, __FUNCTION__);
Expand Down Expand Up @@ -909,3 +912,51 @@ HRESULT Direct3DDevicePatched::ddraw_buffer_add(Direct3DDevicePatched *device, D
}
return E_NOTIMPL;
}

struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw;
DWORD color;
};

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
static DWORD D3DCOLOR_ARGB(char a, char r, char g, char b) {
DWORD d = 0;
d |= a << 0;
d |= r << 8;
d |= g << 16;
d |= b << 24;
return d;
}

// #define D3DCOLOR_ARGB(x, ...)

static float histogram[256] = {0};

void ddraw_buffer_histogram(Direct3DDevicePatched *device) {
static int histo_idx = -1;
histo_idx = (histo_idx + 1) % 256;
histogram[histo_idx] = device->vertex_batch.vertex_count;

CUSTOMVERTEX vertices[512];

for (int i = 0; i < 256; i ++) {
int vtx_idx = i*2;
vertices[vtx_idx].x = 0.0 + i;
vertices[vtx_idx].y = 0.0;
vertices[vtx_idx].z = -1.f;
vertices[vtx_idx].rhw = 1.f;
vertices[vtx_idx].color = D3DCOLOR_ARGB(255, 0, 255, 0);

vtx_idx ++;
vertices[vtx_idx].x = 0.f + i;
vertices[vtx_idx].y = 0.f + histogram[i];
vertices[vtx_idx].z = -1.f;
vertices[vtx_idx].rhw = 1.f;
vertices[vtx_idx].color = D3DCOLOR_ARGB(0, 0, 255, 0);
}

INFO("ddraw_buffer_histogram");

device->DrawPrimitiveUnbuffered(D3DPT_LINELIST, CUSTOMFVF, vertices, 512, NULL);
}

0 comments on commit 219ec69

Please sign in to comment.