Jump to content

[1.6.4] [Solved] Massive lag setting textures inside a loop


lexwebb

Recommended Posts

I'm trying to render 16*16 individual cube models with different textures all at once, that's 256 texture sets... This is causing me horrendous amounts of lag, ie. 3FPS when i usually get 150+.

 

6XI46.jpg

 

I cant quite work out why its taking SO MUCH time to reset the textures each time.

 

for(int xPos = 0; xPos < 16; xPos++){
		for(int yPos = 0; yPos < 16; yPos++){		
			GL11.glPushMatrix();
			GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F,
					(float) z + 0.5F);

			Opticraft.textureLoader.loadTexture(imageList[xPos][yPos]);

			GL11.glPushMatrix();

			GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
			GL11.glScalef(0.5f, 0.5f, 0.5f);

			GL11.glTranslatef(0.1f * xPos, 0.1f * yPos, 0.0f);

			cModel.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F,
					0.0625F);

			GL11.glPopMatrix();
			GL11.glPopMatrix();	
		}
	}

 

I've a custom texture loader that borrows some inner functions from Minecraft TextureUtil's in my TextureLoader:

 

public void loadTexture(BufferedImage bufferedimage){
    try
    {
        boolean flag = false;
        boolean flag1 = false;

        TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedimage, flag, flag1);
    
        if (inputstream != null)
        {
            inputstream.close();
        }
    } catch (IOException ex){
    	ex.printStackTrace();
    }
}

 

This basically bypasses the Resource Location setting, so if anything, should be quicker than setting from resourceLocation.

 

Is this a really stupid way of doing things? There are a few different ways i can do what i'm trying to do, but this would be my preferred.

Link to comment
Share on other sites

Is this a really stupid way of doing things?

Yes.

 

You're not saving your textures anywhere and are constantly creating new ones.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Well, i found out a better way of doing it, i am now using a single white texture and am coloring each pixel using glColor4d. This, quite handily takes the alpha values from my textures, so now all i have to do is literally plug the texture in and it renders :).

 

6YJAS.jpg

 

Thanks for your help Draco!

Link to comment
Share on other sites

Also, that looks fantastic.

 

When I did a quickpass on a 3D printer block* I just rendered the item it printed if it had any in its output slot using RenderEntityItem and having a vaguely printerish Tile Entity.  It didn't look like a 3D printer, at least not as we know them, but it worked for what I was doing and didn't want to spend a lot of time making it look fancy.

 

Not visible well in this, but it was a silly thing I did because I was feeling silly.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

That's pretty cool :). I was going to do something pretty similar, but then i sas iChuns Sync mod and thought it would be freaking cool if the item were to build in front of you, which this will! The overall aim is to have it build pixel by pixel into the full item.

Link to comment
Share on other sites

Yup, that's definitely a neat idea.

 

Mine was just a kind of "survival, but limited creative" where I needed certain stuff just be readily available.

 

So mine can only have the item it's printing changed (added, removed) if the player is in creative mode.  Then it duplicates that stack every two and a half minutes or so into the output stack (which is a standard output slot).

 

It still has some bugs, but it's not intended for distribution. :)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.