Blame view

ios/cocos2d/cocos/renderer/backend/VertexLayout.h 3.95 KB
520389e3   xiaoyu   接入cocos源码,编译未通过,继续修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  /****************************************************************************
   Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
  
   http://www.cocos2d-x.org
  
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
  
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
  
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
   ****************************************************************************/
   
  #pragma once
  
  #include "Macros.h"
  #include "Types.h"
  #include "base/CCRef.h"
  
  #include <string>
  #include <cstdint>
  #include <vector>
  #include <unordered_map>
  
  CC_BACKEND_BEGIN
  /**
   * @addtogroup _backend
   * @{
   */
  
  /**
   * Store vertex attribute layout.
   */
  class VertexLayout
  {
  public:
      struct Attribute
      {
          Attribute() = default;
          Attribute(const std::string& _name, std::size_t _index, VertexFormat _format, std::size_t _offset, bool needToBeNormallized)
          : name(_name)
          , format(_format)
          , offset(_offset)
          , index(_index)
          , needToBeNormallized(needToBeNormallized)
          {}
          
          std::string name; ///< name is used in opengl
          VertexFormat format = VertexFormat::INT3; 
          std::size_t offset = 0;
          std::size_t index = 0; ///< index is used in metal
          bool needToBeNormallized = false;
      };
  
      VertexLayout() = default;
      
      /**
       * Set attribute values to name.
       * @param name Specifies the attribute name.
       * @param index Specifies the index of the generic vertex attribute to be modified.
       * @param format Specifies how the vertex attribute data is laid out in memory.
       * @param offset Specifies the byte offset to the first component of the first generic vertex attribute.
       * @param needToBeNormallized Specifies whether fixed-point data values should be normalized (true) or converted directly as fixed-point values (false) when they are accessed.
       */
      void setAttribute(const std::string& name, std::size_t index, VertexFormat format, std::size_t offset, bool needToBeNormallized);
      
      /**
       * Set stride of vertices.
       * @param stride Specifies the distance between the data of two vertices, in bytes.
       */
      void setLayout(std::size_t stride);
      
      /**
       * Get the distance between the data of two vertices, in bytes.
       * @return The distance between the data of two vertices, in bytes.
       */
      inline std::size_t getStride() const { return _stride; }
  
      /**
       * Get vertex step function. Default value is VERTEX.
       * @return Vertex step function.
       * @note Used in metal.
       */
      inline VertexStepMode getVertexStepMode() const { return _stepMode; }
  
      /**
       * Get attribute informations
       * @return Atrribute informations.
       */
      inline const std::unordered_map<std::string, Attribute>& getAttributes() const { return _attributes; }
  
      /**
       * Check if vertex layout has been set.
       */
      inline bool isValid() const { return _stride != 0; }
      
  private:
      std::unordered_map<std::string, Attribute> _attributes;
      std::size_t _stride = 0;
      VertexStepMode _stepMode = VertexStepMode::VERTEX;
  };
  
  //end of _backend group
  /// @}
  CC_BACKEND_END