Skip to content

Commit

Permalink
Fix Kong compilation for D3D9
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 5, 2023
1 parent 708b5b4 commit 3cdf439
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,19 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) {
kinc_internal_g4_index_buffer_set(buffer);
}

#ifdef KINC_KONG
void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit);

void kinc_g4_set_texture(uint32_t unit, struct kinc_g4_texture *texture) {
kinc_internal_texture_set(texture, unit);
}
#else
void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit);

void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture) {
kinc_internal_texture_set(texture, unit);
}
#endif

void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture) {}

Expand Down Expand Up @@ -829,3 +837,5 @@ bool kinc_g4_supports_non_pow2_textures() {
bool kinc_g4_render_targets_inverted_y(void) {
return false;
}

void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifdef KINC_KONG

#include <kinc/graphics4/constantbuffer.h>

#include "Direct3D9.h"

void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) {
buffer->impl.size = size;
buffer->impl.last_start = 0;
buffer->impl.last_size = size;
}

void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) {}

uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) {
return NULL;
}

uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) {
buffer->impl.last_start = start;
buffer->impl.last_size = size;

return NULL;
}

void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) {}

void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) {}

size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) {
return buffer->impl.size;
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef KINC_KONG

typedef struct kinc_g4_constant_buffer_impl {
size_t size;
size_t last_start;
size_t last_size;
} kinc_g4_constant_buffer_impl;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) {
}
}

#ifdef KINC_KONG
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit) {
if (renderTarget->impl.antialiasing) {
IDirect3DSurface9 *surface;
renderTarget->impl.colorTexture->GetSurfaceLevel(0, &surface);
kinc_microsoft_affirm(device->StretchRect(renderTarget->impl.colorSurface, nullptr, surface, nullptr, D3DTEXF_NONE));
surface->Release();
}
device->SetTexture(unit, renderTarget->isDepthAttachment ? renderTarget->impl.depthTexture : renderTarget->impl.colorTexture);
}
#else
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
if (renderTarget->impl.antialiasing) {
IDirect3DSurface9 *surface;
Expand All @@ -100,6 +111,7 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderT
device->SetTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT],
renderTarget->isDepthAttachment ? renderTarget->impl.depthTexture : renderTarget->impl.colorTexture);
}
#endif

void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source) {
renderTarget->impl.depthTexture = source->impl.depthTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ void kinc_g4_texture_destroy(kinc_g4_texture_t *texture) {
texture->impl.texture->Release();
}

#ifdef KINC_KONG
void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit) {
kinc_microsoft_affirm(device->SetTexture(unit, texture->impl.texture));
texture->impl.stage = unit;
setTextures[texture->impl.stage] = texture;
}
#else
void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) {
kinc_microsoft_affirm(device->SetTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], texture->impl.texture));
texture->impl.stage = unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT];
setTextures[texture->impl.stage] = texture;
}
#endif

void kinc_internal_texture_unset(struct kinc_g4_texture *texture) {
if (setTextures[texture->impl.stage] == texture) {
Expand Down

0 comments on commit 3cdf439

Please sign in to comment.