Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport multiple ray queries fix (#665) #690

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions ogre2/src/Ogre2SelectionBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,26 @@ void Ogre2SelectionBuffer::CreateRTTBuffer()

Ogre::TextureGpuManager *textureMgr =
ogreRoot->getRenderSystem()->getTextureGpuManager();
const std::string selectionTextureName = "SelectionPassTex";
bool hasSelectionTexture =
textureMgr->findTextureNoThrow(selectionTextureName);
this->dataPtr->renderTexture =
textureMgr->createOrRetrieveTexture(
"SelectionPassTex",
selectionTextureName,
Ogre::GpuPageOutStrategy::SaveToSystemRam,
Ogre::TextureFlags::RenderToTexture,
Ogre::TextureTypes::Type2D);
this->dataPtr->renderTexture->setResolution(1, 1);
this->dataPtr->renderTexture->setNumMipmaps(1u);
this->dataPtr->renderTexture->setPixelFormat(Ogre::PFG_RGBA32_FLOAT);

this->dataPtr->renderTexture->scheduleTransitionTo(
Ogre::GpuResidency::Resident);
if (!hasSelectionTexture)
{
this->dataPtr->renderTexture->setResolution(1, 1);
this->dataPtr->renderTexture->setNumMipmaps(1u);
this->dataPtr->renderTexture->setPixelFormat(Ogre::PFG_RGBA32_FLOAT);

// we are reusing the same render texture so schedule transition only
// if it is not resident yet otherwise it may throw an exception
this->dataPtr->renderTexture->scheduleTransitionTo(
Ogre::GpuResidency::Resident);
}

this->dataPtr->selectionCamera->addListener(
this->dataPtr->materialSwitcher.get());
Expand Down
34 changes: 31 additions & 3 deletions src/RayQuery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,45 @@ void RayQueryTest::RayQuery(const std::string &_renderEngine)

// set from camera
CameraPtr camera = scene->CreateCamera("camera");
camera->SetLocalPosition(math::Vector3d::Zero);
unsigned int width = 320u;
unsigned int height = 240u;
camera->SetImageWidth(width);
camera->SetImageHeight(height);

VisualPtr root = scene->RootVisual();
root->AddChild(camera);
math::Vector2d pos(0.0, 0.0);
rayQuery->SetFromCamera(camera, pos);

EXPECT_GT(rayQuery->Origin().X(), 0.0);
EXPECT_LT(0.0, rayQuery->Origin().X());
EXPECT_EQ(math::Vector3d::UnitX, rayQuery->Direction().Normalize());

RayQueryResult result = rayQuery->ClosestPoint();
EXPECT_EQ(math::Vector3d::Zero, result.point);
EXPECT_LT(result.distance, 0.0);
EXPECT_GT(0.0, result.distance);
EXPECT_EQ(0u, result.objectId);
EXPECT_FALSE((result));
EXPECT_FALSE(result);

// testing multiple ray queries that are set from camera
CameraPtr camera2 = scene->CreateCamera("camera2");
camera2->SetLocalPosition(math::Vector3d::Zero);
camera2->SetImageWidth(width);
camera2->SetImageHeight(height);

root->AddChild(camera2);
math::Vector2d pos2(0.0, 0.0);
RayQueryPtr rayQuery2 = scene->CreateRayQuery();
rayQuery2->SetFromCamera(camera2, pos2);

EXPECT_LT(0.0, rayQuery2->Origin().X());
EXPECT_EQ(math::Vector3d::UnitX, rayQuery2->Direction().Normalize());

RayQueryResult result2 = rayQuery2->ClosestPoint();
EXPECT_EQ(math::Vector3d::Zero, result2.point);
EXPECT_GT(0.0, result2.distance);
EXPECT_EQ(0u, result2.objectId);
EXPECT_FALSE(result2);

// Clean up
engine->DestroyScene(scene);
Expand Down