Skip to content

Commit

Permalink
Cleanup: Further simplify AG
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Dec 9, 2022
1 parent d63bcdc commit 1d3a1d7
Show file tree
Hide file tree
Showing 36 changed files with 296 additions and 314 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ class BatchBuilder2D constructor(
fun getDefaultProgram(): Program = PROGRAM
fun getDefaultProgramForTexture(): Program = getDefaultProgram()

/** When there are vertices pending, this performs a [AG.drawV2] call flushing all the buffered geometry pending to draw */
/** When there are vertices pending, this performs a [AG.draw] call flushing all the buffered geometry pending to draw */
fun flush(uploadVertices: Boolean = true, uploadIndices: Boolean = true) {
//println("vertexCount=${vertexCount}")
if (vertexCount > 0) {
Expand All @@ -915,20 +915,20 @@ class BatchBuilder2D constructor(

val program = currentProgram ?: PROGRAM
//println("program=$program, currentTexN[0]=${currentTexN[0]}")
ag.drawV2(
ag.draw(
ctx.currentFrameBuffer,
vertexData = vertexData,
indices = indexBuffer,
program = program,
//program = PROGRAM_PRE,
type = AGDrawType.TRIANGLES,
drawType = AGDrawType.TRIANGLES,
blending = factors.factors(ctx.isRenderingToTexture),
uniforms = uniforms,
stencilOpFunc = stencilOpFunc,
stencilRef = stencilRef,
colorMask = colorMask,
scissor = scissor,
offset = 0,
drawOffset = 0,
vertexCount = indexPos,
)
beforeFlush(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ class LineRenderBatcher(
ctx.updateStandardUniforms()
//projMat.setToOrtho(tempRect.setBounds(0, 0, ag.backWidth, ag.backHeight), -1f, 1f)

ag.drawV2(
ag.draw(
ctx.currentFrameBuffer,
vertexData,
program = program,
type = AGDrawType.LINES,
drawType = AGDrawType.LINES,
vertexCount = vertexCount,
uniforms = uniforms,
blending = blendMode.factors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class RenderContext constructor(
* Finishes the drawing and flips the screen. Called by the KorGe engine at the end of the frame.
*/
fun finish() {
ag.flip()
ag.finish()
frameBuffers.free(frameFrameBuffers)
if (frameFrameBuffers.isNotEmpty()) frameFrameBuffers.clear()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.soywiz.korge.view.debug

import com.soywiz.kds.fastArrayListOf
import com.soywiz.kds.iterators.fastForEach
import com.soywiz.korag.*
import com.soywiz.korag.shader.FragmentShader
Expand Down Expand Up @@ -117,14 +116,14 @@ class DebugVertexView(pointsList: List<IVectorArrayList>, color: RGBA = Colors.W
AGVertexData(DefaultShaders.LAYOUT_DEBUG, vb)
)
batches.fastForEach { batch ->
ctx.ag.drawV2(
ctx.ag.draw(
ctx.currentFrameBuffer,
vData,
type = type,
drawType = type,
program = PROGRAM,
uniforms = this.uniforms,
vertexCount = batch.count,
offset = batch.offset,
drawOffset = batch.offset,
blending = renderBlendMode.factors
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.soywiz.korge.view.fast
import com.soywiz.kds.Extra
import com.soywiz.kds.FastArrayList
import com.soywiz.kds.IntArrayList
import com.soywiz.kds.fastArrayListOf
import com.soywiz.kmem.*
import com.soywiz.korag.*
import com.soywiz.korag.shader.Attribute
Expand Down Expand Up @@ -174,11 +172,11 @@ open class FSprites(val maxSize: Int) {
//ctx.batch.setStateFast()
sprites.uploadVertices(ctx)
ctx.xyBuffer.buffer.upload(xyData)
ctx.ag.drawV2(
ctx.ag.draw(
ctx.currentFrameBuffer,
vertexData = ctx.buffers,
program = program,
type = AGDrawType.TRIANGLE_FAN,
drawType = AGDrawType.TRIANGLE_FAN,
vertexCount = 4,
instances = sprites.size,
uniforms = uniforms,
Expand Down
6 changes: 3 additions & 3 deletions korge/src/commonMain/kotlin/com/soywiz/korge3d/SkyBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ class SkyBox(
.setColumn(3, 0f, 0f, 0f, 0f)
.setRow(3, 0f, 0f, 0f, 0f)
.translate(center)
ctx.ag.drawV2(
ctx.ag.draw(
ctx.rctx.currentFrameBuffer,
vertexData = AGVertexArrayObject(AGVertexData(layout, vertexBuffer)),
type = AGDrawType.TRIANGLES,
drawType = AGDrawType.TRIANGLES,
program = skyBoxProgram,
vertexCount = 36,
indices = indexBuffer,
Expand All @@ -188,7 +188,7 @@ class SkyBox(
this[u_ViewMat] = viewNoTrans
this[u_SkyBox] = cubeMapTexUnit
},
renderState = rs
depthAndFrontFace = rs
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions korge/src/commonMain/kotlin/com/soywiz/korge3d/Terrain3D.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ class Terrain3D(
indexBuffer.upload(mesh.indexBuffer)
Shaders3D.apply {
val meshMaterial = mesh.material
ag.drawV2(
ag.draw(
ctx.rctx.currentFrameBuffer,
vertexData = vertexData,
indices = indexBuffer,
indexType = mesh.indexType,
type = mesh.drawType,
drawType = mesh.drawType,
program = mesh.program ?: ctx.shaders.getProgram3D(
ctx.lights.size.clamp(0, 4),
mesh.maxWeights,
Expand Down Expand Up @@ -183,7 +183,7 @@ class Terrain3D(
)
}
},
renderState = rs
depthAndFrontFace = rs
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions korge/src/commonMain/kotlin/com/soywiz/korge3d/Text3D.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class Text3D(

Shaders3D.apply {
val meshMaterial = mesh.material
ag.drawV2(
ag.draw(
ctx.rctx.currentFrameBuffer,
vertexData,
type = mesh.drawType,
drawType = mesh.drawType,
program = mesh.program ?: ctx.shaders.getProgram3D(
ctx.lights.size.clamp(0, 4),
mesh.maxWeights,
Expand Down Expand Up @@ -111,7 +111,7 @@ class Text3D(
)
}
},
renderState = rs
depthAndFrontFace = rs
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ open class ViewWithMesh3D(

Shaders3D.apply {
val meshMaterial = mesh.material
ag.drawV2(
ag.draw(
ctx.rctx.currentFrameBuffer,
vertexData = vertexData,
indices = indexBuffer,
indexType = mesh.indexType,
type = mesh.drawType,
drawType = mesh.drawType,
program = mesh.program ?: ctx.shaders.getProgram3D(
ctx.lights.size.clamp(0, 4),
mesh.maxWeights,
Expand Down Expand Up @@ -137,7 +137,7 @@ open class ViewWithMesh3D(
)
}
},
renderState = rs
depthAndFrontFace = rs
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MaskedViewTest : ViewsForTesting() {
masked.solidRect(64, 64)

testRenderContext(object : AGBaseLog() {

override fun execute(command: AGCommand) {
when (command) {
is AGBatch -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
clear(AGFrameBufferBase(isMain=true), AGFrameBufferInfo(width=1280, height=720, hasDepth=true, hasStencil=true, samples=1), #00000000, 1.0, 0, true, true, true)
flip()
clear(AGFrameBufferBase(isMain=true), AGFrameBufferInfo(width=1280, height=720, hasDepth=true, hasStencil=true, samples=1), #00000000, 1.0, 0, true, true, true)
execute(AGBatch(frameBuffer=AGFrameBufferBase(isMain=true), frameBufferInfo=AGFrameBufferInfo(width=1280, height=720, hasDepth=true, hasStencil=true, samples=1), vertexData=AGVertexArrayObject(list=[AGVertexData(layout=VertexLayout[a_Pos, a_Tex, a_Col, a_Col2], buffer=AGBuffer(96)), AGVertexData(layout=VertexLayout[a_TexIndex], buffer=AGBuffer(16384)), AGVertexData(layout=VertexLayout[a_Wrap], buffer=AGBuffer(16384))]), indices=AGBuffer(12), indexType=USHORT, program=Program(name=BatchBuilder2D.Tinted.NoAdd, attributes=[a_Tex, a_TexIndex, a_Wrap, a_Col, a_Col2, a_Pos], uniforms=[u_ProjMat, u_ViewMat, u_Tex0, u_Tex1, u_Tex2, u_Tex3, u_OutputPre]), uniforms=AGUniformValues(u_ProjMat=AGValue[TFLOAT]([[0.0015625, 0, 0, 0, 0, -0.0027777778, 0, 0, 0, 0, -1, 0, -1, 1, 0, 1]]), u_ViewMat=AGValue[TFLOAT]([[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]]), u_Tex0=AGValue[TINT]([[0]]), u_Tex1=AGValue[TINT]([[1]]), u_Tex2=AGValue[TINT]([[2]]), u_Tex3=AGValue[TINT]([[3]]), u_OutputPre=AGValue[TBOOL]([[0]])), blending=Blending(outRGB = (srcRGB * srcA) + (dstRGB * (1 - srcA)), outA = (srcA * 1) + (dstA * (1 - srcA))), stencilOpFunc=AGStencilOpFunc(data=5591072), stencilRef=AGStencilReference(data=16776960), colorMask=AGColorMask(data=15), depthAndFrontFace=AGDepthAndFrontFace(data=33550336), scissor=Scissor(x=0, y=0, width=1280, height=720), cullFace=NONE, drawType=TRIANGLES, drawOffset=0, vertexCount=6, instances=1))
flip()
AGClear(frameBuffer=AGFrameBufferBase(isMain=true), frameBufferInfo=AGFrameBufferInfo(width=1280, height=720, hasDepth=true, hasStencil=true, samples=1), color=#00000000, depth=1.0, stencil=0, clearColor=true, clearDepth=true, clearStencil=true)
finish()
AGClear(frameBuffer=AGFrameBufferBase(isMain=true), frameBufferInfo=AGFrameBufferInfo(width=1280, height=720, hasDepth=true, hasStencil=true, samples=1), color=#00000000, depth=1.0, stencil=0, clearColor=true, clearDepth=true, clearStencil=true)
AGBatch(frameBuffer=AGFrameBufferBase(isMain=true), frameBufferInfo=AGFrameBufferInfo(width=1280, height=720, hasDepth=true, hasStencil=true, samples=1), vertexData=AGVertexArrayObject(list=[AGVertexData(layout=VertexLayout[a_Pos, a_Tex, a_Col, a_Col2], buffer=AGBuffer(96)), AGVertexData(layout=VertexLayout[a_TexIndex], buffer=AGBuffer(16384)), AGVertexData(layout=VertexLayout[a_Wrap], buffer=AGBuffer(16384))]), indices=AGBuffer(12), indexType=USHORT, program=Program(name=BatchBuilder2D.Tinted.NoAdd, attributes=[a_Tex, a_TexIndex, a_Wrap, a_Col, a_Col2, a_Pos], uniforms=[u_ProjMat, u_ViewMat, u_Tex0, u_Tex1, u_Tex2, u_Tex3, u_OutputPre]), uniforms=AGUniformValues(u_ProjMat=AGValue[TFLOAT]([[0.0015625, 0, 0, 0, 0, -0.0027777778, 0, 0, 0, 0, -1, 0, -1, 1, 0, 1]]), u_ViewMat=AGValue[TFLOAT]([[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]]), u_Tex0=AGValue[TINT]([[0]]), u_Tex1=AGValue[TINT]([[1]]), u_Tex2=AGValue[TINT]([[2]]), u_Tex3=AGValue[TINT]([[3]]), u_OutputPre=AGValue[TBOOL]([[0]])), blending=Blending(outRGB = (srcRGB * srcA) + (dstRGB * (1 - srcA)), outA = (srcA * 1) + (dstA * (1 - srcA))), stencilOpFunc=AGStencilOpFunc(data=5591072), stencilRef=AGStencilReference(data=16776960), colorMask=AGColorMask(data=15), depthAndFrontFace=AGDepthAndFrontFace(data=33550336), scissor=Scissor(x=0, y=0, width=1280, height=720), cullFace=NONE, drawType=TRIANGLES, drawOffset=0, vertexCount=6, instances=1)
finish()
Original file line number Diff line number Diff line change
@@ -1 +1 @@
execute(AGBatch(frameBuffer=AGFrameBufferBase(isMain=true), frameBufferInfo=AGFrameBufferInfo(width=640, height=480, hasDepth=true, hasStencil=true, samples=1), vertexData=AGVertexArrayObject(list=[AGVertexData(layout=VertexLayout[a_Pos, a_Tex, a_Col, a_Col2], buffer=AGBuffer(384)), AGVertexData(layout=VertexLayout[a_TexIndex], buffer=AGBuffer(16384)), AGVertexData(layout=VertexLayout[a_Wrap], buffer=AGBuffer(16384))]), indices=AGBuffer(48), indexType=USHORT, program=Program(name=BatchBuilder2D.Tinted.NoAdd, attributes=[a_Tex, a_TexIndex, a_Wrap, a_Col, a_Col2, a_Pos], uniforms=[u_ProjMat, u_ViewMat, u_Tex0, u_Tex1, u_Tex2, u_Tex3, u_OutputPre]), uniforms=AGUniformValues(u_ProjMat=AGValue[TFLOAT]([[0.003125, 0, 0, 0, 0, -0.004166667, 0, 0, 0, 0, -1, 0, -1, 1, 0, 1]]), u_ViewMat=AGValue[TFLOAT]([[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]]), u_Tex0=AGValue[TINT]([[0]]), u_Tex1=AGValue[TINT]([[1]]), u_Tex2=AGValue[TINT]([[2]]), u_Tex3=AGValue[TINT]([[3]]), u_OutputPre=AGValue[TBOOL]([[0]])), blending=Blending(outRGB = (srcRGB * srcA) + (dstRGB * (1 - srcA)), outA = (srcA * 1) + (dstA * (1 - srcA))), stencilOpFunc=AGStencilOpFunc(data=5591072), stencilRef=AGStencilReference(data=16776960), colorMask=AGColorMask(data=15), depthAndFrontFace=AGDepthAndFrontFace(data=33550336), scissor=null, cullFace=NONE, drawType=TRIANGLES, drawOffset=0, vertexCount=24, instances=1))
AGBatch(frameBuffer=AGFrameBufferBase(isMain=true), frameBufferInfo=AGFrameBufferInfo(width=640, height=480, hasDepth=true, hasStencil=true, samples=1), vertexData=AGVertexArrayObject(list=[AGVertexData(layout=VertexLayout[a_Pos, a_Tex, a_Col, a_Col2], buffer=AGBuffer(384)), AGVertexData(layout=VertexLayout[a_TexIndex], buffer=AGBuffer(16384)), AGVertexData(layout=VertexLayout[a_Wrap], buffer=AGBuffer(16384))]), indices=AGBuffer(48), indexType=USHORT, program=Program(name=BatchBuilder2D.Tinted.NoAdd, attributes=[a_Tex, a_TexIndex, a_Wrap, a_Col, a_Col2, a_Pos], uniforms=[u_ProjMat, u_ViewMat, u_Tex0, u_Tex1, u_Tex2, u_Tex3, u_OutputPre]), uniforms=AGUniformValues(u_ProjMat=AGValue[TFLOAT]([[0.003125, 0, 0, 0, 0, -0.004166667, 0, 0, 0, 0, -1, 0, -1, 1, 0, 1]]), u_ViewMat=AGValue[TFLOAT]([[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]]), u_Tex0=AGValue[TINT]([[0]]), u_Tex1=AGValue[TINT]([[1]]), u_Tex2=AGValue[TINT]([[2]]), u_Tex3=AGValue[TINT]([[3]]), u_OutputPre=AGValue[TBOOL]([[0]])), blending=Blending(outRGB = (srcRGB * srcA) + (dstRGB * (1 - srcA)), outA = (srcA * 1) + (dstA * (1 - srcA))), stencilOpFunc=AGStencilOpFunc(data=5591072), stencilRef=AGStencilReference(data=16776960), colorMask=AGColorMask(data=15), depthAndFrontFace=AGDepthAndFrontFace(data=33550336), scissor=null, cullFace=NONE, drawType=TRIANGLES, drawOffset=0, vertexCount=24, instances=1)
Loading

0 comments on commit 1d3a1d7

Please sign in to comment.