| 14 | |
| 15 | |
| 16 | StarField::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 | |
| 63 | StarField::~StarField() |
| 64 | { |
nothing calls this directly
no test coverage detected