-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See: #15
- Loading branch information
Showing
12 changed files
with
268 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 330 | ||
|
||
uniform uint object_type; | ||
uniform uint object_id; | ||
|
||
out uvec3 picking_fragment; | ||
|
||
void main() { | ||
// The leading 1.0 is to indicate the presence of an object | ||
// in the texture, since by default, OpenGL will, clear to 0 | ||
// so, we need some way to tell an object was rendered at this | ||
// fragment | ||
picking_fragment = uvec3(1.0, object_type, object_id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#version 330 | ||
|
||
layout (location = 0) in vec3 in_position; | ||
|
||
uniform mat4 model; | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
void main() { | ||
gl_Position = projection * view * model * vec4(in_position, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* NIST-developed software is provided by NIST as a public service. You may use, | ||
* copy and distribute copies of the software in any medium, provided that you | ||
* keep intact this entire notice. You may improve,modify and create derivative | ||
* works of the software or any portion of the software, and you may copy and | ||
* distribute such modifications or works. Modified works should carry a notice | ||
* stating that you changed the software and should note the date and nature of | ||
* any such change. Please explicitly acknowledge the National Institute of | ||
* Standards and Technology as the source of the software. | ||
* | ||
* NIST-developed software is expressly provided "AS IS." NIST MAKES NO | ||
* WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF | ||
* LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT | ||
* AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR WARRANTS THAT THE | ||
* OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT | ||
* ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY | ||
* REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, | ||
* INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, | ||
* OR USEFULNESS OF THE SOFTWARE. | ||
* | ||
* You are solely responsible for determining the appropriateness of using and | ||
* distributing the software and you assume all risks associated with its use, | ||
* including but not limited to the risks and costs of program errors, | ||
* compliance with applicable laws, damage to or loss of data, programs or | ||
* equipment, and the unavailability or interruption of operation. This | ||
* software is not intended to be used in any situation where a failure could | ||
* cause risk of injury or damage to property. The software developed by NIST | ||
* employees is not subject to copyright protection within the United States. | ||
* | ||
* Author: Evan Black <[email protected]> | ||
*/ | ||
|
||
#include "PickingFramebuffer.h" | ||
#include <QOpenGLFunctions_3_3_Core> | ||
namespace netsimulyzer { | ||
|
||
void PickingFramebuffer::generate(int width, int height) { | ||
openGl.glGenFramebuffers(1, &fbo); | ||
bind(GL_FRAMEBUFFER); | ||
|
||
openGl.glGenTextures(1, &idTexture); | ||
openGl.glBindTexture(GL_TEXTURE_2D, idTexture); | ||
openGl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, width, height, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr); | ||
openGl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
openGl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
openGl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, idTexture, 0); | ||
|
||
openGl.glGenTextures(1, &depthTexture); | ||
openGl.glBindTexture(GL_TEXTURE_2D, depthTexture); | ||
openGl.glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); | ||
openGl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); | ||
} | ||
|
||
// NOLINT(cppcoreguidelines-pro-type-member-init) | ||
PickingFramebuffer::PickingFramebuffer(QOpenGLFunctions_3_3_Core &openGl, int width, int height) | ||
: openGl(openGl) { // NOLINT(cppcoreguidelines-pro-type-member-init) | ||
generate(width, height); | ||
} | ||
|
||
PickingFramebuffer::~PickingFramebuffer() { | ||
openGl.glDeleteTextures(1, &idTexture); | ||
openGl.glDeleteTextures(1, &depthTexture); | ||
openGl.glDeleteFramebuffers(1, &fbo); | ||
} | ||
|
||
void PickingFramebuffer::bind(GLenum mode) const { | ||
openGl.glBindFramebuffer(mode, fbo); | ||
} | ||
|
||
void PickingFramebuffer::unbind(GLenum mode, unsigned int defaultFbo) const { | ||
openGl.glBindFramebuffer(mode, defaultFbo); | ||
} | ||
|
||
PickingFramebuffer::PixelInfo PickingFramebuffer::read(int x, int y) const { | ||
bind(GL_READ_FRAMEBUFFER); | ||
openGl.glReadBuffer(GL_COLOR_ATTACHMENT0); | ||
|
||
PixelInfo pixelInfo; // NOLINT(cppcoreguidelines-pro-type-member-init) | ||
openGl.glReadPixels(x, y, 1, 1, GL_RGB_INTEGER, GL_UNSIGNED_INT, &pixelInfo); | ||
|
||
return pixelInfo; | ||
} | ||
|
||
void PickingFramebuffer::resize(int width, int height) { | ||
openGl.glDeleteTextures(1, &idTexture); | ||
openGl.glDeleteTextures(1, &depthTexture); | ||
openGl.glDeleteFramebuffers(1, &fbo); | ||
generate(width, height); | ||
} | ||
|
||
} // namespace netsimulyzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* NIST-developed software is provided by NIST as a public service. You may use, | ||
* copy and distribute copies of the software in any medium, provided that you | ||
* keep intact this entire notice. You may improve,modify and create derivative | ||
* works of the software or any portion of the software, and you may copy and | ||
* distribute such modifications or works. Modified works should carry a notice | ||
* stating that you changed the software and should note the date and nature of | ||
* any such change. Please explicitly acknowledge the National Institute of | ||
* Standards and Technology as the source of the software. | ||
* | ||
* NIST-developed software is expressly provided "AS IS." NIST MAKES NO | ||
* WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF | ||
* LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT | ||
* AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR WARRANTS THAT THE | ||
* OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT | ||
* ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY | ||
* REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, | ||
* INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, | ||
* OR USEFULNESS OF THE SOFTWARE. | ||
* | ||
* You are solely responsible for determining the appropriateness of using and | ||
* distributing the software and you assume all risks associated with its use, | ||
* including but not limited to the risks and costs of program errors, | ||
* compliance with applicable laws, damage to or loss of data, programs or | ||
* equipment, and the unavailability or interruption of operation. This | ||
* software is not intended to be used in any situation where a failure could | ||
* cause risk of injury or damage to property. The software developed by NIST | ||
* employees is not subject to copyright protection within the United States. | ||
* | ||
* Author: Evan Black <[email protected]> | ||
*/ | ||
#pragma once | ||
#include <QOpenGLFunctions_3_3_Core> | ||
|
||
namespace netsimulyzer { | ||
|
||
class PickingFramebuffer { | ||
QOpenGLFunctions_3_3_Core &openGl; | ||
unsigned int fbo; | ||
unsigned int idTexture; | ||
unsigned int depthTexture; | ||
|
||
void generate(int width, int height); | ||
|
||
public: | ||
struct PixelInfo { | ||
unsigned int object; | ||
unsigned int type; | ||
unsigned int id; | ||
}; | ||
|
||
PickingFramebuffer(QOpenGLFunctions_3_3_Core &openGl, int width, int height); | ||
~PickingFramebuffer(); | ||
|
||
// Disallow copying | ||
PickingFramebuffer(const PickingFramebuffer &) = delete; | ||
PickingFramebuffer &operator=(const PickingFramebuffer &) = delete; | ||
|
||
void bind(GLenum mode) const; | ||
void unbind(GLenum mode, unsigned int defaultFbo) const; | ||
|
||
[[nodiscard]] PixelInfo read(int x, int y) const; | ||
|
||
inline unsigned int getIds() { | ||
return idTexture; | ||
} | ||
|
||
void resize(int width, int height); | ||
}; | ||
|
||
} // namespace netsimulyzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters