Recent Posts

Pages: [1] 2 3 ... 10
Support / [Tips] Huge texture uploading (memory tricks)
« Last post by AeroShark333 on April 03, 2020, 08:52:58 pm »

I have been digging around a little for the memory issues I have concerning texture uploading since I do use pretty huge textures.
It seems that jPCT-AE requires twice the size of a texture (in peak memory usage) in JVM RAM: the original pixeldata of the texture + the buffer used for uploading.
But I believe that on modern day devices you can actually use tricks to consume near nothing in the JVM RAM when loading such huge textures.
I believe jPCT-AE doesn't support these features out of the box because it's been directly ported from the PC version and to provide backwards compatibility with the very old devices.

Here's the class I use to upload textures now (feel free to use it or make your own modifications to it):
Code: [Select]
package com.aeroshark333.artofearthify.utils;

import android.opengl.GLES20;
import android.opengl.GLUtils;

import com.threed.jpct.RGBColor;
import com.threed.jpct.Texture;

// Created by Abiram/AeroShark333
public class CustomTexture extends Texture {
    final Bitmap bmp;

    public CustomTexture(Bitmap image) {
        super(2, 2, RGBColor.BLACK);
        this.bmp = image;

    public int loadTexture(final boolean forceNearest, final boolean keepInMemory){
        final int[] textureHandle = new int[1];

        GLES20.glGenTextures(1, textureHandle, 0);

        if (textureHandle[0] != 0)
            // Bind to the texture in OpenGL
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

            // Set filtering
            if (!forceNearest) {
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
            }else {
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

            // Load the bitmap into the bound texture.
            GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);

            // Recycle the bitmap, since its data has been loaded into OpenGL.
            if (!keepInMemory) {

        if (textureHandle[0] == 0)
            throw new RuntimeException("Error loading texture.");

        return textureHandle[0];

One could use the CustomTexture constructor from any Thread but the CustomTexture#loadTexture(boolean,boolean) method needs to be called from the GLThread.
This implementation is kinda very simple and it doesn't cover all of jPCT-AE's texture features (and it probably isn't really (easily) possible to have texture manipulation/effects like jPCT-AE supports them out of the box). However, the uploading process seems much faster using this method too. Also, this could potentially solve memory issues if you have them.

Now, I did say you could use near nothing in JVM RAM, so what about the Bitmap that is passed to this CustomTexture?
Well, as since Android 8.0, you can load Bitmap's immediately into the hardware-level (probably GPU..?), meaning that the Bitmap is not stored in the JVM RAM.
That is if you use Bitmap.Config.HARDWARE when you decode your image file (from resources, online of file):
Unfortunately, jPCT-AE does not seem to support Bitmap's that have been created using this Config, because of the immutability and inaccessibility of the Bitmap pixels.
However, but the CustomTexture class would work with Bitmap's that are using this Config.

I hope this could be useful for someone someday.
Feel free to give your thoughts and ideas :)

Support / Re: RenderToTexture and alpha blending problem
« Last post by MichaelJPCT on March 30, 2020, 12:04:28 pm »
hi Egon,
don't worry about this, i just figured out this method can't get me the same visual effect at all, it's wrong method.
setAlphaWrites(false) can let me get a texture of the same look, just that it can't be transparent so it can't be put back to the main scene.
the blending is always correct, i didn't understand it, now i understand.
Support / Re: RenderToTexture and alpha blending problem
« Last post by MichaelJPCT on March 29, 2020, 09:56:25 am »
i just tried, it doesnt change. i think the first time the texture is used, alpha channel is automatically created.
if i remove the channel after the first time, i get a total black texture after render.
but to the npot texture of screen size, i cant call removeAlpha, or the app crashes.
i tried creating npot texture (but with pot size) for this case, but the result doesnt differ from Texture(x,y).
Support / Re: RenderToTexture and alpha blending problem
« Last post by EgonOlsen on March 28, 2020, 09:52:05 pm »
Have you tried to use the,%20int,%20int) constructor instead to force the texture to have an alpha channel? Maybe that helps...
Support / Re: RenderToTexture and alpha blending problem
« Last post by MichaelJPCT on March 28, 2020, 02:55:35 pm »
i tested on 2 different gpu , same result.
the rectangle holding the rtt texture uses a shader which just copies texture color to gl_fragcolor.
Support / RenderToTexture and alpha blending problem
« Last post by MichaelJPCT on March 28, 2020, 02:37:44 pm »
hi Egon,
i encounter a strange problem.
i want to render some clouds into textures and put them into rectangle meshes then put them back to the scene. the replaced method is putting the clouds directly into the scene.
there is a far scene where nothing but clouds are in, and the far scene is rendered without depth test/depth write.
i believe the environment for rtt is the same as the non rtt one - same shader, same depth test setting.
but the rtt texture doesnt look the same.
without rtt, the overlapping particles blend, the result looks thick. but with rtt it seems only one layer remains, which indicates a replace method rather than blending.
and even if the rtt texture has opaque background, the particles make the texture look-through. the below screenshots are comparison of 2 methods .
 the large white area is because i clear the rtt fb with color 0xffffffff, which is not necessary, but it indicates the opaque background was lost because of the particles. i also tried to use an opaque mesh as background, same result.
turning depth test on, doesnt change the result either.
the texture for rtt is created with Texture(x,y) method.
more strangely, the main scene is also rendered into a texture(npot) then blit into the true fb, but the clouds directly in main scene doesnt change the npot texture to transparent.

why would the rtt result be different from directly rendering into the main scene?

Projects / Re: my project - Vehicle Simulation
« Last post by MichaelJPCT on March 19, 2020, 08:24:44 pm »
you are mostly right.
but there is no filter, the location of particles are random and they are transparent, somewhere it's thicker or thinner so the blended color varies even with just white color. the bottom is set to grey, yes.
the theory is quite simple.
the good side is, little texture is needed, and it has 3D shape. the bad side is, slower, and does not look very real.

Projects / Re: my project - Vehicle Simulation
« Last post by AeroShark333 on March 19, 2020, 01:11:59 pm »
I believe you're using circles as some kind of base for these cloud particles? And you're having a multiple of these circles for each cloud, I guess?
And then applying them with a random filter (in shader?) so it creates these pixel holes so it looks more cloudy.
I guess the color is either white (top) or gray (bottom).

I believe it'd look better with even smaller circle particles but it'd be heavy for devices I suppose...
Projects / Re: my project - Vehicle Simulation
« Last post by MichaelJPCT on March 16, 2020, 06:07:38 pm »
clouds , made of groups of randomly placed particles , rendered using a shader.
Support / Re: render thread question
« Last post by EgonOlsen on March 16, 2020, 08:05:40 am »
Depends on which renderer you are using. For the normal GL renderer, the work is done after World.draw(); The AWTGLRenderer renders in another thread, you can detect if it's done or not by using the IRenderHook.
Pages: [1] 2 3 ... 10