diff --git a/Kinc b/Kinc index 997f9c8fd..38bc2f29e 160000 --- a/Kinc +++ b/Kinc @@ -1 +1 @@ -Subproject commit 997f9c8fd49577ef5ff796af6464bf1dfb43b728 +Subproject commit 38bc2f29e720a0388e4b014090c6773111b9aec4 diff --git a/Sources/Kore/Compute/Compute.cpp b/Sources/Kore/Compute/Compute.cpp deleted file mode 100644 index 2f842119d..000000000 --- a/Sources/Kore/Compute/Compute.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "Compute.h" - -#include - -using namespace Kore; - -ComputeShader::ComputeShader(void *source, int length) { - kinc_compute_shader_init(&kincImpl, source, length); -} - -ComputeShader::~ComputeShader() { - kinc_compute_shader_destroy(&kincImpl); -} - -ComputeConstantLocation ComputeShader::getConstantLocation(const char *name) { - ComputeConstantLocation location; - location.kincImpl = kinc_compute_shader_get_constant_location(&kincImpl, name); - return location; -} - -ComputeTextureUnit ComputeShader::getTextureUnit(const char *name) { - ComputeTextureUnit unit; - unit.kincImpl = kinc_compute_shader_get_texture_unit(&kincImpl, name); - return unit; -} - -#ifdef KORE_OPENGL -ShaderStorageBuffer::ShaderStorageBuffer(int count, Graphics4::VertexData type) { - kinc_shader_storage_buffer_init(&kincImpl, count, (kinc_g4_vertex_data_t)type); -} - -ShaderStorageBuffer::~ShaderStorageBuffer() { - kinc_shader_storage_buffer_destroy(&kincImpl); -} - -int *ShaderStorageBuffer::lock() { - return kinc_shader_storage_buffer_lock(&kincImpl); -} - -void ShaderStorageBuffer::unlock() { - kinc_shader_storage_buffer_unlock(&kincImpl); -} - -int ShaderStorageBuffer::count() { - return kinc_shader_storage_buffer_count(&kincImpl); -} - -void ShaderStorageBuffer::_set() { - kinc_shader_storage_buffer_internal_set(&kincImpl); -} -#endif - -void Compute::setBool(ComputeConstantLocation location, bool value) { - kinc_compute_set_bool(location.kincImpl, value); -} - -void Compute::setInt(ComputeConstantLocation location, int value) { - kinc_compute_set_int(location.kincImpl, value); -} - -void Compute::setFloat(ComputeConstantLocation location, float value) { - kinc_compute_set_float(location.kincImpl, value); -} - -void Compute::setFloat2(ComputeConstantLocation location, float value1, float value2) { - kinc_compute_set_float2(location.kincImpl, value1, value2); -} - -void Compute::setFloat3(ComputeConstantLocation location, float value1, float value2, float value3) { - kinc_compute_set_float3(location.kincImpl, value1, value2, value3); -} - -void Compute::setFloat4(ComputeConstantLocation location, float value1, float value2, float value3, float value4) { - kinc_compute_set_float4(location.kincImpl, value1, value2, value3, value4); -} - -void Compute::setFloats(ComputeConstantLocation location, float *values, int count) { - kinc_compute_set_floats(location.kincImpl, values, count); -} - -void Compute::setMatrix(ComputeConstantLocation location, const mat4 &value) { - kinc_matrix4x4_t matrix; - memcpy(&matrix.m, value.data, sizeof(float) * 4 * 4); - kinc_compute_set_matrix4(location.kincImpl, &matrix); -} - -void Compute::setMatrix(ComputeConstantLocation location, const mat3 &value) { - kinc_matrix3x3_t matrix; - memcpy(&matrix.m, value.data, sizeof(float) * 3 * 3); - kinc_compute_set_matrix3(location.kincImpl, &matrix); -} - -#ifdef KORE_OPENGL -void Compute::setBuffer(ShaderStorageBuffer *buffer, int index) { - kinc_compute_set_buffer(&buffer->kincImpl, index); -} -#endif - -void Compute::setTexture(ComputeTextureUnit unit, Graphics4::Texture *texture, Compute::Access access) { - kinc_compute_set_texture(unit.kincImpl, &texture->kincTexture, (kinc_compute_access_t)access); -} - -void Compute::setTexture(ComputeTextureUnit unit, Graphics4::RenderTarget *texture, Compute::Access access) { - kinc_compute_set_render_target(unit.kincImpl, &texture->kincRenderTarget, (kinc_compute_access_t)access); -} - -void Compute::setSampledTexture(ComputeTextureUnit unit, Graphics4::Texture *texture) { - kinc_compute_set_sampled_texture(unit.kincImpl, &texture->kincTexture); -} - -void Compute::setSampledTexture(ComputeTextureUnit unit, Graphics4::RenderTarget *target) { - kinc_compute_set_sampled_render_target(unit.kincImpl, &target->kincRenderTarget); -} - -void Compute::setSampledDepthTexture(ComputeTextureUnit unit, Graphics4::RenderTarget *target) { - kinc_compute_set_sampled_depth_from_render_target(unit.kincImpl, &target->kincRenderTarget); -} - -void Compute::setTextureAddressing(ComputeTextureUnit unit, Graphics4::TexDir dir, Graphics4::TextureAddressing addressing) { - kinc_compute_set_texture_addressing(unit.kincImpl, (kinc_g4_texture_direction_t)dir, (kinc_g4_texture_addressing_t)addressing); -} - -void Compute::setTextureMagnificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter) { - kinc_compute_set_texture_magnification_filter(unit.kincImpl, (kinc_g4_texture_filter_t)filter); -} - -void Compute::setTextureMinificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter) { - kinc_compute_set_texture_minification_filter(unit.kincImpl, (kinc_g4_texture_filter_t)filter); -} - -void Compute::setTextureMipmapFilter(ComputeTextureUnit unit, Graphics4::MipmapFilter filter) { - kinc_compute_set_texture_mipmap_filter(unit.kincImpl, (kinc_g4_mipmap_filter_t)filter); -} - -void Compute::setTexture3DAddressing(ComputeTextureUnit unit, Graphics4::TexDir dir, Graphics4::TextureAddressing addressing) { - kinc_compute_set_texture3d_addressing(unit.kincImpl, (kinc_g4_texture_direction_t)dir, (kinc_g4_texture_addressing_t)addressing); -} - -void Compute::setTexture3DMagnificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter) { - kinc_compute_set_texture3d_magnification_filter(unit.kincImpl, (kinc_g4_texture_filter_t)filter); -} - -void Compute::setTexture3DMinificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter) { - kinc_compute_set_texture3d_minification_filter(unit.kincImpl, (kinc_g4_texture_filter_t)filter); -} - -void Compute::setTexture3DMipmapFilter(ComputeTextureUnit unit, Graphics4::MipmapFilter filter) { - kinc_compute_set_texture3d_mipmap_filter(unit.kincImpl, (kinc_g4_mipmap_filter_t)filter); -} - -void Compute::setShader(ComputeShader *shader) { - kinc_compute_set_shader(&shader->kincImpl); -} - -void Compute::compute(int x, int y, int z) { - kinc_compute(x, y, z); -} diff --git a/Sources/Kore/Compute/Compute.h b/Sources/Kore/Compute/Compute.h deleted file mode 100644 index 983c85061..000000000 --- a/Sources/Kore/Compute/Compute.h +++ /dev/null @@ -1,80 +0,0 @@ -#pragma once - -#include - -#ifdef KORE_OPENGL -#include -#endif -#include -#include - -namespace Kore { - namespace Graphics4 { - class Texture; - class RenderTarget; - } - - class ComputeConstantLocation { - public: - kinc_compute_constant_location_t kincImpl; - }; - - class ComputeTextureUnit { - public: - kinc_compute_texture_unit_t kincImpl; - }; - - class ComputeShader { - public: - ComputeShader(void *source, int length); - ~ComputeShader(); - ComputeConstantLocation getConstantLocation(const char *name); - ComputeTextureUnit getTextureUnit(const char *name); - kinc_compute_shader_t kincImpl; - }; - -#ifdef KORE_OPENGL - class ShaderStorageBuffer { - public: - ShaderStorageBuffer(int count, Graphics4::VertexData type); - virtual ~ShaderStorageBuffer(); - int *lock(); - void unlock(); - int count(); - void _set(); - kinc_shader_storage_buffer_t kincImpl; - }; -#endif - - namespace Compute { - enum Access { Read, Write, ReadWrite }; - - void setBool(ComputeConstantLocation location, bool value); - void setInt(ComputeConstantLocation location, int value); - void setFloat(ComputeConstantLocation location, float value); - void setFloat2(ComputeConstantLocation location, float value1, float value2); - void setFloat3(ComputeConstantLocation location, float value1, float value2, float value3); - void setFloat4(ComputeConstantLocation location, float value1, float value2, float value3, float value4); - void setFloats(ComputeConstantLocation location, float *values, int count); - void setMatrix(ComputeConstantLocation location, const mat4 &value); - void setMatrix(ComputeConstantLocation location, const mat3 &value); -#ifdef KORE_OPENGL - void setBuffer(ShaderStorageBuffer *buffer, int index); -#endif - void setTexture(ComputeTextureUnit unit, Graphics4::Texture *texture, Access access); - void setTexture(ComputeTextureUnit unit, Graphics4::RenderTarget *texture, Access access); - void setSampledTexture(ComputeTextureUnit unit, Graphics4::Texture *texture); - void setSampledTexture(ComputeTextureUnit unit, Graphics4::RenderTarget *target); - void setSampledDepthTexture(ComputeTextureUnit unit, Graphics4::RenderTarget *target); - void setTextureAddressing(ComputeTextureUnit unit, Graphics4::TexDir dir, Graphics4::TextureAddressing addressing); - void setTextureMagnificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter); - void setTextureMinificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter); - void setTextureMipmapFilter(ComputeTextureUnit unit, Graphics4::MipmapFilter filter); - void setTexture3DAddressing(ComputeTextureUnit unit, Graphics4::TexDir dir, Graphics4::TextureAddressing addressing); - void setTexture3DMagnificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter); - void setTexture3DMinificationFilter(ComputeTextureUnit unit, Graphics4::TextureFilter filter); - void setTexture3DMipmapFilter(ComputeTextureUnit unit, Graphics4::MipmapFilter filter); - void setShader(ComputeShader *shader); - void compute(int x, int y, int z); - }; -} diff --git a/Sources/Kore/Graphics4/Compute.cpp b/Sources/Kore/Graphics4/Compute.cpp new file mode 100644 index 000000000..7c13bdcf1 --- /dev/null +++ b/Sources/Kore/Graphics4/Compute.cpp @@ -0,0 +1,51 @@ +#include "Compute.h" + +#include + +using namespace Kore; + +Graphics4::ComputeShader::ComputeShader(void *source, int length) { + kinc_g4_compute_shader_init(&kincImpl, source, length); +} + +Graphics4::ComputeShader::~ComputeShader() { + kinc_g4_compute_shader_destroy(&kincImpl); +} + +Graphics4::ConstantLocation Graphics4::ComputeShader::getConstantLocation(const char *name) { + Graphics4::ConstantLocation location; + location.kincConstant = kinc_g4_compute_shader_get_constant_location(&kincImpl, name); + return location; +} + +Graphics4::TextureUnit Graphics4::ComputeShader::getTextureUnit(const char *name) { + Graphics4::TextureUnit unit; + unit.kincUnit = kinc_g4_compute_shader_get_texture_unit(&kincImpl, name); + return unit; +} + +#ifdef KORE_OPENGL +Graphics4::ShaderStorageBuffer::ShaderStorageBuffer(int count, Graphics4::VertexData type) { + kinc_shader_storage_buffer_init(&kincImpl, count, (kinc_g4_vertex_data_t)type); +} + +Graphics4::ShaderStorageBuffer::~ShaderStorageBuffer() { + kinc_shader_storage_buffer_destroy(&kincImpl); +} + +int *Graphics4::ShaderStorageBuffer::lock() { + return kinc_shader_storage_buffer_lock(&kincImpl); +} + +void Graphics4::ShaderStorageBuffer::unlock() { + kinc_shader_storage_buffer_unlock(&kincImpl); +} + +int Graphics4::ShaderStorageBuffer::count() { + return kinc_shader_storage_buffer_count(&kincImpl); +} + +void Graphics4::ShaderStorageBuffer::_set() { + kinc_shader_storage_buffer_internal_set(&kincImpl); +} +#endif diff --git a/Sources/Kore/Graphics4/Compute.h b/Sources/Kore/Graphics4/Compute.h new file mode 100644 index 000000000..5949f6d13 --- /dev/null +++ b/Sources/Kore/Graphics4/Compute.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#ifdef KORE_OPENGL +#include +#endif +#include +#include + +namespace Kore { + namespace Graphics4 { + class Texture; + class RenderTarget; + + class ComputeShader { + public: + ComputeShader(void *source, int length); + ~ComputeShader(); + ConstantLocation getConstantLocation(const char *name); + TextureUnit getTextureUnit(const char *name); + kinc_g4_compute_shader kincImpl; + }; + +#ifdef KORE_OPENGL + class ShaderStorageBuffer { + public: + ShaderStorageBuffer(int count, Graphics4::VertexData type); + virtual ~ShaderStorageBuffer(); + int *lock(); + void unlock(); + int count(); + void _set(); + kinc_shader_storage_buffer_t kincImpl; + }; +#endif + } +} diff --git a/Sources/Kore/Graphics4/Graphics.cpp b/Sources/Kore/Graphics4/Graphics.cpp index 433bcc7ed..0a4ed2a40 100644 --- a/Sources/Kore/Graphics4/Graphics.cpp +++ b/Sources/Kore/Graphics4/Graphics.cpp @@ -6,6 +6,7 @@ #include +#include #include #include @@ -285,4 +286,18 @@ void Graphics4::_changeFramebuffer(int window, struct kinc_framebuffer_options * kinc_internal_change_framebuffer(window, frame); } +#ifdef KORE_OPENGL +void Graphics4::setShaderStorageBuffer(ShaderStorageBuffer *buffer, int index) { + kinc_g4_set_shader_storage_buffer(&buffer->kincImpl, index); +} +#endif + +void Graphics4::setComputeShader(ComputeShader *shader) { + kinc_g4_set_compute_shader(&shader->kincImpl); +} + +void Graphics4::compute(int x, int y, int z) { + kinc_g4_compute(x, y, z); +} + #endif diff --git a/Sources/Kore/Graphics4/Graphics.h b/Sources/Kore/Graphics4/Graphics.h index 82915f02b..e6259bd7d 100644 --- a/Sources/Kore/Graphics4/Graphics.h +++ b/Sources/Kore/Graphics4/Graphics.h @@ -15,8 +15,12 @@ struct kinc_framebuffer_options; namespace Kore { namespace Graphics4 { + class ComputeShader; class PipelineState; class TextureArray; +#ifdef KORE_OPENGL + class ShaderStorageBuffer; +#endif class VertexBuffer { public: @@ -178,6 +182,12 @@ namespace Kore { void setRenderTargetFace(RenderTarget *texture, int face = 0); void restoreRenderTarget(); +#ifdef KORE_OPENGL + void setShaderStorageBuffer(ShaderStorageBuffer *buffer, int index); +#endif + void setComputeShader(ComputeShader *shader); + void compute(int x, int y, int z); + void begin(int window = 0); void end(int window = 0); bool swapBuffers(); diff --git a/Sources/Kore/Graphics5/CommandList.cpp b/Sources/Kore/Graphics5/CommandList.cpp index c9b14b5cb..195c58cb3 100644 --- a/Sources/Kore/Graphics5/CommandList.cpp +++ b/Sources/Kore/Graphics5/CommandList.cpp @@ -1,5 +1,6 @@ #include "CommandList.h" +#include "Compute.h" #include "ConstantBuffer.h" #include "Graphics.h" #include "PipelineState.h" @@ -170,3 +171,11 @@ bool CommandList::isQueryResultsAvailable(Kore::uint occlusionQuery) { void CommandList::getQueryResults(Kore::uint occlusionQuery, Kore::uint *pixelCount) { kinc_g5_command_list_get_query_result(&kincCommandList, occlusionQuery, pixelCount); } + +void CommandList::setComputeShader(ComputeShader *shader) { + kinc_g5_command_list_set_compute_shader(&kincCommandList, &shader->kincImpl); +} + +void CommandList::compute(int x, int y, int z) { + kinc_g5_command_list_compute(&kincCommandList, x, y, z); +} diff --git a/Sources/Kore/Graphics5/CommandList.h b/Sources/Kore/Graphics5/CommandList.h index e06f4f0f2..e568c6a2b 100644 --- a/Sources/Kore/Graphics5/CommandList.h +++ b/Sources/Kore/Graphics5/CommandList.h @@ -6,6 +6,7 @@ namespace Kore { namespace Graphics5 { + class ComputeShader; class ConstantBuffer; class IndexBuffer; class PipelineState; @@ -13,6 +14,9 @@ namespace Kore { class Sampler; class Texture; class VertexBuffer; +#ifdef KORE_OPENGL + class ShaderStorageBuffer; +#endif class CommandList { public: @@ -52,6 +56,9 @@ namespace Kore { void setTextureFromRenderTarget(TextureUnit unit, RenderTarget *target); void setTextureFromRenderTargetDepth(TextureUnit unit, RenderTarget *target); + void setComputeShader(ComputeShader *shader); + void compute(int x, int y, int z); + // Occlusion Query bool initOcclusionQuery(uint *occlusionQuery); void deleteOcclusionQuery(uint occlusionQuery); diff --git a/Sources/Kore/Graphics5/Compute.cpp b/Sources/Kore/Graphics5/Compute.cpp new file mode 100644 index 000000000..12ca7cb93 --- /dev/null +++ b/Sources/Kore/Graphics5/Compute.cpp @@ -0,0 +1,25 @@ +#include "Compute.h" + +#include + +using namespace Kore; + +Graphics5::ComputeShader::ComputeShader(void *source, int length) { + kinc_g5_compute_shader_init(&kincImpl, source, length); +} + +Graphics5::ComputeShader::~ComputeShader() { + kinc_g5_compute_shader_destroy(&kincImpl); +} + +Graphics5::ConstantLocation Graphics5::ComputeShader::getConstantLocation(const char *name) { + Graphics5::ConstantLocation location; + location.kincConstantLocation = kinc_g5_compute_shader_get_constant_location(&kincImpl, name); + return location; +} + +Graphics5::TextureUnit Graphics5::ComputeShader::getTextureUnit(const char *name) { + Graphics5::TextureUnit unit; + unit.kincTextureUnit = kinc_g5_compute_shader_get_texture_unit(&kincImpl, name); + return unit; +} diff --git a/Sources/Kore/Graphics5/Compute.h b/Sources/Kore/Graphics5/Compute.h new file mode 100644 index 000000000..c0950955e --- /dev/null +++ b/Sources/Kore/Graphics5/Compute.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +#ifdef KORE_OPENGL +#include +#endif +#include +#include + +namespace Kore { + namespace Graphics5 { + class ComputeShader { + public: + ComputeShader(void *source, int length); + ~ComputeShader(); + ConstantLocation getConstantLocation(const char *name); + TextureUnit getTextureUnit(const char *name); + kinc_g5_compute_shader kincImpl; + }; + } +}