Author Topic: Texture switching  (Read 2934 times)

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Texture switching
« on: June 03, 2016, 06:24:54 pm »
Is it possible to swap texture name assignments and texture info's while running a game?



eg assign like this

TextureManager m;
Texture tex1;
Texture tex2;


m.addTexture( "textureA ", tex1) ;
m.addTexture( "textureB", tex2) ;


//Then swap them ?


m.addTexture( "textureA", tex2) ;
m.addTexture( "textureB", tex1) ;


Maybe with a 3rd texture as temporary holder.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture switching
« Reply #1 on: June 04, 2016, 12:37:19 am »
That wouldn't swap textures on the objects...there's a replaceTexture()-method that can be used for that. But the actual question is: Why would you want to swap textures? It might be a better idea to do that on the objects and not in the manager.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Texture switching
« Reply #2 on: June 05, 2016, 12:22:29 am »
Just experimenting with some way of post processing, i wanted to rapidly switch between two.

Basically im creating a world with the textured object in it , using the object shader to perform a process on the shader that writes a result back to the same texture via the framebuffer.


I can't find the replaceTexture method  :-[

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture switching
« Reply #3 on: June 05, 2016, 07:56:10 pm »
It's in the TextureManager... ???

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Texture switching
« Reply #4 on: June 17, 2016, 02:23:21 am »
 
Would something like this work? to swap between two textures every time the function is called?

<code>
  private void swapTexture()
    {

        Temp = texture;
        texture=texture2;
        texture2=Temp;
        tm.replaceTexture("my_little_texture", texture2);
    }

</code>

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture switching
« Reply #5 on: June 17, 2016, 09:11:32 am »
It should.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Texture switching
« Reply #6 on: June 20, 2016, 01:37:11 pm »
I'm an idiot  ;D .

I was using the texture swapping as i wanted to avoid writing to a texture while simultaneously reading from it... completely unnecessary as the frame-buffer does the drawing first then outputs the result to the texture..

swapping them was also a very slow operation

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture switching
« Reply #7 on: June 20, 2016, 01:43:42 pm »
swapping them was also a very slow operation
Yes, because it may trigger a new texture upload.