/*---------------------------------------------------------------------------* Project: Horizon File: demo_GraphicsDrawing.h Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #ifndef DEMO_GRAPHICS_DRAWING_H_ #define DEMO_GRAPHICS_DRAWING_H_ #include #include #include "demo/RenderData/demo_TextsRenderData.h" #include "demo/RenderData/demo_TrianglesRenderData.h" #include "demo/ShaderProgram/demo_ShaderManager.h" namespace demo { /*! @brief Class to perform 2D rendering for CTR */ class GraphicsDrawing : private nn::util::NonCopyable { public: GraphicsDrawing(void); virtual ~GraphicsDrawing(void); public: virtual void Initialize(void); virtual void Finalize(void); public: /*! @brief Initial processing for the 2D triangle to be rendered. Because this function is implicitly called inside DrawTriangle2d function, there is no need to explicitly call it. 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. @param[in] maxTrianglesNum Maximum number of triangles to be rendered each on the upper and lower LCDs (default is MAX_TRIANGLES_NUM) */ virtual void InitializeTriangles(const u32 maxTrianglesNum = demo::MAX_TRIANGLES_NUM); /*! @brief Initial processing for the 2D quadrangle to be rendered. Because this function is implicitly called inside DrawSquare2d function, there is no need to explicitly call it. 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. @param[in] maxSquaresNum Maximum number of quadrangles to be rendered each on the upper and lower LCDs (default is MAX_SQUARES_NUM) */ virtual void InitializeSquares(const u32 maxSquaresNum = demo::MAX_SQUARES_NUM); /*! @brief Initial processing for the 2D text to be rendered. Because this function is implicitly called inside DrawText2d function, there is no need to explicitly call it. 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. @param[in] maxLength Maximum number of characters to be rendered each on the upper and lower LCDs (default is MAX_TEXT_NUM) */ virtual void InitializeTexts(const u32 maxLength = demo::MAX_TEXT_LENGTH); public: /*! @brief Sets the size of the window to render in 2D. @param[in] windowWidth Window width @param[in] windowWidth Window height */ virtual void SetWindowSize(const f32 windowWidth, const f32 windowHeight); /*! @brief Gets the size of the window to render in 2D. @param[out] windowWidth Window width @param[out] windowWidth Window height */ virtual void GetWindowSize(f32& windowWidth, f32& windowHeight); /*! @brief Sets the vertex color of the primitive to render in 2D. @param[in] red Vertex color red component ([0.0f,1.0f]) @param[in] green Vertex color green component ([0.0f,1.0f]) @param[in] blue Vertex color blue component ([0.0f,1.0f]) @param[in] alpha Vertex color alpha component ([0.0f,1.0f]) */ virtual void SetColor(const f32 red, const f32 green, const f32 blue, const f32 alpha); /*! @brief Sets the vertex color of the primitive to render in 2D. @param[in] red Vertex color red component ([0.0f,1.0f]) @param[in] green Vertex color green component ([0.0f,1.0f]) @param[in] blue Vertex color blue component ([0.0f,1.0f]) */ virtual void SetColor(const f32 red, const f32 green, const f32 blue); /*! @brief Sets the depth value for the primitive to render in 2D. @param[in] depth2d Depth value for normalized device coordinates ([0.0f,1.0f]) */ virtual void SetDepth(const f32 depth); /*! @brief Sets so the depth value is automatically decreased each time the primitive is rendered in 2D. @param[in] enableAutoDepth2d Whether to set so depth value is automatically decreased (true or false) */ virtual void SetAutoDepth(const bool enableAutoDepth); /*! @brief Depth value is decreased when primitive is rendered in 2D. */ virtual void DecrementDepth(void); public: /*! @brief Sets the size when a point is rendered in 2D. @param[in] pointSize Point size in pixels ([1.0f,]) */ virtual void SetPointSize(const f32 pointSize); /*! @brief Renders the point specified in the window coordinate system in 2D. @param[in] windowCoordinateX X-coordinate of center of point in the window coordinate system (f32 range) @param[in] windowCoordinateY Y-coordinate of center of point in the window coordinate system (f32 range) */ virtual void DrawPoint(const f32 windowCoordinateX, const f32 windowCoordinateY); public: /*! @brief Sets width of line when a line is rendered in 2D. @param[in] lineWidth Width of line in pixels ([1.0f,]) */ virtual void SetLineWidth(const f32 lineWidth); /*! @brief Renders the line segment specified in the window coordinate system in 2D. @param[in] windowCoordinateX0 X-coordinate of the start point of the line segment in the window coordinate system (f32 range) @param[in] windowCoordinateY0 Y-coordinate of the start point of the line segment in the window coordinate system (f32 range) @param[in] windowCoordinateX1 X-coordinate of the end point of the line segment in the window coordinate system (f32 range) @param[in] windowCoordinateY1 Y-coordinate of the end point of the line segment in the window coordinate system (f32 range) */ virtual void DrawLine(const f32 windowCoordinateX0, const f32 windowCoordinateY0, const f32 windowCoordinateX1, const f32 windowCoordinateY1); public: /*! @brief Renders the quadrangle specified in window coordinates in 2D. Provide vertex data in counterclockwise direction. @param[in] windowCoordinateX0 X-coordinate of the top-left vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateY0 Y-coordinate of the top-left vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateX1 X-coordinate of the bottom-left vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateY1 Y-coordinate of the bottom-left vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateX2 X-coordinate of the bottom-right vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateY2 Y-coordinate of the bottom-right vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateX3 X-coordinate of the top-right vertex of the quadrangle in the window coordinate system (f32 range) @param[in] windowCoordinateY3 Y-coordinate of the top-right vertex of the quadrangle in the window coordinate system (f32 range) */ virtual void FillSquare(const f32 windowCoordinateX0, const f32 windowCoordinateY0, const f32 windowCoordinateX1, const f32 windowCoordinateY1, const f32 windowCoordinateX2, const f32 windowCoordinateY2, const f32 windowCoordinateX3, const f32 windowCoordinateY3); public: /*! @brief Renders the rectangle specified in window coordinates in 2D. @param[in] windowCoordinateX X-coordinate of the top-left vertex of the rectangle in the window coordinate system (f32 range) @param[in] windowCoordinateY Y-coordinate of the top-left vertex of the rectangle in the window coordinate system (f32 range) @param[in] width Length of the side in the X-direction of the rectangle in the window coordinate system (f32 range) @param[in] height Length of the side in the Y-direction of the rectangle in the window coordinate system (f32 range) */ virtual void FillRectangle(const f32 windowCoordinateX, const f32 windowCoordinateY, const f32 width, const f32 height); public: /*! @brief Renders the triangle specified in window coordinates in 2D. Provide vertex data in counterclockwise direction. @param[in] windowCoordinateX0 X-coordinate of the first vertex of the triangle in the window coordinate system (f32 range) @param[in] windowCoordinateY0 Y-coordinate of the first vertex of the triangle in the window coordinate system (f32 range) @param[in] windowCoordinateX1 X-coordinate of the second vertex of the triangle in the window coordinate system (f32 range) @param[in] windowCoordinateY1 Y-coordinate of the second vertex of the triangle in the window coordinate system (f32 range) @param[in] windowCoordinateX2 X-coordinate of the third vertex of the triangle in the window coordinate system (f32 range) @param[in] windowCoordinateY2 Y-coordinate of the third vertex of the triangle in the window coordinate system (f32 range) */ virtual void FillTriangle(const f32 windowCoordinateX0, const f32 windowCoordinateY0, const f32 windowCoordinateX1, const f32 windowCoordinateY1, const f32 windowCoordinateX2, const f32 windowCoordinateY2); public: /*! @brief Sets the size when a font is rendered in 2D. However, since the original font data size is 8x8 pixels, a font size of 8 is recommended. @param[in] fontSize Font size in pixels ([1.0f,]) */ virtual void SetFontSize(const f32 fontSize); /*! @brief Renders text to the position specified in window coordinates. 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. @param[in] windowCoordinateX X-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) @param[in] windowCoordinateY Y-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) @param[in] format Format string */ virtual void DrawText(const f32 windowCoordinateX, const f32 windowCoordinateY, const char* format, ...); /*! @brief Renders text to the position specified in window coordinates. 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. @param[in] windowCoordinateX X-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) @param[in] windowCoordinateY Y-coordinate of the top-left of the rectangle in the window coordinate system where the text is rendered (f32 range) @param[in] text String */ virtual void DrawTextBuffer(const f32 windowCoordinateX, const f32 windowCoordinateY, const char* textBuffer); public: /*! @brief Displays result of rendering to the specified target. */ virtual void Flush(void); protected: virtual void FlushColorFillPrimitives(void); virtual void FlushTexts(void); public: f32 m_Color[4]; f32 m_Depth; bool m_AutoDepth; bool m_Padding0[3]; f32 m_DepthValue; f32 m_WindowWidth; f32 m_WindowHeight; public: demo::ShaderManager m_ShaderManager; protected: bool m_InitializeTriangles; bool m_InitializeSquares; bool m_InitializeTexts; bool m_Padding1; protected: u32 m_MaxTrianglesNum; u32 m_TotalTrianglesNum; protected: u32 m_MaxSquaresNum; u32 m_TotalSquaresNum; protected: u32 m_MaxTextLength; u32 m_TotalTextLength; protected: bool m_UseColorFillProgram; bool m_UseFontProgram; bool m_Padding2[2]; protected: f32 m_PointSize; f32 m_LineWidth; demo::TrianglesRenderData m_TrianglesRenderData; demo::TrianglesRenderData m_SquaresRenderData; f32 m_FontSize; demo::TextsRenderData m_TextsRenderData; }; } #endif