mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | FPS ~ | Single triangle shader
This commit is contained in:
@ -26,7 +26,7 @@ class Window
|
|||||||
|
|
||||||
GLFWwindow *getWindow(void) const;
|
GLFWwindow *getWindow(void) const;
|
||||||
RT::Vec2i getMousePos(void) const;
|
RT::Vec2i getMousePos(void) const;
|
||||||
|
float getFps(void) const;
|
||||||
|
|
||||||
void display();
|
void display();
|
||||||
void pollEvents();
|
void pollEvents();
|
||||||
@ -40,6 +40,8 @@ class Window
|
|||||||
GLFWwindow *_window;
|
GLFWwindow *_window;
|
||||||
RT::Vec2i _mousePos;
|
RT::Vec2i _mousePos;
|
||||||
|
|
||||||
|
float _fps;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -51,7 +51,8 @@ void main()
|
|||||||
vec2 uv;
|
vec2 uv;
|
||||||
vec4 color;
|
vec4 color;
|
||||||
|
|
||||||
uv = gl_FragCoord.xy / u_resolution.xy * 2.0 - 1.0;
|
uv = gl_FragCoord.xy / u_resolution.xy;
|
||||||
|
uv = uv * 2.0 - 1.0;
|
||||||
uv.x *= u_resolution.x / u_resolution.y;
|
uv.x *= u_resolution.x / u_resolution.y;
|
||||||
|
|
||||||
vec3 rayOrigin = vec3(0.0, 0.0, 0.0);
|
vec3 rayOrigin = vec3(0.0, 0.0, 0.0);
|
||||||
@ -70,6 +71,6 @@ void main()
|
|||||||
vec3 color = computeLighting(hitPoint, normal, viewDir);
|
vec3 color = computeLighting(hitPoint, normal, viewDir);
|
||||||
FragColor = vec4(color, 1.0);
|
FragColor = vec4(color, 1.0);
|
||||||
} else {
|
} else {
|
||||||
FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
FragColor = vec4(0., 0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
14
srcs/RT.cpp
14
srcs/RT.cpp
@ -14,14 +14,17 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
Window window(WIDTH, HEIGHT, "RT_GPU", 1);
|
Window window(WIDTH, HEIGHT, "RT_GPU", 0);
|
||||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag");
|
Shader shader("shaders/vertex.vert", "shaders/frag.frag");
|
||||||
|
|
||||||
shader.attach();
|
shader.attach();
|
||||||
|
|
||||||
RT::Vec2f vertices[6] = {
|
// RT::Vec2f vertices[6] = {
|
||||||
{ -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f },
|
// { -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f },
|
||||||
{ 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }
|
// { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }
|
||||||
|
// };
|
||||||
|
RT::Vec2f vertices[3] = {
|
||||||
|
{-1.0f, -1.0f}, {3.0f, -1.0f}, {-1.0f, 3.0f}
|
||||||
};
|
};
|
||||||
size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3;
|
size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3;
|
||||||
|
|
||||||
@ -32,10 +35,11 @@ int main(void)
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
shader.setVec2f("u_resolution", RT::Vec2f(WIDTH, HEIGHT));
|
shader.setVec2f("u_resolution", RT::Vec2f(WIDTH, HEIGHT));
|
||||||
|
|
||||||
glUseProgram(shader.getProgram());
|
glUseProgram(shader.getProgram());
|
||||||
shader.drawTriangles(size);
|
shader.drawTriangles(size);
|
||||||
|
|
||||||
|
std::cout << "\rFPS: " << int(window.getFps()) << " " << std::flush;
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
window.pollEvents();
|
window.pollEvents();
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,15 @@ void Window::mouseButtonCallback(GLFWwindow* window, int button, int action, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Window::display()
|
void Window::display()
|
||||||
{
|
{
|
||||||
|
static double lastTime = glfwGetTime();
|
||||||
|
double currentTime = glfwGetTime();
|
||||||
|
double delta = currentTime - lastTime;
|
||||||
|
|
||||||
|
lastTime = currentTime;
|
||||||
|
_fps = 1.0f / delta;
|
||||||
|
|
||||||
glfwSwapBuffers(_window);
|
glfwSwapBuffers(_window);
|
||||||
}
|
}
|
||||||
void Window::pollEvents()
|
void Window::pollEvents()
|
||||||
@ -107,3 +113,8 @@ RT::Vec2i Window::getMousePos(void) const
|
|||||||
{
|
{
|
||||||
return (_mousePos);
|
return (_mousePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Window::getFps(void) const
|
||||||
|
{
|
||||||
|
return (_fps);
|
||||||
|
}
|
Reference in New Issue
Block a user