Brute force debugging
This commit is contained in:
parent
5cbd74c93d
commit
a6705f6e6e
3 changed files with 57 additions and 5 deletions
|
@ -8,7 +8,7 @@
|
||||||
#include <gui/GLShader.h>
|
#include <gui/GLShader.h>
|
||||||
#include <gui/GLBuffer.h>
|
#include <gui/GLBuffer.h>
|
||||||
#include <gui/GLVertexArray.h>
|
#include <gui/GLVertexArray.h>
|
||||||
|
#include "timer.h"
|
||||||
class Viewer : public nse::gui::AbstractViewer
|
class Viewer : public nse::gui::AbstractViewer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -23,6 +23,8 @@ class Viewer : public nse::gui::AbstractViewer
|
||||||
private:
|
private:
|
||||||
void RenderSky();
|
void RenderSky();
|
||||||
|
|
||||||
|
Counter counter;
|
||||||
|
|
||||||
Eigen::Matrix4f view, proj;
|
Eigen::Matrix4f view, proj;
|
||||||
|
|
||||||
nse::gui::GLShader skyShader;
|
nse::gui::GLShader skyShader;
|
||||||
|
|
44
exercise2/include/timer.h
Normal file
44
exercise2/include/timer.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ratio>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
typedef std::chrono::duration<int, std::milli> milliseconds_type;
|
||||||
|
|
||||||
|
class Counter {
|
||||||
|
private:
|
||||||
|
int max;
|
||||||
|
int n;
|
||||||
|
std::chrono::_V2::system_clock::time_point last_time;
|
||||||
|
milliseconds_type update_interval;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Counter(int max, float interval)
|
||||||
|
: max(max), update_interval((int)(interval * 1000.0f))
|
||||||
|
{
|
||||||
|
last_time = std::chrono::high_resolution_clock::now();
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
~Counter() {}
|
||||||
|
|
||||||
|
int get_counter() {
|
||||||
|
auto new_time = std::chrono::high_resolution_clock::now();
|
||||||
|
milliseconds_type time_difference = std::chrono::duration_cast<milliseconds_type>(new_time - last_time);
|
||||||
|
|
||||||
|
if (time_difference.count() >= update_interval.count()) {
|
||||||
|
last_time += update_interval;
|
||||||
|
|
||||||
|
n++;
|
||||||
|
|
||||||
|
if (n >= max) {
|
||||||
|
n = n - max;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
};
|
|
@ -27,14 +27,16 @@
|
||||||
#define Eigen::Vector2f vec2
|
#define Eigen::Vector2f vec2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
constexpr bool REFERENCE = true;
|
constexpr bool REFERENCE = false;
|
||||||
constexpr uint32_t PATCH_SIZE = 256; //number of vertices along one side of the terrain patch
|
constexpr uint32_t PATCH_SIZE = 32; //number of vertices along one side of the terrain patch
|
||||||
|
constexpr int elements = PATCH_SIZE * 12;
|
||||||
|
|
||||||
Viewer::Viewer()
|
Viewer::Viewer()
|
||||||
: AbstractViewer("CG1 Exercise 2"),
|
: AbstractViewer("CG1 Exercise 2"),
|
||||||
terrainPositions(nse::gui::VertexBuffer), terrainIndices(nse::gui::IndexBuffer),
|
terrainPositions(nse::gui::VertexBuffer), terrainIndices(nse::gui::IndexBuffer),
|
||||||
offsetBuffer(nse::gui::VertexBuffer),
|
offsetBuffer(nse::gui::VertexBuffer),
|
||||||
referenceVB(nse::gui::VertexBuffer), referenceIB(nse::gui::IndexBuffer)
|
referenceVB(nse::gui::VertexBuffer), referenceIB(nse::gui::IndexBuffer),
|
||||||
|
counter(elements, 0.5)
|
||||||
{
|
{
|
||||||
LoadShaders();
|
LoadShaders();
|
||||||
CreateGeometry();
|
CreateGeometry();
|
||||||
|
@ -381,7 +383,11 @@ void Viewer::drawContents()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glPrimitiveRestartIndex(PATCH_SIZE * 2);
|
int n = counter.get_counter();
|
||||||
|
|
||||||
|
std::cout << "current n: " << n << std::endl;
|
||||||
|
|
||||||
|
glPrimitiveRestartIndex(n);
|
||||||
glDrawElements(GL_TRIANGLE_STRIP, (PATCH_SIZE - 1) * PATCH_SIZE * 2, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLE_STRIP, (PATCH_SIZE - 1) * PATCH_SIZE * 2, GL_UNSIGNED_INT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue