1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: demo_ProgramObject.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_PROGRAM_OBJECT_H_ 17 #define DEMO_PROGRAM_OBJECT_H_ 18 19 #include <nn/gx.h> 20 #include <nn/math.h> 21 22 #include "demo/Utility/demo_Utility.h" 23 #include "demo/RenderData/demo_TrianglesRenderData.h" 24 25 namespace demo 26 { 27 28 /*! 29 :private 30 31 @brief Maximum number of shader that the ProgramObject class can maintain 32 */ 33 const u32 PROGRAM_OBJECT_MAX_SHADERS = 1; 34 35 /*! 36 :private 37 38 @brief Base class for the shader program. 39 */ 40 41 class ProgramObject : private nn::util::NonCopyable<ProgramObject> 42 { 43 public: 44 /*! 45 :private 46 47 @brief Constructor. 48 */ 49 ProgramObject(void); 50 51 /*! 52 :private 53 54 @brief Destructor. 55 */ 56 virtual ~ProgramObject(void); 57 58 public: 59 /*! 60 :private 61 62 @brief Performs initialization for the shader program object. 63 */ 64 virtual bool Initialize(const GLuint shaderId) = 0; 65 66 /*! 67 :private 68 69 @brief Performs termination for the shader program object. 70 */ 71 virtual bool Finalize(void) = 0; 72 73 public: 74 /*! 75 :private 76 77 @brief Sets the rendering state before the shader program object is used. 78 */ 79 virtual bool Begin(void); 80 81 /*! 82 :private 83 84 @brief Uses shader program object. 85 */ 86 virtual bool Use(void) = 0; 87 88 /*! 89 :private 90 91 @brief Sets the rendering state after the shader program object is used. 92 */ 93 virtual bool End(void); 94 95 public: 96 /*! 97 :private 98 99 @brief Gets vertex attributes set in the shader program object. 100 101 @return Vertex attributes 102 */ 103 virtual u32 GetVertexAttributes(void); 104 105 /*! 106 :private 107 108 @brief Sets whether to convert the 3-dimensional vertex position coordinates to clip coordinates using the projection matrix and model view matrix. 109 110 @param[in] use3d Whether to convert to the clip coordinate system (true or false) 111 */ 112 virtual void SetUse3d(const bool use3d); 113 114 /*! 115 :private 116 117 @brief Sets the projection matrix for the shader program object. 118 119 @param[in] projectionMatrix Projection matrix 120 */ 121 virtual void SetProjectionMatrix(const nn::math::MTX44& projectionMatrix); 122 123 /*! 124 :private 125 126 @brief Sets the model view matrix for the shader program object. 127 128 @param[in] modelViewMatrix Model view matrix 129 */ 130 virtual void SetModelViewMatrix(const nn::math::MTX44& modelViewMatrix); 131 132 /*! 133 :private 134 135 @brief Sets a texture object handle. 136 137 @param[in] textureId Texture object handle 138 */ 139 virtual void SetTextureId(const GLuint textureId); 140 141 /*! 142 :private 143 144 @brief Updates the internal state of the shader program object. 145 */ 146 virtual void Update(void); 147 148 protected: 149 virtual void InitializeVertexAttributes(void); 150 virtual void InitializeUniforms(void); 151 virtual void UpdateModelViewProjectionMatrix(void); 152 153 protected: 154 bool m_Initialized; 155 bool m_Padding0[3]; 156 157 u32 m_VertexAttributes; 158 bool m_Use3d; 159 u8 m_Padding[3]; 160 161 GLuint m_ProgramId; 162 GLuint m_ShaderIds[PROGRAM_OBJECT_MAX_SHADERS]; 163 GLint m_UniformLocation[MAX_UNIFORM_LOCATIONS_NUM]; 164 165 nn::math::MTX44 m_ProjectionMatrix; 166 nn::math::MTX44 m_ModelViewMatrix; 167 }; 168 169 } 170 171 #endif 172