*noises of anguish*
This commit is contained in:
parent
308bfeaff8
commit
8a6bc0ed61
54
source/app.d
54
source/app.d
|
@ -159,8 +159,8 @@ struct PixelBuffer {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
//linearly interpolate between pixels, MIN if texture is too small for drawing area, MAG if drawing area is smaller than texture
|
//linearly interpolate between pixels, MIN if texture is too small for drawing area, MAG if drawing area is smaller than texture
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
//texture type, level, format to store as, width, height, border, format loaded in
|
//texture type, level, format to store as, width, height, border, format loaded in
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, input_format_, width_, height_, 0, output_format_, data_type_, pixels);
|
glTexImage2D(GL_TEXTURE_2D, 0, input_format_, width_, height_, 0, output_format_, data_type_, pixels);
|
||||||
|
@ -205,7 +205,7 @@ struct PixelBuffer {
|
||||||
void update(void[] pixels, size_t offset = 0) {
|
void update(void[] pixels, size_t offset = 0) {
|
||||||
|
|
||||||
bind(0);
|
bind(0);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, cast(GLintptr)offset, pixels.length, pixels.ptr);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, input_format_, data_type_, pixels.ptr);
|
||||||
unbind();
|
unbind();
|
||||||
|
|
||||||
} // update
|
} // update
|
||||||
|
@ -241,13 +241,14 @@ struct PixelBuffer {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertices.length * vertices[0].sizeof, vertices.ptr, draw_type);
|
glBufferData(GL_ARRAY_BUFFER, vertices.length * vertices[0].sizeof, vertices.ptr, draw_type);
|
||||||
|
|
||||||
|
// pos
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0,
|
glVertexAttribPointer(0,
|
||||||
vertices[0].length,
|
2,
|
||||||
GL_FLOAT,
|
GL_FLOAT,
|
||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
vertices[0].sizeof,
|
float.sizeof * 2,
|
||||||
vertices.ptr
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
@ -280,13 +281,12 @@ struct PixelBuffer {
|
||||||
uniform vec2 screen_size;
|
uniform vec2 screen_size;
|
||||||
|
|
||||||
layout(location = 0) in vec2 pos;
|
layout(location = 0) in vec2 pos;
|
||||||
layout(location = 1) in vec2 uv;
|
|
||||||
|
|
||||||
out vec2 frag_uv;
|
out vec2 frag_uv;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
frag_uv = uv;
|
gl_Position = vec4(pos, 0.0, 1.0);
|
||||||
gl_Position = vec4(pos, 0.0, 0.0);
|
frag_uv = clamp(pos, vec2(0.0, 0.0), vec2(1.0, 1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -301,7 +301,9 @@ struct PixelBuffer {
|
||||||
out vec4 out_col;
|
out vec4 out_col;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
out_col = texture(tex, frag_uv.st);
|
float v = texture(tex, frag_uv.st).r;
|
||||||
|
out_col = vec4(v, v, v, 1.0);
|
||||||
|
// out_col = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -313,17 +315,17 @@ struct PixelBuffer {
|
||||||
void create(void* pixels, int w, int h) {
|
void create(void* pixels, int w, int h) {
|
||||||
|
|
||||||
float[2][6] rect = [
|
float[2][6] rect = [
|
||||||
[0.0f, 0.0f], // top left
|
[-1.0f, -1.0f], // top left
|
||||||
[1.0f, 0.0f], // top right
|
[1.0f, -1.0f], // top right
|
||||||
[1.0f, 1.0f], // bottom right
|
[1.0f, 1.0f], // bottom right
|
||||||
|
|
||||||
[0.0f, 0.0f], // top left
|
[-1.0f, -1.0f], // top left
|
||||||
[0.0f, 1.0f], // bottom left
|
[-1.0f, 1.0f], // bottom left
|
||||||
[1.0f, 1.0f], // bottom right
|
[1.0f, 1.0f], // bottom right
|
||||||
];
|
];
|
||||||
|
|
||||||
vao.create(rect[]);
|
vao.create(rect[]);
|
||||||
tex.create(pixels, w, h);
|
tex.create(pixels, w, h, GL_RED, GL_RED);
|
||||||
shader.compile(&vs_shader, &fs_shader);
|
shader.compile(&vs_shader, &fs_shader);
|
||||||
|
|
||||||
} // create
|
} // create
|
||||||
|
@ -338,6 +340,11 @@ struct PixelBuffer {
|
||||||
|
|
||||||
} // draw
|
} // draw
|
||||||
|
|
||||||
|
nothrow @nogc
|
||||||
|
void update(void[] pixels, size_t offset = 0) {
|
||||||
|
tex.update(pixels, offset);
|
||||||
|
} // update
|
||||||
|
|
||||||
} // PixelBuffer
|
} // PixelBuffer
|
||||||
|
|
||||||
struct Chip8Status {
|
struct Chip8Status {
|
||||||
|
@ -637,7 +644,7 @@ struct Chip8 {
|
||||||
switch (cpu.opcode & 0x0FFF) {
|
switch (cpu.opcode & 0x0FFF) {
|
||||||
|
|
||||||
case 0x00E0: // 0x00E0 Clears the screen.
|
case 0x00E0: // 0x00E0 Clears the screen.
|
||||||
// screen_buf[0..$] = 0;
|
screen_buf[0..$] = 0;
|
||||||
draw_flag = true;
|
draw_flag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1005,11 +1012,14 @@ struct Emulator {
|
||||||
// setup debug ui
|
// setup debug ui
|
||||||
status.initialize(&this, &emu);
|
status.initialize(&this, &emu);
|
||||||
|
|
||||||
// set up pixel buffer to poke at
|
// debug data
|
||||||
emu.screen_data[0][] = 255;
|
emu.screen_buf[0] = 255;
|
||||||
buf.create(emu.screen_data.ptr, 64, 32);
|
emu.screen_buf[64 - 1] = 255;
|
||||||
|
emu.screen_buf[64*32 - 64] = 255;
|
||||||
|
emu.screen_buf[64*32 - 1] = 255;
|
||||||
|
|
||||||
emu.screen_buf[] = 255;
|
// set up pixel buffer to poke a
|
||||||
|
buf.create(emu.screen_buf.ptr, 64, 32);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,6 +1071,10 @@ struct Emulator {
|
||||||
int w, h;
|
int w, h;
|
||||||
window.windowSize(w, h);
|
window.windowSize(w, h);
|
||||||
|
|
||||||
|
if (emu.draw_flag) {
|
||||||
|
buf.update(emu.screen_buf);
|
||||||
|
}
|
||||||
|
|
||||||
buf.draw(w, h);
|
buf.draw(w, h);
|
||||||
imgui.newFrame(window);
|
imgui.newFrame(window);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue