Adds line drawing to DebugRenderer.
This was SVN commit r25271.
This commit is contained in:
parent
57e85c195e
commit
4a51012442
@ -1,7 +1,13 @@
|
||||
!!ARBfp1.0
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
ATTRIB v_tex = fragment.texcoord[0];
|
||||
|
||||
TEX result.color, v_tex, texture[0], 2D;
|
||||
#else
|
||||
PARAM color = program.local[0];
|
||||
|
||||
MOV result.color, color;
|
||||
#endif
|
||||
|
||||
END
|
||||
|
@ -1,19 +1,25 @@
|
||||
!!ARBvp1.0
|
||||
|
||||
PARAM transform[4] = { program.local[0..3] };
|
||||
#if DEBUG_TEXTURED
|
||||
PARAM textureTransform[4] = { program.local[4..7] };
|
||||
#endif
|
||||
|
||||
ATTRIB position = vertex.position;
|
||||
#if DEBUG_TEXTURED
|
||||
ATTRIB uv = vertex.texcoord[0];
|
||||
#endif
|
||||
|
||||
DP4 result.position.x, transform[0], position;
|
||||
DP4 result.position.y, transform[1], position;
|
||||
DP4 result.position.z, transform[2], position;
|
||||
DP4 result.position.w, transform[3], position;
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
OUTPUT v_tex = result.texcoord[0];
|
||||
|
||||
DP4 v_tex.x, textureTransform[0], uv;
|
||||
DP4 v_tex.y, textureTransform[1], uv;
|
||||
#endif
|
||||
|
||||
END
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
<vertex file="arb/debug_overlay.vp">
|
||||
<uniform name="transform" loc="0" type="mat4"/>
|
||||
<uniform name="textureTransform" loc="4" type="mat4"/>
|
||||
<uniform name="textureTransform" loc="4" type="mat4" if="DEBUG_TEXTURED"/>
|
||||
<stream name="pos"/>
|
||||
<stream name="uv0"/>
|
||||
<stream name="uv0" if="DEBUG_TEXTURED"/>
|
||||
</vertex>
|
||||
|
||||
<fragment file="arb/debug_overlay.fp">
|
||||
<uniform name="baseTex" loc="0" type="sampler2D"/>
|
||||
<uniform name="baseTex" loc="0" type="sampler2D" if="DEBUG_TEXTURED"/>
|
||||
<uniform name="color" loc="0" type="vec4" if="!DEBUG_TEXTURED"/>
|
||||
</fragment>
|
||||
|
||||
</program>
|
||||
|
14
binaries/data/mods/public/shaders/effects/debug_line.xml
Normal file
14
binaries/data/mods/public/shaders/effects/debug_line.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<effect>
|
||||
|
||||
<technique>
|
||||
<require shaders="arb"/>
|
||||
<pass shader="arb/debug_overlay"/>
|
||||
</technique>
|
||||
|
||||
<technique>
|
||||
<require shaders="glsl"/>
|
||||
<pass shader="glsl/debug_overlay"/>
|
||||
</technique>
|
||||
|
||||
</effect>
|
@ -2,11 +2,13 @@
|
||||
<effect>
|
||||
|
||||
<technique>
|
||||
<define name="DEBUG_TEXTURED" value="1"/>
|
||||
<require shaders="arb"/>
|
||||
<pass shader="arb/debug_overlay"/>
|
||||
</technique>
|
||||
|
||||
<technique>
|
||||
<define name="DEBUG_TEXTURED" value="1"/>
|
||||
<require shaders="glsl"/>
|
||||
<pass shader="glsl/debug_overlay"/>
|
||||
</technique>
|
||||
|
@ -1,11 +1,18 @@
|
||||
#version 110
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
uniform sampler2D baseTex;
|
||||
|
||||
varying vec2 v_tex;
|
||||
#else
|
||||
uniform vec4 color;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 base = texture2D(baseTex, v_tex);
|
||||
gl_FragColor = base;
|
||||
#if DEBUG_TEXTURED
|
||||
gl_FragColor = texture2D(baseTex, v_tex);
|
||||
#else
|
||||
gl_FragColor = color;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,15 +1,22 @@
|
||||
#version 110
|
||||
|
||||
uniform mat4 transform;
|
||||
#if DEBUG_TEXTURED
|
||||
uniform mat4 textureTransform;
|
||||
#endif
|
||||
|
||||
attribute vec3 a_vertex;
|
||||
|
||||
#if DEBUG_TEXTURED
|
||||
attribute vec3 a_uv0;
|
||||
|
||||
varying vec2 v_tex;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if DEBUG_TEXTURED
|
||||
v_tex = (textureTransform * vec4(a_uv0, 1.0)).xy;
|
||||
#endif
|
||||
gl_Position = transform * vec4(a_vertex, 1.0);
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
<vertex file="glsl/debug_overlay.vs">
|
||||
<stream name="pos"/>
|
||||
<stream name="uv0"/>
|
||||
<stream name="uv0" if="DEBUG_TEXTURED"/>
|
||||
<attrib name="a_vertex" semantics="gl_Vertex"/>
|
||||
<attrib name="a_uv0" semantics="gl_MultiTexCoord0"/>
|
||||
<attrib name="a_uv0" semantics="gl_MultiTexCoord0" if="DEBUG_TEXTURED"/>
|
||||
</vertex>
|
||||
|
||||
<fragment file="glsl/debug_overlay.fs"/>
|
||||
|
@ -86,6 +86,7 @@ X(cameraPos)
|
||||
X(color)
|
||||
X(colorAdd)
|
||||
X(colorMul)
|
||||
X(debug_line)
|
||||
X(debug_overlay)
|
||||
X(delta)
|
||||
X(depthTex)
|
||||
|
@ -20,10 +20,66 @@
|
||||
#include "renderer/DebugRenderer.h"
|
||||
|
||||
#include "graphics/Camera.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "graphics/ShaderManager.h"
|
||||
#include "graphics/ShaderProgram.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "maths/BoundingBoxAligned.h"
|
||||
#include "maths/Brush.h"
|
||||
#include "maths/Vector3D.h"
|
||||
#include "renderer/Renderer.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
void CDebugRenderer::DrawLine(const CVector3D& from, const CVector3D& to, const CColor& color, const float width)
|
||||
{
|
||||
if (from == to)
|
||||
return;
|
||||
|
||||
#if CONFIG2_GLES
|
||||
#warning TODO: implement drawing line for GLES
|
||||
#else
|
||||
CShaderTechniquePtr debugLineTech =
|
||||
g_Renderer.GetShaderManager().LoadEffect(str_debug_line);
|
||||
debugLineTech->BeginPass();
|
||||
CShaderProgramPtr debugLineShader = debugLineTech->GetShader();
|
||||
|
||||
debugLineShader->Bind();
|
||||
debugLineShader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
|
||||
debugLineShader->Uniform(str_color, color);
|
||||
|
||||
// Basis to set a line with the width in R^3 space.
|
||||
const CVector3D direction = (to - from).Normalized();
|
||||
const CVector3D upCandidate = direction.Dot(CVector3D(0.0f, 1.0f, 0.0f)) > 0.9f ?
|
||||
CVector3D(1.0f, 0.0f, 0.0f) :
|
||||
CVector3D(0.0f, 1.0f, 0.0f);
|
||||
const CVector3D right = direction.Cross(upCandidate).Normalized();
|
||||
const CVector3D up = direction.Cross(right);
|
||||
|
||||
std::vector<float> vertices;
|
||||
const size_t splits = 3;
|
||||
float angle = 0.0f;
|
||||
const float step = static_cast<float>(M_PI * 2.0f / splits);
|
||||
for (size_t idx = 0; idx <= splits; ++idx, angle += step)
|
||||
{
|
||||
const CVector3D offset = (right * std::cos(angle) + up * std::sin(angle)) * width;
|
||||
const CVector3D a = from + offset;
|
||||
const CVector3D b = to + offset;
|
||||
vertices.emplace_back(a.X);
|
||||
vertices.emplace_back(a.Y);
|
||||
vertices.emplace_back(a.Z);
|
||||
vertices.emplace_back(b.X);
|
||||
vertices.emplace_back(b.Y);
|
||||
vertices.emplace_back(b.Z);
|
||||
}
|
||||
debugLineShader->VertexPointer(3, GL_FLOAT, sizeof(float) * 3, vertices.data());
|
||||
debugLineShader->AssertPointersBound();
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size() / 3);
|
||||
|
||||
debugLineShader->Unbind();
|
||||
debugLineTech->EndPass();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, int intermediates) const
|
||||
{
|
||||
|
@ -23,12 +23,20 @@
|
||||
class CBoundingBoxAligned;
|
||||
class CBrush;
|
||||
class CCamera;
|
||||
class CVector3D;
|
||||
|
||||
struct CColor;
|
||||
|
||||
// Helper for unoptimized rendering of geometrics primitives. Should not be
|
||||
// used for regular passes.
|
||||
class CDebugRenderer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Render the line in world space.
|
||||
*/
|
||||
void DrawLine(const CVector3D& from, const CVector3D& to, const CColor& color, const float width);
|
||||
|
||||
/**
|
||||
* Render: Renders the camera's frustum in world space.
|
||||
* The caller should set the color using glColorXy before calling Render.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -35,6 +35,7 @@
|
||||
#include "ps/Game.h"
|
||||
#include "ps/GameSetup/GameSetup.h"
|
||||
#include "ps/World.h"
|
||||
#include "renderer/DebugRenderer.h"
|
||||
#include "renderer/Renderer.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "simulation2/components/ICmpObstructionManager.h"
|
||||
@ -239,39 +240,17 @@ void AtlasViewGame::DrawCinemaPathTool()
|
||||
if (!m_DrawMoveTool)
|
||||
return;
|
||||
|
||||
#if CONFIG2_GLES
|
||||
#warning TODO : implement Atlas cinema path tool for GLES
|
||||
#else
|
||||
CVector3D focus = m_MoveTool;
|
||||
CVector3D camera = GetCamera().GetOrientation().GetTranslation();
|
||||
float scale = (focus - camera).Length() / 10.0;
|
||||
const CVector3D focus = m_MoveTool;
|
||||
const CVector3D camera = GetCamera().GetOrientation().GetTranslation();
|
||||
const float scale = (focus - camera).Length();
|
||||
const float axisLength = scale / 10.0f;
|
||||
const float lineWidth = scale / 1e3f;
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glLineWidth(1.6f);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex3fv(focus.GetFloatArray());
|
||||
glVertex3fv((focus + CVector3D(scale, 0, 0)).GetFloatArray());
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex3fv(focus.GetFloatArray());
|
||||
glVertex3fv((focus + CVector3D(0, scale, 0)).GetFloatArray());
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex3fv(focus.GetFloatArray());
|
||||
glVertex3fv((focus + CVector3D(0, 0, scale)).GetFloatArray());
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
glLineWidth(1.0f);
|
||||
g_Renderer.GetDebugRenderer().DrawLine(focus, focus + CVector3D(axisLength, 0, 0), CColor(1.0f, 0.0f, 0.0f, 1.0f), lineWidth);
|
||||
g_Renderer.GetDebugRenderer().DrawLine(focus, focus + CVector3D(0, axisLength, 0), CColor(0.0f, 1.0f, 0.0f, 1.0f), lineWidth);
|
||||
g_Renderer.GetDebugRenderer().DrawLine(focus, focus + CVector3D(0, 0, axisLength), CColor(0.0f, 0.0f, 1.0f, 1.0f), lineWidth);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AtlasViewGame::DrawOverlays()
|
||||
@ -279,6 +258,9 @@ void AtlasViewGame::DrawOverlays()
|
||||
#if CONFIG2_GLES
|
||||
#warning TODO: implement Atlas game overlays for GLES
|
||||
#else
|
||||
if (m_BandboxArray.empty())
|
||||
return;
|
||||
|
||||
// Set up transform for overlays
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
@ -295,20 +277,17 @@ void AtlasViewGame::DrawOverlays()
|
||||
transform = proj * transform;
|
||||
glLoadMatrixf(&transform._11);
|
||||
|
||||
if (m_BandboxArray.size() > 0)
|
||||
{
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
// Render bandbox as array of lines
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(SBandboxVertex), &m_BandboxArray[0].x);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(SBandboxVertex), &m_BandboxArray[0].r);
|
||||
// Render bandbox as array of lines
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(SBandboxVertex), &m_BandboxArray[0].x);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(SBandboxVertex), &m_BandboxArray[0].r);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, m_BandboxArray.size());
|
||||
glDrawArrays(GL_LINES, 0, m_BandboxArray.size());
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
Loading…
Reference in New Issue
Block a user