Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into releases/1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Dec 4, 2020
2 parents 340e0e9 + e2b9598 commit 8b7a04f
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 160 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| **`Release`** | **`Localized`** | **`License`** | **`Contribute`** |
|-------------------|---------------|---------------|---------------|
|[![GitHub release](https://img.shields.io/badge/Release-v1.6.1-blue.svg)](https://celestiaproject.net/download.html) | [![Localization](https://img.shields.io/badge/Localized-85%25-green.svg)](#) | [![License](https://img.shields.io/badge/License-GPLv2-blue.svg)](https://github.com/CelestiaProject/Celestia/blob/master/COPYING) | [![Contribute](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](#contributing) |
|[![GitHub release](https://img.shields.io/badge/Release-v1.6.2-blue)](https://celestia.space/download.html) | [![Localization](https://img.shields.io/badge/Localized-85%25-green.svg)](#) | [![License](https://img.shields.io/badge/License-GPLv2-blue.svg)](https://github.com/CelestiaProject/Celestia/blob/master/COPYING) | [![Contribute](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](#contributing) |

# Celestia
![Celestia](celestia-logo.png)<br>
Expand Down
60 changes: 60 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
trigger:
- main

strategy:
matrix:
Linux:
imageName: 'ubuntu-latest'
Mac:
imageName: 'macos-latest'

pool:
vmImage: $(imageName)

steps:
- checkout: self
submodules: true

- bash: echo "##vso[task.setvariable variable=shellopts]errexit"
displayName: "Force exit on error (bash)"

- script: |
sudo apt install -y libeigen3-dev \
libepoxy-dev \
libtheora-dev \
libjpeg-dev \
libpng-dev \
libglu1-mesa-dev \
qtbase5-dev \
qtbase5-dev-tools \
libqt5opengl5-dev \
libfreetype6-dev \
libsdl2-dev \
libluajit-5.1-dev
displayName: 'Install Linux dependencies'
condition: eq( variables['Agent.OS'], 'Linux' )

- script: |
brew install eigen \
cspice \
fmt \
jpeg \
gettext \
libpng \
lua \
qt5 \
freetype \
libepoxy \
sdl2
brew link gettext --force
displayName: 'Install macOS dependencies'
condition: eq( variables['Agent.OS'], 'Darwin' )

- script: |
mkdir build
cd build
cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TESTS=ON -DENABLE_SDL=ON ..
make -j $(nproc || echo 4)
CTEST_OUTPUT_ON_FAILURE=1 ctest
workingDirectory: "$(system.defaultworkingdirectory)"
displayName: "Build and test"
4 changes: 2 additions & 2 deletions shaders/largestar_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
attribute vec3 in_Position;
attribute vec2 in_Position;
attribute vec2 in_TexCoord0;

uniform float pointWidth;
Expand All @@ -11,6 +11,6 @@ void main(void)
{
texCoord = in_TexCoord0.st;
set_vp(vec4(center, 1.0));
vec2 transformed = vec2((in_TexCoord0.x - 0.5) * pointWidth, (in_TexCoord0.y - 0.5) * pointHeight);
vec2 transformed = vec2(in_Position.x * pointWidth, in_Position.y * pointHeight);
gl_Position.xy += transformed * gl_Position.w;
}
1 change: 1 addition & 0 deletions src/celengine/modelgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ ModelGeometry::render(RenderContext& rc, double /* t */)
for (unsigned int groupIndex = 0; groupIndex < mesh->getGroupCount(); ++groupIndex)
{
const Mesh::PrimitiveGroup* group = mesh->getGroup(groupIndex);
rc.updateShader(mesh->getVertexDescription(), group->prim);

// Set up the material
const Material* material = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/celengine/nebula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void Nebula::render(const Vector3f& /*offset*/,
getOrientation());

GLSLUnlit_RenderContext rc(renderer, getRadius());
rc.setPointScale(2.0f * getRadius() / pixelSize);
rc.setPointScale(2.0f * getRadius() / pixelSize * renderer->getScreenDpi() / 96.0f);
rc.setProjectionMatrix(m.projection);
rc.setModelViewMatrix(&mv);
g->render(rc);
Expand Down
4 changes: 2 additions & 2 deletions src/celengine/planetgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ PlanetographicGrid::render(Renderer* renderer,
{
glVertexAttrib(CelestiaGLProgram::ColorAttributeIndex,
Renderer::PlanetEquatorColor);
glLineWidth(2.0f);
glLineWidth(2.0f * renderer->getScreenDpi() / 96.0f);
}
else
{
Expand All @@ -166,7 +166,7 @@ PlanetographicGrid::render(Renderer* renderer,
prog->setMVPMatrices(projection, modelView * vecgl::translate(0.0f, sin(phi), 0.0f) * vecgl::scale(r));
glDrawArrays(GL_LINE_LOOP, 0, circleSubdivisions);

glLineWidth(1.0f);
glLineWidth(1.0f * renderer->getScreenDpi() / 96.0f);

if (showCoordinateLabels)
{
Expand Down
124 changes: 53 additions & 71 deletions src/celengine/pointstarvertexbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "texture.h"
#include "pointstarvertexbuffer.h"

PointStarVertexBuffer* PointStarVertexBuffer::current = nullptr;

PointStarVertexBuffer::PointStarVertexBuffer(const Renderer& _renderer,
unsigned int _capacity) :
Expand All @@ -32,93 +33,36 @@ PointStarVertexBuffer::~PointStarVertexBuffer()

void PointStarVertexBuffer::startSprites()
{
auto *prog = renderer.getShaderManager().getShader("star");
if (prog == nullptr)
return;
prog->use();
prog->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());
prog->samplerParam("starTex") = 0;

unsigned int stride = sizeof(StarVertex);
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
3, GL_FLOAT, GL_FALSE,
stride, &vertices[0].position);
glEnableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
glVertexAttribPointer(CelestiaGLProgram::ColorAttributeIndex,
4, GL_UNSIGNED_BYTE, GL_TRUE,
stride, &vertices[0].color);

glEnableVertexAttribArray(CelestiaGLProgram::PointSizeAttributeIndex);
glVertexAttribPointer(CelestiaGLProgram::PointSizeAttributeIndex,
1, GL_FLOAT, GL_FALSE,
stride, &vertices[0].size);

#ifndef GL_ES
glEnable(GL_POINT_SPRITE);
#endif

useSprites = true;
program = renderer.getShaderManager().getShader("star");
pointSizeFromVertex = true;
}

void PointStarVertexBuffer::startPoints()
void PointStarVertexBuffer::startBasicPoints()
{
ShaderProperties shadprop;
shadprop.texUsage = ShaderProperties::VertexColors;
shadprop.texUsage = ShaderProperties::VertexColors | ShaderProperties::StaticPointSize;
shadprop.lightModel = ShaderProperties::UnlitModel;
auto *prog = renderer.getShaderManager().getShader(shadprop);
if (prog == nullptr)
return;
prog->use();
prog->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());

unsigned int stride = sizeof(StarVertex);
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
3, GL_FLOAT, GL_FALSE,
stride, &vertices[0].position);
glEnableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
glVertexAttribPointer(CelestiaGLProgram::ColorAttributeIndex,
4, GL_UNSIGNED_BYTE, GL_TRUE,
stride, &vertices[0].color);

// An option to control the size of the stars would be helpful.
// Which size looks best depends a lot on the resolution and the
// type of display device.
// glPointSize(2.0f);
// glEnable(GL_POINT_SMOOTH);
useSprites = false;
program = renderer.getShaderManager().getShader(shadprop);
pointSizeFromVertex = false;
}

void PointStarVertexBuffer::render()
{
if (nStars != 0)
{
makeCurrent();
unsigned int stride = sizeof(StarVertex);
#ifndef GL_ES
if (useSprites)
{
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
}
else
{
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glPointSize(1.0f);
}
#endif
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
3, GL_FLOAT, GL_FALSE,
stride, &vertices[0].position);
glVertexAttribPointer(CelestiaGLProgram::ColorAttributeIndex,
4, GL_UNSIGNED_BYTE, GL_TRUE,
stride, &vertices[0].color);

if (useSprites)
{
if (pointSizeFromVertex)
glVertexAttribPointer(CelestiaGLProgram::PointSizeAttributeIndex,
1, GL_FLOAT, GL_FALSE,
stride, &vertices[0].size);
}

if (texture != nullptr)
texture->bind();
Expand All @@ -127,22 +71,60 @@ void PointStarVertexBuffer::render()
}
}

void PointStarVertexBuffer::makeCurrent()
{
if (current == this || program == nullptr)
return;

program->use();
program->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());
if (pointSizeFromVertex)
{
program->samplerParam("starTex") = 0;
glEnableVertexAttribArray(CelestiaGLProgram::PointSizeAttributeIndex);
}
else
{
program->pointScale = pointScale;
glVertexAttrib1f(CelestiaGLProgram::PointSizeAttributeIndex, 1.0f);
}

glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
glEnableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
current = this;
}

void PointStarVertexBuffer::finish()
{
render();
glDisableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
glDisableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);

if (useSprites)
{
if (pointSizeFromVertex)
glDisableVertexAttribArray(CelestiaGLProgram::PointSizeAttributeIndex);
}

void PointStarVertexBuffer::enable()
{
#ifndef GL_ES
glDisable(GL_POINT_SPRITE);
glEnable(GL_POINT_SPRITE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
#endif
}

void PointStarVertexBuffer::disable()
{
#ifndef GL_ES
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDisable(GL_POINT_SPRITE);
#endif
}
}

void PointStarVertexBuffer::setTexture(Texture* _texture)
{
texture = _texture;
texture = _texture;
}

void PointStarVertexBuffer::setPointScale(float pointSize)
{
pointScale = pointSize;
}
21 changes: 16 additions & 5 deletions src/celengine/pointstarvertexbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Color;
class Renderer;
class Texture;
class CelestiaGLProgram;

// PointStarVertexBuffer is used when hardware supports point sprites.
class PointStarVertexBuffer
Expand All @@ -30,12 +31,16 @@ class PointStarVertexBuffer
PointStarVertexBuffer& operator=(const PointStarVertexBuffer&) = delete;
PointStarVertexBuffer& operator=(PointStarVertexBuffer&&) = delete;

void startPoints();
void startBasicPoints();
void startSprites();
void render();
void finish();
inline void addStar(const Eigen::Vector3f& pos, const Color&, float);
void setTexture(Texture* /*_texture*/);
void setPointScale(float);

static void enable();
static void disable();

private:
struct StarVertex
Expand All @@ -49,10 +54,16 @@ class PointStarVertexBuffer
const Renderer& renderer;
capacity_t capacity;

capacity_t nStars { 0 };
StarVertex* vertices { nullptr };
Texture* texture { nullptr };
bool useSprites { false };
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();
};

inline void PointStarVertexBuffer::addStar(const Eigen::Vector3f& pos,
Expand Down
Loading

0 comments on commit 8b7a04f

Please sign in to comment.