Skip to content

Commit

Permalink
Mostly adjust G4onG5 for Kong
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 5, 2023
1 parent b47d8d8 commit 38a45d0
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,38 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) {
kinc_g5_command_list_set_index_buffer(&commandList, g5_index_buffer);
}

#ifdef KINC_KONG
void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) {
if (!texture->impl._uploaded) {
kinc_g5_command_list_upload_texture(&commandList, &texture->impl._texture);
texture->impl._uploaded = true;
}

assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT);
kinc_g5_texture_unit_t g5_unit;
for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) {
g5_unit.stages[i] = unit;
}

bool found = false;
for (int i = 0; i < current_state.texture_count; ++i) {
if (kinc_g5_texture_unit_equals(&current_state.texture_units[i], &g5_unit)) {
current_state.textures[i] = &texture->impl._texture;
current_state.texture_units[i] = g5_unit;
found = true;
break;
}
}
if (!found) {
assert(current_state.texture_count < MAX_TEXTURES);
current_state.textures[current_state.texture_count] = &texture->impl._texture;
current_state.texture_units[current_state.texture_count] = g5_unit;
current_state.texture_count += 1;
}

kinc_g5_command_list_set_texture(&commandList, g5_unit, &texture->impl._texture);
}
#else
void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {
if (!texture->impl._uploaded) {
kinc_g5_command_list_upload_texture(&commandList, &texture->impl._texture);
Expand Down Expand Up @@ -649,6 +681,7 @@ void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture

kinc_g5_command_list_set_texture(&commandList, g5_unit, &texture->impl._texture);
}
#endif

void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {}

Expand Down Expand Up @@ -709,6 +742,38 @@ bool kinc_g4_render_targets_inverted_y(void) {
return kinc_g5_render_targets_inverted_y();
}

#ifdef KINC_KONG
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_target, uint32_t unit) {
if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) {
kinc_g5_command_list_render_target_to_texture_barrier(&commandList, &render_target->impl._renderTarget);
render_target->impl.state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE;
}

assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT);
kinc_g5_texture_unit_t g5_unit;
for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) {
g5_unit.stages[i] = unit;
}

bool found = false;
for (int i = 0; i < current_state.render_target_count; ++i) {
if (kinc_g5_texture_unit_equals(&current_state.render_target_units[i], &g5_unit)) {
current_state.render_targets[i] = &render_target->impl._renderTarget;
current_state.render_target_units[i] = g5_unit;
found = true;
break;
}
}
if (!found) {
assert(current_state.render_target_count < MAX_TEXTURES);
current_state.render_targets[current_state.render_target_count] = &render_target->impl._renderTarget;
current_state.render_target_units[current_state.render_target_count] = g5_unit;
current_state.render_target_count += 1;
}

kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, &render_target->impl._renderTarget);
}
#else
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_target, kinc_g4_texture_unit_t unit) {
if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) {
kinc_g5_command_list_render_target_to_texture_barrier(&commandList, &render_target->impl._renderTarget);
Expand Down Expand Up @@ -737,6 +802,7 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_

kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, &render_target->impl._renderTarget);
}
#endif

void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *render_target, kinc_g4_texture_unit_t unit) {
if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifdef KINC_KONG

#include <kinc/graphics4/constantbuffer.h>

void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) {
kinc_g5_constant_buffer_init(&buffer->impl.buffer, (int)size);
}

void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) {
kinc_g5_constant_buffer_destroy(&buffer->impl.buffer);
}

uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) {
kinc_g5_constant_buffer_lock_all(&buffer->impl.buffer);
return buffer->impl.buffer.data;
}

uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) {
kinc_g5_constant_buffer_lock(&buffer->impl.buffer, (int)start, (int)size);
return buffer->impl.buffer.data;
}

void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) {
kinc_g5_constant_buffer_unlock(&buffer->impl.buffer);
}

void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) {
kinc_g5_constant_buffer_unlock(&buffer->impl.buffer);
}

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

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

#ifdef KINC_KONG

#include <kinc/graphics5/constantbuffer.h>

typedef struct kinc_g4_constant_buffer_impl {
kinc_g5_constant_buffer_t buffer;
} kinc_g4_constant_buffer_impl;

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "samplers.c.h"

#include "G4.c.h"
#include "constantbuffer.c.h"
#include "indexbuffer.c.h"
#include "pipeline.c.h"
#include "rendertarget.c.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void kinc_g4_pipeline_destroy(kinc_g4_pipeline_t *pipe) {
kinc_g5_pipeline_destroy(&pipe->impl._pipeline);
}

#ifndef KINC_KONG
kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(kinc_g4_pipeline_t *pipe, const char *name) {
kinc_g4_constant_location_t location;
location.impl._location = kinc_g5_pipeline_get_constant_location(&pipe->impl._pipeline, name);
Expand All @@ -28,6 +29,7 @@ kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *pip

return g4_unit;
}
#endif

void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *pipe) {
for (int i = 0; i < 16; ++i) {
Expand Down

0 comments on commit 38a45d0

Please sign in to comment.