fixed so the picking works with the new framebuffer class
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include "../../OpenGL.h"
|
#include "../../OpenGL.h"
|
||||||
#include "../../GLM.h"
|
#include "../../GLM.h"
|
||||||
#include "../../Core/Util/Rectangle.h"
|
#include "../../Core/Util/Rectangle.h"
|
||||||
|
#include "FrameBuffer.h"
|
||||||
|
|
||||||
class ScreenCoords
|
class ScreenCoords
|
||||||
{
|
{
|
||||||
@@ -17,8 +18,8 @@ public:
|
|||||||
static glm::vec3 ToWorldPos(float x, float y, float depth, float screenWidth, float screenHeight, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
static glm::vec3 ToWorldPos(float x, float y, float depth, float screenWidth, float screenHeight, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
|
||||||
//Return data from the given buffers at the coordinates given in screenspace. Buffer should probably have a texture that covers the screen.
|
//Return data from the given buffers at the coordinates given in screenspace. Buffer should probably have a texture that covers the screen.
|
||||||
//Data is given as R = x, B = y, and
|
//Data is given as R = x, B = y, and
|
||||||
static glm::vec3 ToPixelData(glm::vec2 screenCoord, GLuint PickDataBuffer, GLuint DepthBuffer);
|
static glm::vec3 ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
|
||||||
static glm::vec3 ToPixelData(float x, float y, GLuint PickDataBuffer, GLuint DepthBuffer);
|
static glm::vec3 ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
|
||||||
//Return EntityID of the clicked coordinate in given screenspace coordinates.
|
//Return EntityID of the clicked coordinate in given screenspace coordinates.
|
||||||
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);
|
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ void Renderer::InputUpdate(double dt)
|
|||||||
static double mousePosX, mousePosY;
|
static double mousePosX, mousePosY;
|
||||||
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
||||||
if (glfwGetMouseButton(m_Window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS) {
|
if (glfwGetMouseButton(m_Window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS) {
|
||||||
glm::vec3 data = ScreenCoords::ToPixelData(mousePosX, m_Resolution.Height - mousePosY, m_PickingBuffer, m_DepthBuffer);
|
glm::vec3 data = ScreenCoords::ToPixelData(mousePosX, m_Resolution.Height - mousePosY, &m_PickingBuffer, m_DepthBuffer);
|
||||||
glm::vec2 color = glm::vec2(data);
|
glm::vec2 color = glm::vec2(data);
|
||||||
float depth = data.z;
|
float depth = data.z;
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ void Renderer::InputUpdate(double dt)
|
|||||||
// glm::vec3 worldPos = glm::vec3(glm::inverse(m_Camera->ViewMatrix()) * glm::vec4(viewPos, 1.f));
|
// glm::vec3 worldPos = glm::vec3(glm::inverse(m_Camera->ViewMatrix()) * glm::vec4(viewPos, 1.f));
|
||||||
|
|
||||||
//printf("R: %f, G: %f, Depth: %f\n", color.r, color.g, depth);
|
//printf("R: %f, G: %f, Depth: %f\n", color.r, color.g, depth);
|
||||||
//printf("view: x: %f, y: %f z: %f, Length: %f\n\n", viewPos.x, viewPos.y, viewPos.z, glm::length(viewPos));
|
printf("view: x: %f, y: %f z: %f, Length: %f\n\n", viewPos.x, viewPos.y, viewPos.z, glm::length(viewPos));
|
||||||
|
|
||||||
if (color != glm::vec2(0, 0)) {
|
if (color != glm::vec2(0, 0)) {
|
||||||
const Model* pickModel = m_PickingColorsToModels[color];
|
const Model* pickModel = m_PickingColorsToModels[color];
|
||||||
@@ -209,8 +209,8 @@ void Renderer::Draw(RenderQueueCollection& rq)
|
|||||||
//TODO: Renderer: Kanske borde vara längst upp i update.
|
//TODO: Renderer: Kanske borde vara längst upp i update.
|
||||||
PickingPass();
|
PickingPass();
|
||||||
DrawScreenQuad(m_PickingTexture);
|
DrawScreenQuad(m_PickingTexture);
|
||||||
//DrawScreenQuad(m_DepthBuffer);
|
|
||||||
//DrawScene(rq);
|
// DrawScene(rq);
|
||||||
glfwSwapBuffers(m_Window);
|
glfwSwapBuffers(m_Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ void Renderer::PickingPass()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_PickingBuffer.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ glm::vec3 ScreenCoords::ToWorldPos(glm::vec2 screenCoord, float depth, float scr
|
|||||||
return ToWorldPos(screenCoord.x, screenCoord.y, depth, screenWidth, screenHeight, cameraProjectionMat, cameraViewMat);
|
return ToWorldPos(screenCoord.x, screenCoord.y, depth, screenWidth, screenHeight, cameraProjectionMat, cameraViewMat);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 ScreenCoords::ToPixelData(float x, float y, GLuint PickDataBuffer, GLuint DepthBuffer)
|
glm::vec3 ScreenCoords::ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, PickDataBuffer);
|
PickDataBuffer->Bind();
|
||||||
glm::vec2 pixelData;
|
glm::vec2 pixelData;
|
||||||
glReadPixels(x, y, 1, 1, GL_RG, GL_FLOAT, &pixelData);
|
glReadPixels(x, y, 1, 1, GL_RG, GL_FLOAT, &pixelData);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
PickDataBuffer->Unbind();
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
|
||||||
float depthData;
|
float depthData;
|
||||||
@@ -44,7 +44,7 @@ glm::vec3 ScreenCoords::ToPixelData(float x, float y, GLuint PickDataBuffer, GLu
|
|||||||
return glm::vec3(pixelData, depthData);
|
return glm::vec3(pixelData, depthData);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 ScreenCoords::ToPixelData(glm::vec2 screenCoord, GLuint PickDataBuffer, GLuint DepthBuffer)
|
glm::vec3 ScreenCoords::ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
||||||
{
|
{
|
||||||
return ToPixelData(screenCoord.x, screenCoord.y, PickDataBuffer, DepthBuffer);
|
return ToPixelData(screenCoord.x, screenCoord.y, PickDataBuffer, DepthBuffer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user