983 / cppglsl

C++11 implementation of vec2, vec3, vec4, mat2, mat3, mat4 and sampler2D with swizzeling.
The Unlicense
5 stars 0 forks source link

Matrix vector multiplication incorrect #2

Open deanm opened 8 years ago

deanm commented 8 years ago

The matrix * vector multiplication is incorrect, effectively treating the matrix as row major when it is column major.

For example for (int j = 0; j < N; j++) sum += a[i][j] * b[j]; should be for (int j = 0; j < N; j++) sum += a[j][i] * b[j];, etc.

983 commented 8 years ago

This project is EOL but that bug is very embarrassing so I fixed it anyway.

deanm commented 8 years ago

Yeah, I assumed the project wasn't really maintained. But I think it's a really nice idea to be able to easily test shaders as C++ (even just for debugging sake). Know of any similar efforts?

983 commented 8 years ago

The most similar library I found was https://github.com/gwiazdorrr/CxxSwizzle but last I checked (two years ago) it did not support other operators than the assignment operator on swizzled operands.

Due to the syntax of C++, it is impossible to parse all possible GLSL code as C++ code anyway, so this approach can't possibly yield a perfect solution, which is why I discontinued this project.

A more complete solution might be to use the Mesa 3D library which can do software OpenGL emulation and also has a glsl_compiler that outputs an AST.