summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/VertexAttribute.h
blob: 4e50a1aef4af27bcedf4d0399c6d0d8176585ca6 (plain)
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
#pragma once

#include <vector>

#include "../Utilities/UtilMacros.h"
#include "../Shaders/ShaderChannel.h"

#include "OpenGL.h"
#include "GPUDataBuffer.h"

// component format
enum VertexAttrFormat
{
	VertexAttrFormat_Float = 0,   // position\normal\tangent\uv\uv2\uv3\uv4
	VertexAttrFormat_Float16 = 1,
	VertexAttrFormat_Color = 2,   // color
	VertexAttrFormat_Byte = 3,

	VertexAttrFormat_Count = 4
};

struct VertexAttributeDescriptor
{
	// for default vertex layout
	VertexAttributeDescriptor() {}
	// for custom vertex layout
	VertexAttributeDescriptor(int startOff, uint num, uint fmt, uint16 strd, bool normalized = false)
	{
		startOffset = startOff;
		componentNum = num;
		componentFormat = fmt;
		stride = strd;
		normalize = normalized;
	}

	union {
		const void* pointer;  // 内存地址或显存中相对VBO的偏移值
		int startOffset;
	};
	uint componentNum;    // 向量维度1,2,3,4
	uint componentFormat; // 每个分量的类型
	uint16 stride;        // 间隔
	bool normalize;       // 是否归一化,只用于CustomVertexLayout
};

namespace VertexAttribute
{

	extern GLenum ConvertAttrFormatToGLFormat(uint fmt);

}