Search in sources :

Example 1 with Texture

use of org.terasology.engine.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class LwjglGraphicsManager method registerCoreAssetTypes.

public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) {
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.createAssetType(Font.class, FontImpl::new, "fonts");
    AssetType<Texture, TextureData> texture = assetTypeManager.createAssetType(Texture.class, (urn, assetType, data) -> (OpenGLTexture.create(urn, assetType, data, this)), "textures", "fonts");
    assetTypeManager.getAssetFileDataProducer(texture).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> {
        if (path.getPath().get(0).equals(ModuleAssetScanner.OVERRIDE_FOLDER)) {
            return path.getPath().get(2).equals("textures");
        } else {
            return path.getPath().get(1).equals("textures");
        }
    }));
    assetTypeManager.getAssetFileDataProducer(texture).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> {
        if (path.getPath().get(0).equals(ModuleAssetScanner.OVERRIDE_FOLDER)) {
            return path.getPath().get(2).equals("fonts");
        } else {
            return path.getPath().get(1).equals("fonts");
        }
    }));
    assetTypeManager.createAssetType(Shader.class, (urn, assetType, data) -> GLSLShader.create(urn, assetType, data, this), "shaders");
    assetTypeManager.createAssetType(Material.class, (urn, assetType, data) -> GLSLMaterial.create(urn, this, assetType, data), "materials");
    assetTypeManager.createAssetType(Mesh.class, (urn, assetType, data) -> OpenGLMesh.create(urn, assetType, data, this), "mesh");
    assetTypeManager.createAssetType(SkeletalMesh.class, (urn, assetType, data) -> OpenGLSkeletalMesh.create(urn, assetType, data, this), "skeletalMesh");
    assetTypeManager.createAssetType(MeshAnimation.class, MeshAnimationImpl::new, "animations", "skeletalMesh");
    assetTypeManager.createAssetType(Atlas.class, Atlas::new, "atlas");
    assetTypeManager.createAssetType(MeshAnimationBundle.class, MeshAnimationBundle::new, "skeletalMesh", "animations");
    assetTypeManager.createAssetType(Subtexture.class, Subtexture::new);
}
Also used : PNGTextureFormat(org.terasology.engine.rendering.assets.texture.PNGTextureFormat) Atlas(org.terasology.engine.rendering.assets.atlas.Atlas) Shader(org.terasology.engine.rendering.assets.shader.Shader) Texture(org.terasology.engine.rendering.assets.texture.Texture) ModuleAssetScanner(org.terasology.gestalt.assets.module.ModuleAssetScanner) GL_TEXTURE_WRAP_T(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T) GL_TEXTURE_WRAP_S(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S) GLSLMaterial(org.terasology.engine.rendering.opengl.GLSLMaterial) GL11.glBindTexture(org.lwjgl.opengl.GL11.glBindTexture) GL_TEXTURE_2D(org.lwjgl.opengl.GL11.GL_TEXTURE_2D) ByteBuffer(java.nio.ByteBuffer) Subtexture(org.terasology.engine.rendering.assets.texture.subtexture.Subtexture) Lists(com.google.common.collect.Lists) OpenGLTexture(org.terasology.engine.rendering.opengl.OpenGLTexture) Font(org.terasology.engine.rendering.assets.font.Font) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) OpenGLMesh(org.terasology.engine.rendering.opengl.OpenGLMesh) GL12(org.lwjgl.opengl.GL12) FontImpl(org.terasology.engine.rendering.assets.font.FontImpl) GL11(org.lwjgl.opengl.GL11) MeshAnimationImpl(org.terasology.engine.rendering.assets.animation.MeshAnimationImpl) BlockingDeque(java.util.concurrent.BlockingDeque) AssetType(org.terasology.gestalt.assets.AssetType) OpenGLSkeletalMesh(org.terasology.engine.rendering.opengl.OpenGLSkeletalMesh) GL11.glGenTextures(org.lwjgl.opengl.GL11.glGenTextures) SkeletalMesh(org.terasology.engine.rendering.assets.skeletalmesh.SkeletalMesh) GameThread(org.terasology.engine.core.GameThread) DisplayDeviceInfo(org.terasology.engine.core.subsystem.DisplayDeviceInfo) RenderingSubsystemFactory(org.terasology.engine.core.subsystem.RenderingSubsystemFactory) MeshAnimationBundle(org.terasology.engine.rendering.assets.animation.MeshAnimationBundle) Consumer(java.util.function.Consumer) Queues(com.google.common.collect.Queues) List(java.util.List) Context(org.terasology.engine.context.Context) Material(org.terasology.engine.rendering.assets.material.Material) PNGTextureFormat(org.terasology.engine.rendering.assets.texture.PNGTextureFormat) GLSLShader(org.terasology.engine.rendering.opengl.GLSLShader) GL11.glDeleteTextures(org.lwjgl.opengl.GL11.glDeleteTextures) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) MeshAnimation(org.terasology.engine.rendering.assets.animation.MeshAnimation) GL11.glTexParameterf(org.lwjgl.opengl.GL11.glTexParameterf) Atlas(org.terasology.engine.rendering.assets.atlas.Atlas) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) Subtexture(org.terasology.engine.rendering.assets.texture.subtexture.Subtexture) Texture(org.terasology.engine.rendering.assets.texture.Texture) GL11.glBindTexture(org.lwjgl.opengl.GL11.glBindTexture) OpenGLTexture(org.terasology.engine.rendering.opengl.OpenGLTexture) MeshAnimationImpl(org.terasology.engine.rendering.assets.animation.MeshAnimationImpl) FontImpl(org.terasology.engine.rendering.assets.font.FontImpl) MeshAnimationBundle(org.terasology.engine.rendering.assets.animation.MeshAnimationBundle)

Example 2 with Texture

use of org.terasology.engine.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class HeadlessGraphics method registerCoreAssetTypes.

@Override
public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) {
    assetTypeManager.createAssetType(Font.class, FontImpl::new, "fonts");
    AssetType<Texture, TextureData> texture = assetTypeManager.createAssetType(Texture.class, (urn, assetType, data) -> new HeadlessTexture(urn, assetType, data, new HeadlessTexture.DisposalAction()), "textures", "fonts");
    assetTypeManager.getAssetFileDataProducer(texture).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getPath().get(1).equals("textures")));
    assetTypeManager.getAssetFileDataProducer(texture).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getPath().get(1).equals("fonts")));
    assetTypeManager.createAssetType(Shader.class, HeadlessShader::new, "shaders");
    assetTypeManager.createAssetType(Material.class, HeadlessMaterial::new, "materials");
    assetTypeManager.createAssetType(Mesh.class, HeadlessMesh::new, "mesh");
    assetTypeManager.createAssetType(SkeletalMesh.class, HeadlessSkeletalMesh::new, "skeletalMesh");
    assetTypeManager.createAssetType(MeshAnimation.class, MeshAnimationImpl::new, "animations");
    assetTypeManager.createAssetType(Atlas.class, Atlas::new, "atlas");
    assetTypeManager.createAssetType(Subtexture.class, Subtexture::new);
}
Also used : PNGTextureFormat(org.terasology.engine.rendering.assets.texture.PNGTextureFormat) Atlas(org.terasology.engine.rendering.assets.atlas.Atlas) Shader(org.terasology.engine.rendering.assets.shader.Shader) HeadlessMesh(org.terasology.engine.core.subsystem.headless.assets.HeadlessMesh) Texture(org.terasology.engine.rendering.assets.texture.Texture) HeadlessSkeletalMesh(org.terasology.engine.core.subsystem.headless.assets.HeadlessSkeletalMesh) CanvasRenderer(org.terasology.nui.canvas.CanvasRenderer) HeadlessMaterial(org.terasology.engine.core.subsystem.headless.assets.HeadlessMaterial) Subtexture(org.terasology.engine.rendering.assets.texture.subtexture.Subtexture) DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) Font(org.terasology.engine.rendering.assets.font.Font) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) FontImpl(org.terasology.engine.rendering.assets.font.FontImpl) HeadlessShader(org.terasology.engine.core.subsystem.headless.assets.HeadlessShader) HeadlessDisplayDevice(org.terasology.engine.core.subsystem.headless.device.HeadlessDisplayDevice) MeshAnimationImpl(org.terasology.engine.rendering.assets.animation.MeshAnimationImpl) AssetType(org.terasology.gestalt.assets.AssetType) SkeletalMesh(org.terasology.engine.rendering.assets.skeletalmesh.SkeletalMesh) RenderingSubsystemFactory(org.terasology.engine.core.subsystem.RenderingSubsystemFactory) HeadlessTexture(org.terasology.engine.core.subsystem.headless.assets.HeadlessTexture) HeadlessCanvasRenderer(org.terasology.engine.core.subsystem.headless.renderer.HeadlessCanvasRenderer) ShaderManagerHeadless(org.terasology.engine.core.subsystem.headless.renderer.ShaderManagerHeadless) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) Context(org.terasology.engine.context.Context) Material(org.terasology.engine.rendering.assets.material.Material) PNGTextureFormat(org.terasology.engine.rendering.assets.texture.PNGTextureFormat) HeadlessRenderingSubsystemFactory(org.terasology.engine.core.subsystem.headless.renderer.HeadlessRenderingSubsystemFactory) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) ShaderManager(org.terasology.engine.rendering.ShaderManager) MeshAnimation(org.terasology.engine.rendering.assets.animation.MeshAnimation) Atlas(org.terasology.engine.rendering.assets.atlas.Atlas) HeadlessMaterial(org.terasology.engine.core.subsystem.headless.assets.HeadlessMaterial) HeadlessMesh(org.terasology.engine.core.subsystem.headless.assets.HeadlessMesh) Texture(org.terasology.engine.rendering.assets.texture.Texture) HeadlessTexture(org.terasology.engine.core.subsystem.headless.assets.HeadlessTexture) MeshAnimationImpl(org.terasology.engine.rendering.assets.animation.MeshAnimationImpl) HeadlessShader(org.terasology.engine.core.subsystem.headless.assets.HeadlessShader) FontImpl(org.terasology.engine.rendering.assets.font.FontImpl) HeadlessTexture(org.terasology.engine.core.subsystem.headless.assets.HeadlessTexture) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) HeadlessSkeletalMesh(org.terasology.engine.core.subsystem.headless.assets.HeadlessSkeletalMesh) Subtexture(org.terasology.engine.rendering.assets.texture.subtexture.Subtexture)

Example 3 with Texture

use of org.terasology.engine.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class FontDataBuilder method endCharacter.

public FontDataBuilder endCharacter() {
    Texture page = pages.get(characterPage);
    FontCharacter character = new FontCharacter(((float) characterX / page.getWidth()), ((float) characterY / page.getHeight()), characterWidth, characterHeight, characterXOffset, characterYOffset, characterXAdvance, page, pageMats.get(characterPage));
    characters.put(currentCharacterId, character);
    return this;
}
Also used : Texture(org.terasology.engine.rendering.assets.texture.Texture)

Example 4 with Texture

use of org.terasology.engine.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class PreviewWorldScreen method genTexture.

private void genTexture() {
    int imgWidth = 384;
    int imgHeight = 384;
    ByteBuffer buffer = ByteBuffer.allocateDirect(imgWidth * imgHeight * Integer.BYTES);
    ByteBuffer[] data = new ByteBuffer[] { buffer };
    ResourceUrn uri = new ResourceUrn("engine:terrainPreview");
    TextureData texData = new TextureData(imgWidth, imgHeight, data, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
    texture = Assets.generateAsset(uri, texData, Texture.class);
    previewImage = find("preview", UIImage.class);
    previewImage.setImage(texture);
}
Also used : TextureData(org.terasology.engine.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) UIImage(org.terasology.nui.widgets.UIImage) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Example 5 with Texture

use of org.terasology.engine.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class GLSLMaterial method bindTextures.

@Override
public void bindTextures() {
    if (isDisposed()) {
        return;
    }
    enable();
    for (int slot : textureMap.keys()) {
        Texture texture = textureMap.get(slot);
        if (texture.isDisposed()) {
            textureMap.remove(slot);
            logger.error("Attempted to bind disposed texture {}", texture);
        } else {
            shaderManager.bindTexture(slot, texture);
        }
    }
}
Also used : Texture(org.terasology.engine.rendering.assets.texture.Texture)

Aggregations

Texture (org.terasology.engine.rendering.assets.texture.Texture)15 TextureData (org.terasology.engine.rendering.assets.texture.TextureData)9 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)7 ByteBuffer (java.nio.ByteBuffer)6 Context (org.terasology.engine.context.Context)5 UIImage (org.terasology.nui.widgets.UIImage)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Config (org.terasology.engine.config.Config)4 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)4 Lists (com.google.common.collect.Lists)3 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 In (org.terasology.engine.registry.In)3 CoreScreenLayer (org.terasology.engine.rendering.nui.CoreScreenLayer)3 Assets (org.terasology.engine.utilities.Assets)3 WorldGeneratorManager (org.terasology.engine.world.generator.internal.WorldGeneratorManager)3 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3 Name (org.terasology.gestalt.naming.Name)3