fixed so the picking works with the new framebuffer class

This commit is contained in:
viktorljung
2015-12-03 19:20:30 +01:00
parent a82c7c1e3b
commit 96a10ada38
3 changed files with 12 additions and 11 deletions
+3 -2
View File
@@ -5,6 +5,7 @@
#include "../../OpenGL.h"
#include "../../GLM.h"
#include "../../Core/Util/Rectangle.h"
#include "FrameBuffer.h"
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);
//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
static glm::vec3 ToPixelData(glm::vec2 screenCoord, GLuint PickDataBuffer, GLuint DepthBuffer);
static glm::vec3 ToPixelData(float x, float y, GLuint PickDataBuffer, GLuint DepthBuffer);
static glm::vec3 ToPixelData(glm::vec2 screenCoord, FrameBuffer* 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.
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);
+5 -5
View File
@@ -161,7 +161,7 @@ void Renderer::InputUpdate(double dt)
static double mousePosX, mousePosY;
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
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);
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));
//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)) {
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.
PickingPass();
DrawScreenQuad(m_PickingTexture);
//DrawScreenQuad(m_DepthBuffer);
//DrawScene(rq);
// DrawScene(rq);
glfwSwapBuffers(m_Window);
}
@@ -298,7 +298,7 @@ void Renderer::PickingPass()
}
}
}
m_PickingBuffer.Unbind();
}
+4 -4
View File
@@ -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);
}
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;
glReadPixels(x, y, 1, 1, GL_RG, GL_FLOAT, &pixelData);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
PickDataBuffer->Unbind();
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
float depthData;
@@ -44,7 +44,7 @@ glm::vec3 ScreenCoords::ToPixelData(float x, float y, GLuint PickDataBuffer, GLu
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);
}