-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start on scripting and off-thread requests of the graphics system 🥳
- Loading branch information
Showing
18 changed files
with
462 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/mediaplayer/ImageScript.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nz.net.ultraq.redhorizon.cli.mediaplayer | ||
|
||
import nz.net.ultraq.redhorizon.engine.scenegraph.Scene | ||
import nz.net.ultraq.redhorizon.engine.scenegraph.nodes.SpriteScript | ||
|
||
import groovy.transform.InheritConstructors | ||
|
||
/** | ||
* A script to make a sprite node behave as a full-screen image. | ||
* | ||
* @author Emanuel Rabina | ||
*/ | ||
@InheritConstructors | ||
class ImageScript extends SpriteScript { | ||
|
||
@Override | ||
void onSceneAdded(Scene scene) { | ||
|
||
var width = sprite.imageFile.width | ||
var height = sprite.imageFile.height | ||
sprite | ||
.scaleXY(scene.window.renderResolution.calculateScaleToFit(width, height)) | ||
.translate(-width / 2, -height / 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/GraphicsRequests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nz.net.ultraq.redhorizon.engine.graphics | ||
|
||
import nz.net.ultraq.redhorizon.filetypes.ColourFormat | ||
|
||
import org.joml.primitives.Rectanglef | ||
|
||
import groovy.transform.ImmutableOptions | ||
import java.nio.ByteBuffer | ||
import java.util.concurrent.Future | ||
|
||
/** | ||
* Interface to make requests of the graphics system. | ||
* | ||
* @author Emanuel Rabina | ||
*/ | ||
interface GraphicsRequests { | ||
|
||
static interface Request<T> {} | ||
|
||
static record ShaderRequest(String name) implements Request<Shader> {} | ||
|
||
@ImmutableOptions(knownImmutables = ['surface']) | ||
static record SpriteMeshRequest(Rectanglef surface) implements Request<Mesh> {} | ||
|
||
@ImmutableOptions(knownImmutables = ['data']) | ||
static record TextureRequest(int width, int height, ColourFormat format, ByteBuffer data) implements Request<Texture> { | ||
} | ||
|
||
/** | ||
* Request the creation of a mesh from the graphics system. | ||
*/ | ||
Future<Mesh> requestMesh(SpriteMeshRequest spriteMeshRequest) | ||
|
||
/** | ||
* Request an existing shader by name. | ||
*/ | ||
Future<Shader> requestShader(ShaderRequest shaderRequest) | ||
|
||
/** | ||
* Request the creation of a texture from the graphics system. | ||
*/ | ||
Future<Texture> requestTexture(TextureRequest textureRequest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.