MCPcopy Create free account
hub / github.com/Illation/ETEngine / StarField

Method StarField

Engine/source/EtRendering/PlanetTech/StarField.cpp:16–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15
16StarField::StarField(core::HashString const assetId)
17{
18 AssetPtr<core::StubData> jsonDbText = core::ResourceManager::Instance()->GetAssetData<core::StubData>(assetId);
19
20 core::JSON::Parser parser = core::JSON::Parser(std::string(jsonDbText->GetText(), jsonDbText->GetLength()));
21 core::JSON::Object* root = parser.GetRoot();
22
23 uint32 starCount = 0;
24
25 core::JSON::Array* jstarArray = (*root)["stars"]->arr();
26 for (auto jStar : jstarArray->value)
27 {
28 vec4 star;
29 if (core::JSON::ArrayVector(jStar, star) && m_MaxStars == 0 ? true : starCount < m_MaxStars)
30 {
31 //HYG coordinates are in a different coordinate system Z up Y forward
32 //first component is magnitude
33 //output [X, Z, Y, mag]
34 m_Stars.push_back(vec4(star[1], star[3], star[2], star[0]));
35 starCount++;
36 }
37 }
38
39 I_GraphicsApiContext* const api = Viewport::GetCurrentApiContext();
40
41 m_pShader = core::ResourceManager::Instance()->GetAssetData<ShaderData>(core::HashString("FwdStarField.glsl"));
42 m_pSprite = core::ResourceManager::Instance()->GetAssetData<TextureData>(core::HashString("starSprite.png"));
43
44 //Generate buffers and arrays
45 m_VAO = api->CreateVertexArray();
46 m_VBO = api->CreateBuffer();
47
48 //bind
49 api->BindVertexArray(m_VAO);
50 api->BindBuffer(E_BufferType::Vertex, m_VBO);
51
52 //set data and attributes
53 api->SetBufferData(E_BufferType::Vertex, m_Stars.size() * sizeof(vec4), m_Stars.data(), E_UsageHint::Dynamic);
54
55 api->SetVertexAttributeArrayEnabled(0, true);
56 api->DefineVertexAttributePointer(0, 4, E_DataType::Float, false, sizeof(vec4), 0);
57
58 //unbind
59 api->BindBuffer(E_BufferType::Vertex, 0);
60 api->BindVertexArray(0);
61}
62
63StarField::~StarField()
64{

Callers

nothing calls this directly

Calls 14

ParserClass · 0.85
ArrayVectorFunction · 0.85
HashStringClass · 0.85
GetTextMethod · 0.80
GetLengthMethod · 0.80
arrMethod · 0.80
CreateVertexArrayMethod · 0.80
CreateBufferMethod · 0.80
BindVertexArrayMethod · 0.80
BindBufferMethod · 0.80
SetBufferDataMethod · 0.80

Tested by

no test coverage detected