Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/main/kotlin/team/exception/sakura/graphics/G2RenderSystem.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package team.exception.sakura.graphics

import team.exception.sakura.graphics.buffer.G2Device
import org.lwjgl.opengl.GL41.*
import team.exception.sakura.graphics.geek2.G2Device
import team.exception.sakura.graphics.gl.GlDevice

object G2RenderSystem {

val backend: Backends = Backends.OPENGL

val gpuType: GpuTypes = pickGpuType()

private fun pickGpuType(): GpuTypes {
when (backend) {
Backends.OPENGL -> {
val glVendor = glGetString(GL_VENDOR) ?: return GpuTypes.OTHER
return when {
glVendor.contains("Intel") -> GpuTypes.INTEL
glVendor.contains("AMD") -> GpuTypes.AMD
glVendor.contains("NVIDIA") -> GpuTypes.NVIDIA
glVendor.contains("Apple") -> GpuTypes.APPLE
else -> GpuTypes.OTHER
}
}
}
}

val device: G2Device = when (backend) {
Backends.OPENGL -> GlDevice()
}
Expand All @@ -15,4 +33,12 @@ object G2RenderSystem {
OPENGL,
}

enum class GpuTypes {
INTEL,
AMD,
NVIDIA,
APPLE,
OTHER,
}

}
23 changes: 0 additions & 23 deletions src/main/kotlin/team/exception/sakura/graphics/buffer/G2Buffer.kt

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/kotlin/team/exception/sakura/graphics/buffer/G2Device.kt

This file was deleted.

40 changes: 40 additions & 0 deletions src/main/kotlin/team/exception/sakura/graphics/geek2/G2Buffer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package team.exception.sakura.graphics.geek2

import java.nio.ByteBuffer

abstract class G2Buffer(
open val device: G2Device,
val size: Long,
) {

/**
* Get the mapped buffer.
* @return the mapped buffer
* @throws IllegalStateException if the buffer hasn't been mapped.
*/
abstract fun getMappedBuffer(): ByteBuffer

/**
* Refresh modified data in the buffer.
* @throws IllegalStateException if the buffer hasn't been mapped.
*/
abstract fun refresh(modifiedRange: LongRange)

/**
* Remap the buffer.
* @throws IllegalStateException if the buffer hasn't been mapped.
*/
abstract fun remap()

/**
* Destroy & unmap the buffer.
*/
abstract fun destroy()

enum class Access {
WRITE,
READ,
READ_WRITE
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package team.exception.sakura.graphics.geek2

abstract class G2CommandList {

/**
* Binds the graphics pipeline to the command list.
*/
abstract fun bindGraphicsPipeline(pipeline: G2GraphicsPipeline)

/**
* Draw array
*/
abstract fun draw(vertexCount: Int, instanceCount: Int, firstVertex: Int, firstInstance: Int)

/**
* Draw indexed
*/
abstract fun drawIndexed(indexCount: Int, instanceCount: Int, firstIndex: Int, vertexOffset: Int, firstInstance: Int)

/**
* Begin rendering (Dynamic rendering in vulkan)
*/
abstract fun beginRendering(renderingInfo: G2RenderingInfo)

/**
* End rendering (Dynamic rendering in vulkan)
*/
abstract fun endRendering()

/**
* Summit the command list
*/
abstract fun summit()

/**
* Clear the command list
*/
abstract fun clear()

/**
* Summit and clear the command list
*/
abstract fun summitAndClear()

/**
* Destroy the command list
*/
abstract fun destroy()

/**
* Summit and destroy the command list
*/
abstract fun summitAndDestroy()

}
29 changes: 29 additions & 0 deletions src/main/kotlin/team/exception/sakura/graphics/geek2/G2Device.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package team.exception.sakura.graphics.geek2

import java.nio.ByteBuffer

abstract class G2Device {

/**
* Create a new command list.
*
* Note: You should destroy the command list after use.
* @return A new command list.
*/
abstract fun createCommandList(): G2CommandList

abstract fun createBuffer(
size: Long,
access: G2Buffer.Access = G2Buffer.Access.READ_WRITE
): G2Buffer

abstract fun createShader(
source: ByteBuffer,
sourceType: G2Shader.SourceType,
shaderType: G2Shader.ShaderType,
entryPoint: String
): G2Shader

abstract fun createShaderSet(shaders: List<G2Shader>): G2ShaderSet

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.exception.sakura.graphics.geek2

enum class G2Format {
A8R8G8B8,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package team.exception.sakura.graphics.geek2

abstract class G2GraphicsPipeline(
val primitive: Primitive,
open val shaderSet: G2ShaderSet,
val pipelineStates: PipelineStates,
val vertexInput: G2VertexInput? = null,
) {

data class PipelineStates(
var depthTest: Boolean = false,
var depthWrite: Boolean = true,
var depthFunc: DepthFunc = DepthFunc.LESS,
var cullEnable: Boolean = false,
var cullMode: CullMode = CullMode.BACK,
var frontFace: FrontFace = FrontFace.COUNTER_CLOCKWISE,
var fillMode: FillMode = FillMode.FILL,
var blendEnable: Boolean = false,
var blendEquation: BlendEquation = BlendEquation.ADD,
var srcColorBlend: BlendFunc = BlendFunc.SRC_ALPHA,
var dstColorBlend: BlendFunc = BlendFunc.ONE_MINUS_SRC_ALPHA,
var srcAlphaBlend: BlendFunc = BlendFunc.ONE,
var dstAlphaBlend: BlendFunc = BlendFunc.ZERO,
var colorWriteMask: ColorMask = ColorMask.ALL
)

enum class Primitive {
TRIANGLES,
TRIANGLE_FAN,
TRIANGLE_STRIP,
LINES,
LINE_STRIP,
POINTS
}

enum class CullMode {
NONE,
FRONT,
BACK,
FRONT_AND_BACK
}

enum class FillMode {
FILL,
LINE,
POINT
}

enum class FrontFace {
CLOCKWISE,
COUNTER_CLOCKWISE
}

enum class DepthFunc {
NEVER,
LESS,
EQUAL,
LEQUAL,
GREATER,
NOTEQUAL,
GEQUAL,
ALWAYS
}

enum class BlendEquation {
ADD,
SUBTRACT,
REVERSE_SUBTRACT,
MIN,
MAX
}

enum class BlendFunc {
ZERO,
ONE,
SRC_COLOR,
ONE_MINUS_SRC_COLOR,
DST_COLOR,
ONE_MINUS_DST_COLOR,
SRC_ALPHA,
ONE_MINUS_SRC_ALPHA,
DST_ALPHA,
ONE_MINUS_DST_ALPHA,
}

enum class ColorMask {
NONE,
RED,
GREEN,
BLUE,
ALPHA,
ALL
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.exception.sakura.graphics.geek2

abstract class G2Image {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.exception.sakura.graphics.geek2

abstract class G2ImageView(
open val image: G2Image,
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.exception.sakura.graphics.geek2

abstract class G2RenderingInfo {

abstract val colorAttachment: Attachment?

abstract val depthAttachment: Attachment?

abstract val width: Int

abstract val height: Int

data class Attachment(
val image: G2ImageView,
val format: G2Format,
)

}
Loading