Bug 49703 - incorrect macros #define M(row,col) m[col*4+row]
Summary: incorrect macros #define M(row,col) m[col*4+row]
Status: RESOLVED NOTABUG
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: 8.0
Hardware: All All
: medium major
Assignee: mesa-dev
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-09 12:33 UTC by Chuprin Vladislav
Modified: 2012-05-09 21:14 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Chuprin Vladislav 2012-05-09 12:33:17 UTC
In function _math_matrix_frustum you use incorrect macros in this place

void
_math_matrix_frustum( GLmatrix *mat,
		      GLfloat left, GLfloat right,
		      GLfloat bottom, GLfloat top,
		      GLfloat nearval, GLfloat farval )
{
   GLfloat x, y, a, b, c, d;
   GLfloat m[16];

   x = (2.0F*nearval) / (right-left);
   y = (2.0F*nearval) / (top-bottom);
   a = (right+left) / (right-left);
   b = (top+bottom) / (top-bottom);
   c = -(farval+nearval) / ( farval-nearval);
   d = -(2.0F*farval*nearval) / (farval-nearval);  /* error? */

<b>#define M(row,col)  m[col*4+row]</b>
   M(0,0) = x;     M(0,1) = 0.0F;  M(0,2) = a;      M(0,3) = 0.0F;
   M(1,0) = 0.0F;  M(1,1) = y;     M(1,2) = b;      M(1,3) = 0.0F;
   M(2,0) = 0.0F;  M(2,1) = 0.0F;  M(2,2) = c;      M(2,3) = d;
   M(3,0) = 0.0F;  M(3,1) = 0.0F;  M(3,2) = -1.0F;  M(3,3) = 0.0F;
#undef M

   matrix_multf( mat, m, MAT_FLAG_PERSPECTIVE );
}

If we want use element m[2][3], we must use m[2*4+3] where 2 - row and 3 - col, but not vice versa.
Correct macros
#define M(row,col)  m[row*4+col]

Sorry for my english.
Comment 1 Brian Paul 2012-05-09 12:51:27 UTC
OpenGL matrices are stored in column-major order.  The macros are correct.  The glFrustum function has been working properly for many years.
Comment 2 Chuprin Vladislav 2012-05-09 21:14:08 UTC
Sorry I did not know it. Thank you for your answer.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.