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,
|
innerRadius: Float = 0f,
|
||||||
startDegree: Double = 0.0,
|
startDegree: Double = 0.0,
|
||||||
endDegree: Double = PI * 2.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
|
alignAtCenter: Boolean = true
|
||||||
) = drawArc(stack.last().pose(), x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter)
|
) = drawArc(stack.last().pose(), x, y, outerRadius, innerRadius, startDegree, endDegree, steps, alignAtCenter)
|
||||||
|
|
||||||
fun drawArc(
|
|
||||||
|
fun uploadArc(
|
||||||
matrix: Matrix4f,
|
matrix: Matrix4f,
|
||||||
|
builder: VertexConsumer,
|
||||||
x: Float,
|
x: Float,
|
||||||
y: Float,
|
y: Float,
|
||||||
outerRadius: Float,
|
outerRadius: Float,
|
||||||
innerRadius: Float = 0f,
|
innerRadius: Float = 0f,
|
||||||
startDegree: Double = 0.0,
|
startDegree: Double = 0.0,
|
||||||
endDegree: Double = PI * 2.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
|
alignAtCenter: Boolean = true,
|
||||||
|
triangleFan: Boolean
|
||||||
) {
|
) {
|
||||||
require(startDegree < endDegree) { "Invalid arc degree range: $startDegree - $endDegree" }
|
require(startDegree < endDegree) { "Invalid arc degree range: $startDegree - $endDegree" }
|
||||||
require(steps >= 0) { "Invalid amount of arc steps: $steps" }
|
require(steps >= 0) { "Invalid amount of arc steps: $steps" }
|
||||||
require(innerRadius >= 0f) { "Invalid inner radius of arc: $innerRadius" }
|
|
||||||
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionShader)
|
if (!triangleFan) {
|
||||||
RenderSystem.enableBlend()
|
require(innerRadius >= 0f) { "Invalid inner radius of arc: $innerRadius" }
|
||||||
RenderSystem.defaultBlendFunc()
|
}
|
||||||
RenderSystem.depthFunc(GL_ALWAYS)
|
|
||||||
|
|
||||||
@Suppress("name_shadowing")
|
@Suppress("name_shadowing")
|
||||||
var x = x
|
var x = x
|
||||||
@ -632,30 +633,20 @@ fun drawArc(
|
|||||||
y += outerRadius
|
y += outerRadius
|
||||||
}
|
}
|
||||||
|
|
||||||
val builder = tesselator.builder
|
if (triangleFan) {
|
||||||
|
val singleStep = (endDegree - startDegree) / steps
|
||||||
|
|
||||||
if (innerRadius == 0f) {
|
builder.vertex(matrix, x, y, zLevel).endVertex()
|
||||||
if (steps >= 1) {
|
|
||||||
val singleStep = (endDegree - startDegree) / steps
|
|
||||||
|
|
||||||
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()
|
builder.vertex(matrix, x + outerRadius * sin, y + cos * outerRadius, 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())
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val singleStep = (endDegree - startDegree) / (steps + 1)
|
val singleStep = (endDegree - startDegree) / (steps + 1)
|
||||||
|
|
||||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION)
|
|
||||||
|
|
||||||
for (i in 0 .. steps) {
|
for (i in 0 .. steps) {
|
||||||
val sin = sin(startDegree + i * singleStep).toFloat()
|
val sin = sin(startDegree + i * singleStep).toFloat()
|
||||||
val cos = cos(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 * sin2, y + cos2 * innerRadius, zLevel).endVertex()
|
||||||
builder.vertex(matrix, x + innerRadius * sin, y + cos * 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())
|
BufferUploader.drawWithShader(builder.end())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user