Jump to content

dxCreateShader mixing up other dxCreateShader


RizoN

Recommended Posts

Hello. I've ran into some strange issue.

I've got two seperate tables which store to themselves shader from same location e.g files/shaders/hud_mask.fx
so to show it as an example, it'd look like this:
 

Spoiler

FirstTable = {}
FirstTable.__index = FirstTable

function FirstTable:new()

	local tTable = setmetatable({}, FirstTable)

	tTable.hudMaskShader = dxCreateShader("files/shaders/hud_mask.fx")
	tTable.radarTexture = dxCreateTexture("files/images/map.png")
	tTable.maskTexture = dxCreateTexture("files/images/circle_mask.png")

	dxSetShaderValue( tTable.hudMaskShader, "sPicTexture", tTable.radarTexture )
	dxSetShaderValue( tTable.hudMaskShader, "sMaskTexture", tTable.maskTexture )

	return tTable

end



SecondTable = {}
SecondTable.__index = SecondTable

function SecondTable:new()

	local tTable = setmetatable({}, SecondTable)

	tTable.otherShader = dxCreateShader("files/shaders/hud_mask.fx")
	tTable.otherTexture = dxCreateTexture("files/images/other.png")
	tTable.otherMaskTexture = dxCreateTexture("files/images/other_mask.png")

	dxSetShaderValue( tTable.otherShader, "sPicTexture", tTable.otherTexture )
	dxSetShaderValue( tTable.otherShader, "sMaskTexture", tTable.otherMaskTexture )

	return tTable

end


local myFirstTable = FirstTable:new()
local mySecondTable = SecondTable:new()

 

 

This is just an example code.

My problem with this system of usage is, i am expecting when i use dxCreateShader for same file twice but in two different tables that it will return me two different instances of the same shader so that they don't collide with each other. But for me, they do collide for unknown reason.

The second shader and its data stored in sPicTexture and sMaskTexture overwrite first shader even though they shouldn't be connected at all.

How can i solve this?

Thanks for reading.

Link to comment

Do not expect me to help you, i'm noob at this. Sorry :(

If i understand with colliding you mean overwriting right? so both first and second, 2 different objects (that's why you get 2 differents "signature"), will have same data

3 hours ago, RizoN said:

The second shader and its data stored in sPicTexture and sMaskTexture overwrite first shader

 

But does this happen if you make 2 copy of the .fx shader file?

 

In the code i can't see any cause of overwriting... even the only variable with the same name in the script is tTable which is local.... but i'm a noob at this.

I just want to make this as clear as possible.

Link to comment
20 minutes ago, LoPollo said:

Do not expect me to help you, i'm noob at this. Sorry :(

If i understand with colliding you mean overwriting right? so both first and second, 2 different objects (that's why you get 2 differents "signature"), will have same data

 

But does this happen if you make 2 copy of the .fx shader file?

 

In the code i can't see any cause of overwriting... even the only variable with the same name in the script is tTable which is local.... but i'm a noob at this.

I just want to make this as clear as possible.

2 Instances of same shader file can co-exist and have different data for same attributes. Yes it's impossible that they overwrite each other but still it's happening for unknown reason. Making copies of .fx is not a solution I'm looking for because it should be possible to do with dxCreateShader in multiple instances. (In fact in my actual script, the first table already has in each instance of itself the same shader, and it works with seperate images, but when second table gets created, it somehow overwrites first table even though they're not connected in any way.)

I have no idea how to fix this issue.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...