1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: demo_GraphicsDrawing.h 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 46365 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef DEMO_GRAPHICS_DRAWING_H_ 17 #define DEMO_GRAPHICS_DRAWING_H_ 18 19 #include <nn/gx.h> 20 #include <nn/util/util_NonCopyable.h> 21 22 #include "demo/RenderData/demo_TextsRenderData.h" 23 #include "demo/RenderData/demo_TrianglesRenderData.h" 24 25 #include "demo/ShaderProgram/demo_ShaderManager.h" 26 27 namespace demo 28 { 29 /*! 30 @brief Class to perform 2D rendering for CTR 31 */ 32 33 class GraphicsDrawing : private nn::util::NonCopyable<GraphicsDrawing> 34 { 35 public: 36 GraphicsDrawing(void); 37 virtual ~GraphicsDrawing(void); 38 39 public: 40 virtual void Initialize(void); 41 virtual void Finalize(void); 42 43 public: 44 /*! 45 @brief Initial processing for the 2D triangle to be rendered. 46 47 Because this function is implicitly called inside DrawTriangle2d function, there is no need to explicitly call it. 48 Call this function immediately after Initialize function only when you want to change the maximum number of 2D triangles to be rendered on both upper and lower LCDs. 49 50 51 @param[in] maxTrianglesNum Maximum number of triangles to be rendered each on the upper and lower LCDs (default is MAX_TRIANGLES_NUM) 52 */ 53 virtual void InitializeTriangles(const u32 maxTrianglesNum = demo::MAX_TRIANGLES_NUM); 54 55 /*! 56 @brief Initial processing for the 2D quadrangle to be rendered. 57 58 Because this function is implicitly called inside DrawSquare2d function, there is no need to explicitly call it. 59 Call this function immediately after Initialize function call only when you want to change the maximum number of 2D quadrangles (including points and straight lines) to be rendered on both upper and lower LCDs. 60 61 62 @param[in] maxSquaresNum Maximum number of quadrangles to be rendered each on the upper and lower LCDs (default is MAX_SQUARES_NUM) 63 */ 64 virtual void InitializeSquares(const u32 maxSquaresNum = demo::MAX_SQUARES_NUM); 65 66 /*! 67 @brief Initial processing for the 2D text to be rendered. 68 69 Because this function is implicitly called inside DrawText2d function, there is no need to explicitly call it. 70 Call this function immediately after Initialize function call only when you want to change the maximum number of characters in the 2D text to be rendered on both upper and lower LCDs. 71 72 73 @param[in] maxLength Maximum number of characters to be rendered each on the upper and lower LCDs (default is MAX_TEXT_NUM) 74 */ 75 virtual void InitializeTexts(const u32 maxLength = demo::MAX_TEXT_LENGTH); 76 77 public: 78 /*! 79 @brief Sets the size of the window to render in 2D. 80 81 @param[in] windowWidth Window width 82 @param[in] windowWidth Window height 83 */ 84 virtual void SetWindowSize(const f32 windowWidth, const f32 windowHeight); 85 86 /*! 87 @brief Gets the size of the window to render in 2D. 88 89 @param[out] windowWidth Window width 90 @param[out] windowWidth Window height 91 */ 92 virtual void GetWindowSize(f32& windowWidth, f32& windowHeight); 93 94 /*! 95 @brief Sets the vertex color of the primitive to render in 2D. 96 97 @param[in] red Vertex color red component ([0.0f,1.0f]) 98 @param[in] green Vertex color green component ([0.0f,1.0f]) 99 @param[in] blue Vertex color blue component ([0.0f,1.0f]) 100 @param[in] alpha Vertex color alpha component ([0.0f,1.0f]) 101 */ 102 virtual void SetColor(const f32 red, const f32 green, const f32 blue, const f32 alpha); 103 104 /*! 105 @brief Sets the vertex color of the primitive to render in 2D. 106 107 @param[in] red Vertex color red component ([0.0f,1.0f]) 108 @param[in] green Vertex color green component ([0.0f,1.0f]) 109 @param[in] blue Vertex color blue component ([0.0f,1.0f]) 110 */ 111 virtual void SetColor(const f32 red, const f32 green, const f32 blue); 112 113 /*! 114 @brief Sets the depth value for the primitive to render in 2D. 115 116 @param[in] depth2d Depth value for normalized device coordinates ([0.0f,1.0f]) 117 */ 118 virtual void SetDepth(const f32 depth); 119 120 /*! 121 @brief Sets so the depth value is automatically decreased each time the primitive is rendered in 2D. 122 123 @param[in] enableAutoDepth2d Whether to set so depth value is automatically decreased (true or false) 124 */ 125 virtual void SetAutoDepth(const bool enableAutoDepth); 126 127 /*! 128 @brief Depth value is decreased when primitive is rendered in 2D. 129 */ 130 virtual void DecrementDepth(void); 131 132 public: 133 /*! 134 @brief Sets the size when a point is rendered in 2D. 135 136 @param[in] pointSize Point size in pixels ([1.0f,]) 137 */ 138 virtual void SetPointSize(const f32 pointSize); 139 140 /*! 141 @brief Renders the point specified in the window coordinate system in 2D. 142 143 @param[in] windowCoordinateX X-coordinate of center of point in the window coordinate system (f32 range) 144 @param[in] windowCoordinateY Y-coordinate of center of point in the window coordinate system (f32 range) 145 */ 146 virtual void DrawPoint(const f32 windowCoordinateX, const f32 windowCoordinateY); 147 148 public: 149 /*! 150 @brief Sets width of line when a line is rendered in 2D. 151 152 @param[in] lineWidth Width of line in pixels ([1.0f,]) 153 */ 154 virtual void SetLineWidth(const f32 lineWidth); 155 156 /*! 157 @brief Renders the line segment specified in the window coordinate system in 2D. 158 159 @param[in] windowCoordinateX0 X-coordinate of the start point of the line segment in the window coordinate system (f32 range) 160 @param[in] windowCoordinateY0 Y-coordinate of the start point of the line segment in the window coordinate system (f32 range) 161 @param[in] windowCoordinateX1 X-coordinate of the end point of the line segment in the window coordinate system (f32 range) 162 @param[in] windowCoordinateY1 Y-coordinate of the end point of the line segment in the window coordinate system (f32 range) 163 */ 164 virtual void DrawLine(const f32 windowCoordinateX0, const f32 windowCoordinateY0, 165 const f32 windowCoordinateX1, const f32 windowCoordinateY1); 166 167 public: 168 /*! 169 @brief Renders the quadrangle specified in window coordinates in 2D. 170 171 Provide vertex data in counterclockwise direction. 172 173 @param[in] windowCoordinateX0 X-coordinate of the top-left vertex of the quadrangle in the window coordinate system (f32 range) 174 @param[in] windowCoordinateY0 Y-coordinate of the top-left vertex of the quadrangle in the window coordinate system (f32 range) 175 @param[in] windowCoordinateX1 X-coordinate of the bottom-left vertex of the quadrangle in the window coordinate system (f32 range) 176 @param[in] windowCoordinateY1 Y-coordinate of the bottom-left vertex of the quadrangle in the window coordinate system (f32 range) 177 @param[in] windowCoordinateX2 X-coordinate of the bottom-right vertex of the quadrangle in the window coordinate system (f32 range) 178 @param[in] windowCoordinateY2 Y-coordinate of the bottom-right vertex of the quadrangle in the window coordinate system (f32 range) 179 @param[in] windowCoordinateX3 X-coordinate of the top-right vertex of the quadrangle in the window coordinate system (f32 range) 180 @param[in] windowCoordinateY3 Y-coordinate of the top-right vertex of the quadrangle in the window coordinate system (f32 range) 181 */ 182 virtual void FillSquare(const f32 windowCoordinateX0, const f32 windowCoordinateY0, 183 const f32 windowCoordinateX1, const f32 windowCoordinateY1, 184 const f32 windowCoordinateX2, const f32 windowCoordinateY2, 185 const f32 windowCoordinateX3, const f32 windowCoordinateY3); 186 187 public: 188 /*! 189 @brief Renders the rectangle specified in window coordinates in 2D. 190 191 @param[in] windowCoordinateX X-coordinate of the top-left vertex of the rectangle in the window coordinate system (f32 range) 192 @param[in] windowCoordinateY Y-coordinate of the top-left vertex of the rectangle in the window coordinate system (f32 range) 193 @param[in] width Length of the side in the X-direction of the rectangle in the window coordinate system (f32 range) 194 @param[in] height Length of the side in the Y-direction of the rectangle in the window coordinate system (f32 range) 195 */ 196 virtual void FillRectangle(const f32 windowCoordinateX, 197 const f32 windowCoordinateY, 198 const f32 width, const f32 height); 199 public: 200 /*! 201 @brief Renders the triangle specified in window coordinates in 2D. 202 203 Provide vertex data in counterclockwise direction. 204 205 @param[in] windowCoordinateX0 X-coordinate of the first vertex of the triangle in the window coordinate system (f32 range) 206 @param[in] windowCoordinateY0 Y-coordinate of the first vertex of the triangle in the window coordinate system (f32 range) 207 @param[in] windowCoordinateX1 X-coordinate of the second vertex of the triangle in the window coordinate system (f32 range) 208 @param[in] windowCoordinateY1 Y-coordinate of the second vertex of the triangle in the window coordinate system (f32 range) 209 @param[in] windowCoordinateX2 X-coordinate of the third vertex of the triangle in the window coordinate system (f32 range) 210 @param[in] windowCoordinateY2 Y-coordinate of the third vertex of the triangle in the window coordinate system (f32 range) 211 */ 212 virtual void FillTriangle(const f32 windowCoordinateX0, const f32 windowCoordinateY0, 213 const f32 windowCoordinateX1, const f32 windowCoordinateY1, 214 const f32 windowCoordinateX2, const f32 windowCoordinateY2); 215 216 public: 217 /*! 218 @brief Sets the size when a font is rendered in 2D. 219 220 However, since the original font data size is 8x8 pixels, a font size of 8 is recommended. 221 222 @param[in] fontSize Font size in pixels ([1.0f,]) 223 */ 224 virtual void SetFontSize(const f32 fontSize); 225 226 /*! 227 @brief Renders text to the position specified in window coordinates. 228 229 Internally, creates a rectangle using TRIANGLE_STRIP, multiply by the pixels and font texture in pixel units generated when that rectangle is rasterized, and renders the string. 230 231 232 233 @param[in] windowCoordinateX X-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) 234 @param[in] windowCoordinateY Y-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) 235 @param[in] format Format string 236 */ 237 virtual void DrawText(const f32 windowCoordinateX, const f32 windowCoordinateY, const char* format, ...); 238 239 /*! 240 @brief Renders text to the position specified in window coordinates. 241 242 Internally, creates a rectangle using TRIANGLE_STRIP, multiply the pixels by font texture in pixel units generated when that rectangle is rasterized, and renders the string. 243 244 245 246 @param[in] windowCoordinateX X-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) 247 @param[in] windowCoordinateY Y-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) 248 @param[in] text String 249 */ 250 virtual void DrawTextBuffer(const f32 windowCoordinateX, const f32 windowCoordinateY, const char* textBuffer); 251 252 public: 253 /*! 254 @brief Displays result of rendering to the specified target. 255 */ 256 virtual void Flush(void); 257 258 protected: 259 virtual void FlushColorFillPrimitives(void); 260 virtual void FlushTexts(void); 261 262 public: 263 f32 m_Color[4]; 264 f32 m_Depth; 265 bool m_AutoDepth; 266 bool m_Padding0[3]; 267 f32 m_DepthValue; 268 269 f32 m_WindowWidth; 270 f32 m_WindowHeight; 271 272 public: 273 demo::ShaderManager m_ShaderManager; 274 275 protected: 276 bool m_InitializeTriangles; 277 bool m_InitializeSquares; 278 bool m_InitializeTexts; 279 bool m_Padding1; 280 281 protected: 282 u32 m_MaxTrianglesNum; 283 u32 m_TotalTrianglesNum; 284 protected: 285 u32 m_MaxSquaresNum; 286 u32 m_TotalSquaresNum; 287 protected: 288 u32 m_MaxTextLength; 289 u32 m_TotalTextLength; 290 291 protected: 292 bool m_UseColorFillProgram; 293 bool m_UseFontProgram; 294 bool m_Padding2[2]; 295 296 protected: 297 f32 m_PointSize; 298 f32 m_LineWidth; 299 300 demo::TrianglesRenderData m_TrianglesRenderData; 301 demo::TrianglesRenderData m_SquaresRenderData; 302 303 f32 m_FontSize; 304 demo::TextsRenderData m_TextsRenderData; 305 }; 306 307 } 308 309 #endif 310