|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef MATRIX_STACK_H |
|
19 #define MATRIX_STACK_H |
|
20 |
|
21 #include "Matrix.h" |
|
22 |
|
23 namespace shadergen |
|
24 { |
|
25 |
|
26 |
|
27 class MatrixStack |
|
28 { |
|
29 public: |
|
30 static const int MATRIX_STACK_DEPTH = 16; |
|
31 |
|
32 /*! |
|
33 * \brief |
|
34 * Default constructor. Initializes sp to 0. |
|
35 */ |
|
36 MatrixStack (void) |
|
37 { |
|
38 m_currDepth = 0; |
|
39 } |
|
40 |
|
41 /*! |
|
42 * \brief |
|
43 * glPushMatrix() implementation. |
|
44 */ |
|
45 void push (void) |
|
46 { |
|
47 SG_ASSERT(SG_IN_RANGE<int>(m_currDepth, 0, MATRIX_STACK_DEPTH - 1)); |
|
48 memcpy(&m_data[m_currDepth + 1], &m_data[m_currDepth], sizeof(Matrix)); |
|
49 m_currDepth++; |
|
50 } |
|
51 |
|
52 /*! |
|
53 * \brief |
|
54 * glPopMatrix() implementation |
|
55 */ |
|
56 void pop (void) |
|
57 { |
|
58 SG_ASSERT(SG_IN_RANGE<int>(m_currDepth, 1, MATRIX_STACK_DEPTH - 0)); |
|
59 m_currDepth--; |
|
60 } |
|
61 |
|
62 /*! |
|
63 * \brief |
|
64 * Get the topmost matrix in the stack. |
|
65 * |
|
66 * \returns |
|
67 * Returns the topmost matrix in the stack. |
|
68 */ |
|
69 Matrix& top (void) |
|
70 { |
|
71 SG_ASSERT(SG_IN_RANGE<int>(m_currDepth, 0, MATRIX_STACK_DEPTH - 1)); |
|
72 return m_data[m_currDepth]; |
|
73 } |
|
74 |
|
75 private: |
|
76 |
|
77 int m_currDepth; |
|
78 Matrix m_data[MATRIX_STACK_DEPTH]; |
|
79 }; |
|
80 |
|
81 } /* namespace shadergen */ |
|
82 |
|
83 #endif /* MATRIX_STACK_H */ |