1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     demo_FrameBuffer.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_FRAME_BUFFER_H_
17 #define DEMO_FRAME_BUFFER_H_
18 
19 #include "demo/Utility/demo_Utility.h"
20 
21 namespace demo
22 {
23 
24     const u32 DEMO_RENDER_BUFFER_NUM = 2;
25     static const u32 DEMO_COLOR_BUFFER_INDEX = 0;
26     static const u32 DEMO_DEPTH_STENCIL_BUFFER_INDEX = 1;
27 
28     /*!
29         @brief Class to maintain data from the render buffer to create
30     */
31 
32     class RenderBufferDescription
33     {
34     public:
35         RenderBufferDescription(void);
36         virtual ~RenderBufferDescription(void);
37 
38     public:
39         GLenum m_Format;
40         u32 m_Width;
41         u32 m_Height;
42         GLenum m_Area;
43         GLenum m_Attachment;
44 
45     public:
46         static RenderBufferDescription GetDefaultDisplay0ColorDescription(void);
47         static RenderBufferDescription GetDefaultDisplay0DepthStencilDescription(void);
48         static RenderBufferDescription GetDefaultDisplay1ColorDescription(void);
49         static RenderBufferDescription GetDefaultDisplay1DepthStencilDescription(void);
50     };
51 
52 
53 
54     /*!
55         @brief Class to maintain data from the frame buffer to create
56     */
57 
58     class FrameBufferDescription
59     {
60     public:
61         FrameBufferDescription(void);
62         virtual ~FrameBufferDescription(void);
63         FrameBufferDescription(const FrameBufferDescription& rhs);
64         FrameBufferDescription& operator=(const FrameBufferDescription& rhs);
65 
66     public:
67         void Initialize(void);
68         void Finalize(void);
69 
70     public:
71         RenderBufferDescription m_RenderBufferDescriptionArray[DEMO_RENDER_BUFFER_NUM];
72 
73     public:
74         static FrameBufferDescription GetDefaultDisplay0FrameBufferDescription(void);
75         static FrameBufferDescription GetDefaultDisplay1FrameBufferDescription(void);
76     };
77 
78     /*!
79         @brief Frame buffer class
80     */
81 
82     class FrameBuffer : private nn::util::NonCopyable<FrameBuffer>
83     {
84     public:
85         FrameBuffer(void);
86         virtual ~FrameBuffer(void);
87 
88     protected:
89         void Initialize(const FrameBufferDescription& frameBufferDesc);
90         void Finalize(void);
91 
92     public:
93         static void Create(const FrameBufferDescription& frameBufferDesc,
94             FrameBuffer& frameBuffer);
95         static void Destroy(FrameBuffer& frameBuffer);
96 
97     public:
98         void Bind(void);
99         void SetViewport(void);
100         void SetViewport(const GLint x, const GLint y, const GLsizei width, const GLsizei height);
101         GLsizei GetWidth(void);
102         GLsizei GetHeight(void);
103     public:
104         void ClearBuffer(const GLbitfield mask = (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) );
105         void ClearColorDepthStencilBuffer(const GLclampf red, const GLclampf green,
106             const GLclampf blue, const GLclampf alpha,
107             const GLclampf depth = 1.0f, const GLclampf stencil = 0.0f);
108         void ClearDepthStencilBuffer(const GLclampf depth = 1.0f, const GLclampf stencil = 0.0f);
109         void ClearColorDepthBuffer(const GLclampf red, const GLclampf green,
110             const GLclampf blue, const GLclampf alpha,
111             const GLclampf depth = 1.0f);
112         void ClearColorBuffer(const GLclampf red, const GLclampf green,
113             const GLclampf blue, const GLclampf alpha);
114         void ClearDepthBuffer(const GLclampf depth = 1.0f);
115         void ClearStencilBuffer(const GLclampf stencil = 0.0f);
116 
117     public:
118         void Transfer(const GLuint displayBufferId, const GLenum mode,
119             const GLboolean yflip, const GLint colorX, const GLint colorY);
120 
121     public:
122         GLuint GetFrameBufferId(void);
123         GLuint GetRenderBufferId(const u32 bufferIndex);
124 
125     protected:
126         bool m_InitializeFlag;
127         bool m_Padding[3];
128 
129         GLuint m_FrameBufferId;
130         u32 m_RenderBufferNum;
131         GLuint m_RenderBufferIdArray[DEMO_RENDER_BUFFER_NUM];
132         u32 m_Width;
133         u32 m_Height;
134     };
135 
136 }
137 
138 #endif
139