/*---------------------------------------------------------------------------* Project: Horizon File: demo_Models.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_MODELS_H_ #define DEMO_MODELS_H_ #include #include #include namespace demo{ namespace detail { // The number of component elements in each vertex attribute for each vertex (all elements are defined as f32) const int ATTR_NUM_POS = 3; // x, y, z Data for 1 vertex contains three f32 elements const int ATTR_NUM_NORMAL = 3; // x, y, z const int ATTR_NUM_COLOR = 4; // r, g, b, alpha const int ATTR_NUM_TEX = 2; // s, t } // namespace detail /* * Vertex attributes specified by Initialize function are placed in the following order. * The vertex shader's input register settings must be matched. */ /*! @brief Enumerated type representing vertex attributes specified during the initialization of objects */ enum AttributeFlag { ATTR_POSITION = 0x01, ATTR_NORMAL = 0x02, ATTR_VERTEX_COLOR = 0x04, ATTR_TEX_COORDINATE = 0x08 }; /*! @class ModelBase demo_Models.h @brief Base class for simple 3D model objects used in samples. */ class ModelBase : private nn::util::NonCopyable { public: /*! @brief Destroys the object. */ virtual void Finalize() { FinalizeImpl(); } /*! @brief Constructor. */ ModelBase(); virtual ~ModelBase() { FinalizeImpl(); } /*! @brief Destructor. */ virtual void Draw(); private: void FinalizeImpl(); protected: bool m_Initialized; u8 m_AttributeFlag; // Vertex attributes applied to model data u8 m_Padding[2]; GLuint m_ArrayBufferObjectId; GLuint m_ElementArrayBufferObjectId; size_t m_DataSize[4]; size_t m_IndexSize; // Size of the vertex data (index) void InitializeCore(u16* indices, f32* attr1, f32* attr2, f32* attr3, f32* attr4); }; // class ModelBase /*! @class Cube demo_Models.h @brief Class for rendering cube objects for samples. You can specify the vertex attributes to use. */ class CubeModel : public ModelBase { public: /*! @brief Initializes Cube objects. Use the AttributeFlag enum to specify the vertex attributes the Cube object has. When the specified vertex attributes are rendered, they are passed to the vertex shader in the order defined in the AttributeFlag enum, not in the order they were specified. Always use this function once before using the class. @param[in] flag To assign vertex attributes to the Cube object, use a bitwise OR to specify members of the AttributeFlag enum @param[in] r Vertex color's R value (only valid when vertex color is specified as a vertex attribute) @param[in] g Vertex color's G value (only valid when vertex color is specified as a vertex attribute) @param[in] b Vertex color's B value (only valid when vertex color is specified as a vertex attribute) @param[in] alpha Vertex color's A value (only valid when vertex color is specified as a vertex attribute) */ void Initialize(u8 flag, f32 r = 1.0f, f32 g = 1.0f, f32 b = 1.0f, f32 alpha = 1.0f); /*! @brief Destroys the object. */ virtual void Finalize() { ModelBase::Finalize(); } /*! @brief Constructor. */ CubeModel() {} /*! @brief Destructor. */ virtual ~CubeModel() { } }; // class Cube } #endif