Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Oct 10, 2020
2 parents 0786213 + 17cd02b commit 5d1401c
Show file tree
Hide file tree
Showing 44 changed files with 788 additions and 133 deletions.
8 changes: 8 additions & 0 deletions shaders/passthrough_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
varying vec2 texCoord;

uniform sampler2D tex;

void main(void)
{
gl_FragColor = texture2D(tex, texCoord);
}
10 changes: 10 additions & 0 deletions shaders/passthrough_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
attribute vec2 in_Position;
attribute vec2 in_TexCoord0;

varying vec2 texCoord;

void main(void)
{
gl_Position = vec4(in_Position.xy, 0.0, 1.0);
texCoord = in_TexCoord0.st;
}
9 changes: 9 additions & 0 deletions shaders/warpmesh_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
varying vec2 texCoord;
varying float intensity;

uniform sampler2D tex;

void main(void)
{
gl_FragColor = vec4(texture2D(tex, texCoord).rgb * intensity, 1.0);
}
16 changes: 16 additions & 0 deletions shaders/warpmesh_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
attribute vec2 in_Position;
attribute vec2 in_TexCoord0;
attribute float in_Intensity;

varying vec2 texCoord;
varying float intensity;

uniform float screenRatio;

void main(void)
{
float offset = 0.5 - screenRatio * 0.5;
gl_Position = vec4(in_Position.x * screenRatio, in_Position.y, 0.0, 1.0);
texCoord = vec2(in_TexCoord0.x * screenRatio + offset, in_TexCoord0.y);
intensity = in_Intensity;
}
4 changes: 4 additions & 0 deletions src/celengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ set(CELENGINE_SOURCES
location.h
lodspheremesh.cpp
lodspheremesh.h
mapmanager.cpp
mapmanager.h
marker.cpp
marker.h
meshmanager.cpp
Expand Down Expand Up @@ -168,6 +170,8 @@ set(CELENGINE_SOURCES
vecgl.h
vertexobject.cpp
vertexobject.h
viewporteffect.h
viewporteffect.cpp
virtualtex.cpp
virtualtex.h
visibleregion.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/celengine/asterismrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool AsterismRenderer::sameAsterisms(const AsterismList *asterisms) const

/*! Draw visible asterisms.
*/
void AsterismRenderer::render(const Renderer &renderer, const Color &defaultColor, const Eigen::Matrix4f &mvp)
void AsterismRenderer::render(const Renderer &renderer, const Color &defaultColor, const Matrices &mvp)
{
auto *prog = renderer.getShaderManager().getShader(m_shadprop);
if (prog == nullptr)
Expand All @@ -50,7 +50,7 @@ void AsterismRenderer::render(const Renderer &renderer, const Color &defaultColo
}

prog->use();
prog->MVPMatrix = mvp;
prog->setMVPMatrices(*mvp.projection, *mvp.modelview);
glVertexAttrib(CelestiaGLProgram::ColorAttributeIndex, defaultColor);
m_vo.draw(GL_LINES, m_vtxTotal);

Expand Down
3 changes: 2 additions & 1 deletion src/celengine/asterismrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "vertexobject.h"

class Renderer;
struct Matrices;

class AsterismRenderer
{
Expand All @@ -28,7 +29,7 @@ class AsterismRenderer
AsterismRenderer& operator=(const AsterismRenderer&) = delete;
AsterismRenderer& operator=(AsterismRenderer&&) = delete;

void render(const Renderer &renderer, const Color &color, const Eigen::Matrix4f &mvp);
void render(const Renderer &renderer, const Color &color, const Matrices &mvp);
bool sameAsterisms(const AsterismList *asterisms) const;

private:
Expand Down
25 changes: 13 additions & 12 deletions src/celengine/axisarrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ ArrowReferenceMark::render(Renderer* renderer,
if (prog == nullptr)
return;
prog->use();
prog->MVPMatrix = (*m.projection) * mv;
prog->setMVPMatrices(*m.projection, mv);

glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex,
color.red(), color.green(), color.blue(), opacity);
Expand Down Expand Up @@ -358,7 +358,8 @@ AxesReferenceMark::render(Renderer* renderer,
}

Affine3f transform = Translation3f(position) * q.cast<float>() * Scaling(size);
Matrix4f mvp = (*m.projection) * (*m.modelview) * transform.matrix();
Matrix4f projection = *m.projection;
Matrix4f modelView = (*m.modelview) * transform.matrix();

#if 0
// Simple line axes
Expand Down Expand Up @@ -390,30 +391,30 @@ AxesReferenceMark::render(Renderer* renderer,

Affine3f labelTransform = Translation3f(Vector3f(0.1f, 0.0f, 0.75f)) * Scaling(labelScale);
Matrix4f labelTransformMatrix = labelTransform.matrix();
Matrix4f t;
Matrix4f tModelView;

// x-axis
t = mvp * vecgl::rotate(AngleAxisf(90.0_deg, Vector3f::UnitY()));
tModelView = modelView * vecgl::rotate(AngleAxisf(90.0_deg, Vector3f::UnitY()));
glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex, 1.0f, 0.0f, 0.0f, opacity);
prog->MVPMatrix = t;
prog->setMVPMatrices(projection, tModelView);
RenderArrow(vo);
prog->MVPMatrix = t * labelTransformMatrix;
prog->setMVPMatrices(projection, tModelView * labelTransformMatrix);
RenderX(vo);

// y-axis
t = mvp * vecgl::rotate(AngleAxisf(180.0_deg, Vector3f::UnitY()));
tModelView = modelView * vecgl::rotate(AngleAxisf(180.0_deg, Vector3f::UnitY()));
glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex, 0.0f, 1.0f, 0.0f, opacity);
prog->MVPMatrix = t;
prog->setMVPMatrices(projection, tModelView);
RenderArrow(vo);
prog->MVPMatrix = t * labelTransformMatrix;
prog->setMVPMatrices(projection, tModelView * labelTransformMatrix);
RenderY(vo);

// z-axis
t = mvp *vecgl::rotate(AngleAxisf(-90.0_deg, Vector3f::UnitX()));
tModelView = modelView *vecgl::rotate(AngleAxisf(-90.0_deg, Vector3f::UnitX()));
glVertexAttrib4f(CelestiaGLProgram::ColorAttributeIndex, 0.0f, 0.0f, 1.0f, opacity);
prog->MVPMatrix = t;
prog->setMVPMatrices(projection, tModelView);
RenderArrow(vo);
prog->MVPMatrix = t * labelTransformMatrix;
prog->setMVPMatrices(projection, tModelView * labelTransformMatrix);
RenderZ(vo);

renderer->enableBlending();
Expand Down
4 changes: 2 additions & 2 deletions src/celengine/boundariesrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool BoundariesRenderer::sameBoundaries(const ConstellationBoundaries *boundarie
return m_boundaries == boundaries;
}

void BoundariesRenderer::render(const Renderer &renderer, const Color &color, const Eigen::Matrix4f &mvp)
void BoundariesRenderer::render(const Renderer &renderer, const Color &color, const Matrices &mvp)
{
auto *prog = renderer.getShaderManager().getShader(m_shadprop);
if (prog == nullptr)
Expand All @@ -51,7 +51,7 @@ void BoundariesRenderer::render(const Renderer &renderer, const Color &color, co
}

prog->use();
prog->MVPMatrix = mvp;
prog->setMVPMatrices(*mvp.projection, *mvp.modelview);
glVertexAttrib(CelestiaGLProgram::ColorAttributeIndex, color);
m_vo.draw(GL_LINES, m_vtxTotal);

Expand Down
3 changes: 2 additions & 1 deletion src/celengine/boundariesrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Color;
class ConstellationBoundaries;
class Renderer;
struct Matrices;

class BoundariesRenderer
{
Expand All @@ -27,7 +28,7 @@ class BoundariesRenderer
BoundariesRenderer& operator=(const BoundariesRenderer&) = delete;
BoundariesRenderer& operator=(BoundariesRenderer&&) = delete;

void render(const Renderer &renderer, const Color &color, const Eigen::Matrix4f &mvp);
void render(const Renderer &renderer, const Color &color, const Matrices &mvp);
bool sameBoundaries(const ConstellationBoundaries*) const;

private:
Expand Down
4 changes: 2 additions & 2 deletions src/celengine/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool Console::setRowCount(int _nRows)

void Console::begin()
{
mpv = Ortho2D(0.0f, (float)xscale, 0.0f, (float)yscale);
projection = Ortho2D(0.0f, (float)xscale, 0.0f, (float)yscale);

renderer.enableBlending();
renderer.setBlendingFactors(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Expand All @@ -98,7 +98,7 @@ void Console::render(int rowHeight)
return;

font->bind();
font->setMVPMatrix(mpv);
font->setMVPMatrices(projection);
savePos();
for (int i = 0; i < rowHeight; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/celengine/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Console : public std::ostream
};
CursorPosition global { 0.0f, 0.0f };
std::vector<CursorPosition> posStack;
Eigen::Matrix4f mpv;
Eigen::Matrix4f projection;
};

#endif // _CELENGINE_CONSOLE_H_
13 changes: 7 additions & 6 deletions src/celengine/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ FramebufferObject::generateFbo(unsigned int attachments)
{
// Create the FBO
glGenFramebuffers(1, &m_fboId);
GLint oldFboId;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFboId);
glBindFramebuffer(GL_FRAMEBUFFER, m_fboId);

#ifndef GL_ES
Expand All @@ -151,7 +153,7 @@ FramebufferObject::generateFbo(unsigned int attachments)
m_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (m_status != GL_FRAMEBUFFER_COMPLETE)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, oldFboId);
cleanup();
return;
}
Expand All @@ -171,7 +173,7 @@ FramebufferObject::generateFbo(unsigned int attachments)
m_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (m_status != GL_FRAMEBUFFER_COMPLETE)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, oldFboId);
cleanup();
return;
}
Expand All @@ -182,7 +184,7 @@ FramebufferObject::generateFbo(unsigned int attachments)
}

// Restore default frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, oldFboId);
}

// Delete all GL objects associated with this framebuffer object
Expand Down Expand Up @@ -218,9 +220,8 @@ FramebufferObject::bind()
}

bool
FramebufferObject::unbind()
FramebufferObject::unbind(GLint oldfboId)
{
// Restore default frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, oldfboId);
return true;
}
2 changes: 1 addition & 1 deletion src/celengine/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FramebufferObject
GLuint depthTexture() const;

bool bind();
bool unbind();
bool unbind(GLint oldfboId);

private:
void generateColorTexture();
Expand Down
2 changes: 1 addition & 1 deletion src/celengine/galaxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void Galaxy::renderGalaxyPointSprites(const Vector3f& offset,
GLushort j = 0;

prog->use();
prog->mat4Param("MVPMatrix") = (*ms.projection) * mv;
prog->setMVPMatrices(*ms.projection, mv);
prog->samplerParam("galaxyTex") = 0;
prog->samplerParam("colorTex") = 1;

Expand Down
8 changes: 4 additions & 4 deletions src/celengine/glmarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void Renderer::renderMarker(MarkerRepresentation::Symbol symbol,

prog->use();
float s = size / 2.0f;
prog->MVPMatrix = (*m.projection) * (*m.modelview) * vecgl::scale(Vector3f(s, s, 0));
prog->setMVPMatrices(*m.projection, (*m.modelview) * vecgl::scale(Vector3f(s, s, 0)));

switch (symbol)
{
Expand Down Expand Up @@ -362,7 +362,7 @@ void Renderer::renderSelectionPointer(const Observer& observer,

prog->use();
const Vector3f &center = cameraMatrix.col(2);
prog->mat4Param("MVPMatrix") = getProjectionMatrix() * getModelViewMatrix() * vecgl::translate(Vector3f(-center));
prog->setMVPMatrices(getProjectionMatrix(), getModelViewMatrix() * vecgl::translate(Vector3f(-center)));
prog->vec4Param("color") = Color(SelectionCursorColor, 0.6f).toVector4();
prog->floatParam("pixelSize") = pixelSize;
prog->floatParam("s") = s;
Expand Down Expand Up @@ -400,7 +400,7 @@ void Renderer::renderEclipticLine()
initVO(markerVO);

prog->use();
prog->mat4Param("MVPMatrix") = getProjectionMatrix() * getModelViewMatrix();
prog->setMVPMatrices(getProjectionMatrix(), getModelViewMatrix());
prog->vec4Param("color") = EclipticColor.toVector4();
markerVO.draw(GL_LINE_LOOP, EclipticCount, EclipticOffset);

Expand Down Expand Up @@ -435,7 +435,7 @@ void Renderer::renderCrosshair(float selectionSizeInPixels,
float cursorGrow = max(1.0f, min(2.5f, (selectionSizeInPixels - 10.0f) / 100.0f));

prog->use();
prog->mat4Param("MVPMatrix") = (*m.projection) * (*m.modelview);
prog->setMVPMatrices(*m.projection, *m.modelview);
prog->vec4Param("color") = color.toVector4();
prog->floatParam("radius") = cursorRadius;
prog->floatParam("width") = minCursorWidth * cursorGrow;
Expand Down
8 changes: 4 additions & 4 deletions src/celengine/globular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ void Globular::renderGlobularPointSprites(
tidalProg->use();
centerTex[ic]->bind();

Matrix4f mvp = (*m.projection) * (*m.modelview);
tidalProg->mat4Param("MVPMatrix") = mvp;
tidalProg->setMVPMatrices(*m.projection, *m.modelview);

Matrix3f viewMat = viewerOrientation.conjugate().toRotationMatrix();
tidalProg->vec4Param("color") = Vector4f(Rr, Gg, Bb, min(2 * brightness * pixelWeight, 1.0f));
Expand All @@ -492,8 +491,9 @@ void Globular::renderGlobularPointSprites(
globProg->use();

globularTex->bind();
globProg->mat4Param("MVPMatrix") = mvp;
globProg->mat4Param("ModelViewMatrix") = vecgl::translate(*m.modelview, offset);
globProg->setMVPMatrices(*m.projection, *m.modelview);
// TODO: model view matrix should not be reset here
globProg->ModelViewMatrix = vecgl::translate(*m.modelview, offset);
Matrix3f mx = Scaling(form->scale) * getOrientation().toRotationMatrix() * Scaling(tidalSize);
globProg->mat3Param("m") = mx;
globProg->vec3Param("offset") = offset;
Expand Down
Loading

0 comments on commit 5d1401c

Please sign in to comment.