split drawArc to uploadArc, more intelligent steps calculation
This commit is contained in:
parent
b5ed902871
commit
df683477d1
@ -591,29 +591,30 @@ fun drawArc(
|
||||
innerRadius: Float = 0f,
|
||||
startDegree: Double = 0.0,
|
||||
endDegree: Double = PI * 2.0,
|
||||
steps: Int = (outerRadius / 8.0 * (endDegree - startDegree)).roundToInt().coerceAtLeast(12),
|
||||
steps: Int = (outerRadius * (endDegree - startDegree) * 4.0).roundToInt().coerceAtLeast(12),
|
||||
alignAtCenter: Boolean = true
|
||||
) = drawArc(stack.last().pose(), x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter)
|
||||
|
||||
fun drawArc(
|
||||
|
||||
fun uploadArc(
|
||||
matrix: Matrix4f,
|
||||
builder: VertexConsumer,
|
||||
x: Float,
|
||||
y: Float,
|
||||
outerRadius: Float,
|
||||
innerRadius: Float = 0f,
|
||||
startDegree: Double = 0.0,
|
||||
endDegree: Double = PI * 2.0,
|
||||
steps: Int = (outerRadius / 8.0 * (endDegree - startDegree)).roundToInt().coerceAtLeast(12),
|
||||
alignAtCenter: Boolean = true
|
||||
steps: Int = (outerRadius * (endDegree - startDegree) * 4.0).roundToInt().coerceAtLeast(12),
|
||||
alignAtCenter: Boolean = true,
|
||||
triangleFan: Boolean
|
||||
) {
|
||||
require(startDegree < endDegree) { "Invalid arc degree range: $startDegree - $endDegree" }
|
||||
require(steps >= 0) { "Invalid amount of arc steps: $steps" }
|
||||
require(innerRadius >= 0f) { "Invalid inner radius of arc: $innerRadius" }
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionShader)
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.defaultBlendFunc()
|
||||
RenderSystem.depthFunc(GL_ALWAYS)
|
||||
if (!triangleFan) {
|
||||
require(innerRadius >= 0f) { "Invalid inner radius of arc: $innerRadius" }
|
||||
}
|
||||
|
||||
@Suppress("name_shadowing")
|
||||
var x = x
|
||||
@ -632,30 +633,20 @@ fun drawArc(
|
||||
y += outerRadius
|
||||
}
|
||||
|
||||
val builder = tesselator.builder
|
||||
if (triangleFan) {
|
||||
val singleStep = (endDegree - startDegree) / steps
|
||||
|
||||
if (innerRadius == 0f) {
|
||||
if (steps >= 1) {
|
||||
val singleStep = (endDegree - startDegree) / steps
|
||||
builder.vertex(matrix, x, y, zLevel).endVertex()
|
||||
|
||||
builder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION)
|
||||
for (i in 0 .. steps) {
|
||||
val sin = sin(startDegree + i * singleStep).toFloat()
|
||||
val cos = cos(startDegree + i * singleStep).toFloat()
|
||||
|
||||
builder.vertex(matrix, x, y, zLevel).endVertex()
|
||||
|
||||
for (i in 0 .. steps) {
|
||||
val sin = sin(startDegree + i * singleStep).toFloat()
|
||||
val cos = cos(startDegree + i * singleStep).toFloat()
|
||||
|
||||
builder.vertex(matrix, x + outerRadius * sin, y + cos * outerRadius, zLevel).endVertex()
|
||||
}
|
||||
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
builder.vertex(matrix, x + outerRadius * sin, y + cos * outerRadius, zLevel).endVertex()
|
||||
}
|
||||
} else {
|
||||
val singleStep = (endDegree - startDegree) / (steps + 1)
|
||||
|
||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION)
|
||||
|
||||
for (i in 0 .. steps) {
|
||||
val sin = sin(startDegree + i * singleStep).toFloat()
|
||||
val cos = cos(startDegree + i * singleStep).toFloat()
|
||||
@ -668,7 +659,40 @@ fun drawArc(
|
||||
builder.vertex(matrix, x + innerRadius * sin2, y + cos2 * innerRadius, zLevel).endVertex()
|
||||
builder.vertex(matrix, x + innerRadius * sin, y + cos * innerRadius, zLevel).endVertex()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun drawArc(
|
||||
matrix: Matrix4f,
|
||||
x: Float,
|
||||
y: Float,
|
||||
outerRadius: Float,
|
||||
innerRadius: Float = 0f,
|
||||
startDegree: Double = 0.0,
|
||||
endDegree: Double = PI * 2.0,
|
||||
steps: Int = (outerRadius * (endDegree - startDegree) * 4.0).roundToInt().coerceAtLeast(12),
|
||||
alignAtCenter: Boolean = true
|
||||
) {
|
||||
require(startDegree < endDegree) { "Invalid arc degree range: $startDegree - $endDegree" }
|
||||
require(steps >= 0) { "Invalid amount of arc steps: $steps" }
|
||||
require(innerRadius >= 0f) { "Invalid inner radius of arc: $innerRadius" }
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionShader)
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.defaultBlendFunc()
|
||||
RenderSystem.depthFunc(GL_ALWAYS)
|
||||
|
||||
val builder = tesselator.builder
|
||||
|
||||
if (innerRadius == 0f) {
|
||||
if (steps >= 1) {
|
||||
builder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION)
|
||||
uploadArc(matrix, builder, x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter, triangleFan = true)
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
}
|
||||
} else {
|
||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION)
|
||||
uploadArc(matrix, builder, x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter, triangleFan = false)
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user