Skip to content

Commit

Permalink
Fix faction swapping in the unit viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jul 28, 2024
1 parent 7efb0fa commit 2cc616c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ class PalettedSprite extends Sprite implements FactionColours {
)
}

@Override
RenderCommand renderCommand() {

transformCopy.set(globalTransform)

var updateAdjustmentMap = materialCopy.adjustmentMap != material.adjustmentMap
materialCopy.copy(material)

return { renderer ->
if (mesh && shader && materialCopy.texture) {
if (updateAdjustmentMap) {
var paletteMetadataBuffer = IntBuffer.allocate(256 * 4)
materialCopy.adjustmentMap.each { adjustment ->
paletteMetadataBuffer.put(adjustment).advance(3)
}
paletteMetadataBuffer.flip()
materialCopy.paletteMetadataBuffer.updateBufferData(paletteMetadataBuffer, 0)
}
renderer.draw(mesh, transformCopy, shader, materialCopy)
}
}
}

/**
* Update the faction being applied to this sprite.
*/
Expand All @@ -142,7 +165,6 @@ class PalettedSprite extends Sprite implements FactionColours {
@Override
void update(float delta) {

// TODO: Make this a UBO
if (factionChanged) {
material.adjustmentMap = buildAdjustmentMap(faction)
factionChanged = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class OpenGLUniformBuffer extends UniformBuffer {
case ByteBuffer -> {
glBufferSubData(GL_UNIFORM_BUFFER, offset, stack.malloc(data.capacity()).put(data).flip())
}
case IntBuffer -> {
glBufferSubData(GL_UNIFORM_BUFFER, offset, stack.mallocInt(data.capacity()).put(data).flip())
}
case FloatBuffer -> {
glBufferSubData(GL_UNIFORM_BUFFER, offset, stack.mallocFloat(data.capacity()).put(data).flip())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class Sprite extends Node<Sprite> implements GraphicsElement {
return scene.requestDelete(mesh, spriteSheet, material.spriteMetadataBuffer)
}


@Override
RenderCommand renderCommand() {

Expand Down

0 comments on commit 2cc616c

Please sign in to comment.