2019-12-01 05:32:10 -07:00
|
|
|
// pointstarvertexbuffer.h
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001-2019, the Celestia Development Team
|
|
|
|
// Original version by Chris Laurel <claurel@gmail.com>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Eigen/Core>
|
|
|
|
|
|
|
|
class Color;
|
|
|
|
class Renderer;
|
|
|
|
class Texture;
|
2020-11-29 03:23:31 -07:00
|
|
|
class CelestiaGLProgram;
|
2019-12-01 05:32:10 -07:00
|
|
|
|
|
|
|
// PointStarVertexBuffer is used when hardware supports point sprites.
|
|
|
|
class PointStarVertexBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using capacity_t = unsigned int;
|
|
|
|
|
|
|
|
PointStarVertexBuffer(const Renderer& _renderer, unsigned int _capacity);
|
|
|
|
~PointStarVertexBuffer();
|
|
|
|
PointStarVertexBuffer() = delete;
|
|
|
|
PointStarVertexBuffer(const PointStarVertexBuffer&) = delete;
|
|
|
|
PointStarVertexBuffer(PointStarVertexBuffer&&) = delete;
|
|
|
|
PointStarVertexBuffer& operator=(const PointStarVertexBuffer&) = delete;
|
|
|
|
PointStarVertexBuffer& operator=(PointStarVertexBuffer&&) = delete;
|
|
|
|
|
2020-11-29 03:23:31 -07:00
|
|
|
void startBasicPoints();
|
2019-12-01 05:32:10 -07:00
|
|
|
void startSprites();
|
|
|
|
void render();
|
|
|
|
void finish();
|
|
|
|
inline void addStar(const Eigen::Vector3f& pos, const Color&, float);
|
|
|
|
void setTexture(Texture* /*_texture*/);
|
2020-11-29 03:23:31 -07:00
|
|
|
void setPointScale(float);
|
|
|
|
|
|
|
|
static void enable();
|
|
|
|
static void disable();
|
2019-12-01 05:32:10 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct StarVertex
|
|
|
|
{
|
|
|
|
Eigen::Vector3f position;
|
|
|
|
float size;
|
|
|
|
unsigned char color[4];
|
|
|
|
float pad;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Renderer& renderer;
|
|
|
|
capacity_t capacity;
|
|
|
|
|
2020-11-29 03:23:31 -07:00
|
|
|
capacity_t nStars { 0 };
|
|
|
|
StarVertex* vertices { nullptr };
|
|
|
|
Texture* texture { nullptr };
|
|
|
|
bool pointSizeFromVertex { false };
|
|
|
|
float pointScale { 1.0f };
|
|
|
|
CelestiaGLProgram* program { nullptr };
|
|
|
|
|
|
|
|
static PointStarVertexBuffer* current;
|
|
|
|
|
|
|
|
void makeCurrent();
|
2019-12-01 05:32:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void PointStarVertexBuffer::addStar(const Eigen::Vector3f& pos,
|
|
|
|
const Color& color,
|
|
|
|
float size)
|
|
|
|
{
|
|
|
|
if (nStars < capacity)
|
|
|
|
{
|
|
|
|
vertices[nStars].position = pos;
|
|
|
|
vertices[nStars].size = size;
|
|
|
|
color.get(vertices[nStars].color);
|
|
|
|
nStars++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nStars == capacity)
|
|
|
|
{
|
|
|
|
render();
|
|
|
|
nStars = 0;
|
|
|
|
}
|
|
|
|
}
|