Skip to content

SetUniform doesn't handle vector 2 properly #510

@destructor465

Description

@destructor465

The SetUniform function doesn't work properly for vectors. For example if I do this:

rl.SetUniform(positionLoc, []float32{position.X, position.Y}, int32(rl.ShaderUniformVec2))

the uniform doesn't get updated, I looked into why and found out that issue is the count parameter.
I think it expects number of values as in if it's vector 2 uniform then it's number of vectors not just floats.
So I modified the raylib-go locally to fix the issue, my current solution is this:

// SetUniform - Set shader value uniform
func SetUniform(locIndex int32, value []float32, uniformType int32) {
	comps := 1
	switch uniformType {
	case int32(ShaderUniformVec2):
		comps = 2
	case int32(ShaderUniformVec3):
		comps = 3
	case int32(ShaderUniformVec4):
		comps = 4
	default:
		comps = 1 // float/bool/int
	}
	count := len(value) / comps
	if count < 1 {
		count = 1
	}
	C.rlSetUniform(C.int(locIndex), unsafe.Pointer(unsafe.SliceData(value)), C.int(uniformType), C.int(count))
}

But this doesn't fully fix it for other types such as int vec or u int vec, it's enough for my case.
Another solution could be to just expose the count.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions