开发者

What is supposed to happen with the transpose flag for glUniformMatrix with non-square matrices?

开发者 https://www.devze.com 2023-04-11 09:02 出处:网络
I encountered what seemed to me as strange behavior using glUniformMatrix4x3fv. Specifically when I give TRUE as for the transpose flag entire rows of my matrices are missing in my shader variable (an

I encountered what seemed to me as strange behavior using glUniformMatrix4x3fv. Specifically when I give TRUE as for the transpose flag entire rows of my matrices are missing in my shader variable (and those that are there are therefor out of order).

For example. Say I have in my GLSL shader:

mat4x3 T[m];

Then in my C++ OpenGL call I want to send a matrix whose entries are (stored in row-major order):

T = 
  1 2 3
 开发者_开发问答 4 5 6
  7 8 9 
  10 11 12
  101 102 103
  104 105 106
  107 108 109
  110 111 112
  101 102 103
  204 205 206
  207 208 209
  210 211 212
  ...

And I call

glUniformMatrix4x3fv(location,m,false,T);

Then I see in my shader that the each matrix comes out correctly as:

T[0] -> 
    1   4    7   10
    2   5    8   11
    3   6    9   12
T[1] -> 
  101 104  107  110
  102 105  108  111
  103 106  109  112
  ...

BUT, if I store my matrix on the C++ side as (again row-major order):

T = 
    1   4    7   10
    2   5    8   11
    3   6    9   12
  101 104  107  110
  102 105  108  111
  103 106  109  112
  201 204  207  210
  202 205  208  211
  203 206  209  212
  ...

And try to use the transpose flag as TRUE with:

glUniformMatrix4x3fv(location,m,true,T);

Then in my shader the matrices show up incorrectly as:

T[0] -> 
    1   4    7   10
    2   5    8   11
    3   6    9   12
T[1] -> 
  102 105  108  111
  103 106  109  112
  201 204  207  210
T[2] -> 
  203 206  209  212
  301 304  307  310
  302 305  308  311
  ... 

Every 4th row of my data is missing.

Is there a sensible reason for this? I find nothing in the spec (s2.1 p82).

GL_VERSION: 2.1 NVIDIA-1.6.36 GL_SHADING_LANGUAGE_VERSION: 1.20


Then in my C++ OpenGL call I want to send a matrix whose entries are (stored in row-major order):

That's not row-major order. That's column-major order.

Given the following 4x3 matrix:

1  4  7  10
2  5  8  11
3  6  9  12

This is what a C++ array of this data in column-major order would look like:

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}

That's what your data is. Feel free to insert space wherever you want; it's entirely irrelevant.

This is what the same data in row-major order looks like:

{1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12}

As to the specific issue you encountered with transposing your data for 4x3 matrices, it may simply be a driver bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号