Skip to content

Commit bbfa55c

Browse files
authored
Merge pull request #328 from lukaspj/feature/guiRenderTargetVizCtrl
Implementation of guiRenderTargetVizCtrl
2 parents 8c49019 + dca2dc0 commit bbfa55c

File tree

8 files changed

+339
-3
lines changed

8 files changed

+339
-3
lines changed

Engine/source/T3D/camera.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ class Camera: public ShapeBase
253253
DECLARE_DESCRIPTION( "Represents a position, direction and field of view to render a scene from." );
254254
static F32 getMovementSpeed() { return smMovementSpeed; }
255255
bool isCamera() const { return true; }
256+
257+
//Not yet implemented
258+
GFXTexHandle getCameraRenderTarget() { return GFXTexHandle(); }
256259
};
257260

258261
typedef Camera::CameraMotionMode CameraMotionMode;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
//-----------------------------------------------------------------------------
2+
// Copyright (c) 2012 GarageGames, LLC
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including without limitation the
7+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
// sell copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
// IN THE SOFTWARE.
21+
//-----------------------------------------------------------------------------
22+
23+
#include "platform/platform.h"
24+
#include "gui/utility/guiRenderTargetVizCtrl.h"
25+
26+
#include "console/console.h"
27+
#include "console/consoleTypes.h"
28+
#include "gfx/gfxDevice.h"
29+
#include "gfx/gfxDrawUtil.h"
30+
#include "gui/core/guiCanvas.h"
31+
#include "gui/core/guiDefaultControlRender.h"
32+
33+
#include "T3D/camera.h"
34+
35+
IMPLEMENT_CONOBJECT(GuiRenderTargetVizCtrl);
36+
37+
ConsoleDocClass(GuiRenderTargetVizCtrl,
38+
"@brief The most widely used button class.\n\n"
39+
40+
"GuiRenderTargetVizCtrl renders seperately of, but utilizes all of the functionality of GuiBaseButtonCtrl.\n"
41+
"This grants GuiRenderTargetVizCtrl the versatility to be either of the 3 button types.\n\n"
42+
43+
"@tsexample\n"
44+
"// Create a PushButton GuiRenderTargetVizCtrl that calls randomFunction when clicked\n"
45+
"%button = new GuiRenderTargetVizCtrl()\n"
46+
"{\n"
47+
" profile = \"GuiButtonProfile\";\n"
48+
" buttonType = \"PushButton\";\n"
49+
" command = \"randomFunction();\";\n"
50+
"};\n"
51+
"@endtsexample\n\n"
52+
53+
"@ingroup GuiButtons"
54+
);
55+
56+
57+
//-----------------------------------------------------------------------------
58+
59+
GuiRenderTargetVizCtrl::GuiRenderTargetVizCtrl()
60+
{
61+
mTargetName = StringTable->EmptyString();
62+
63+
mTarget = nullptr;
64+
mTargetTexture = nullptr;
65+
66+
mCameraObject = nullptr;
67+
}
68+
69+
//-----------------------------------------------------------------------------
70+
71+
bool GuiRenderTargetVizCtrl::onWake()
72+
{
73+
if (!Parent::onWake())
74+
return false;
75+
76+
return true;
77+
}
78+
79+
void GuiRenderTargetVizCtrl::initPersistFields()
80+
{
81+
Parent::initPersistFields();
82+
83+
addField("RenderTargetName", TypeString, Offset(mTargetName, GuiRenderTargetVizCtrl), "");
84+
addField("cameraObject", TypeSimObjectPtr, Offset(mCameraObject, GuiRenderTargetVizCtrl), "");
85+
}
86+
87+
//-----------------------------------------------------------------------------
88+
89+
void GuiRenderTargetVizCtrl::onRender(Point2I offset,
90+
const RectI& updateRect)
91+
{
92+
GFXDrawUtil* drawer = GFX->getDrawUtil();
93+
94+
RectI boundsRect(offset, getExtent());
95+
96+
//Draw backdrop
97+
GFX->getDrawUtil()->drawRectFill(boundsRect, ColorI::BLACK);
98+
99+
if (mCameraObject != nullptr)
100+
{
101+
Camera* camObject = dynamic_cast<Camera*>(mCameraObject);
102+
103+
camObject = dynamic_cast<Camera*>(camObject->getClientObject());
104+
105+
bool servObj = camObject->isServerObject();
106+
107+
if (camObject)
108+
{
109+
GFXTexHandle targ = camObject->getCameraRenderTarget();
110+
111+
if (targ)
112+
{
113+
Point2I size = Point2I(targ->getWidth(), targ->getHeight());
114+
drawer->drawBitmapStretchSR(targ, boundsRect, RectI(Point2I::Zero, size));
115+
}
116+
return;
117+
}
118+
}
119+
else if (mTargetName == StringTable->EmptyString())
120+
return;
121+
122+
NamedTexTarget* namedTarget = NamedTexTarget::find(mTargetName);
123+
if (namedTarget)
124+
{
125+
GFXTextureObject* theTex = namedTarget->getTexture(0);
126+
RectI viewport = namedTarget->getViewport();
127+
128+
drawer->drawBitmapStretchSR(theTex, boundsRect, viewport);
129+
}
130+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//-----------------------------------------------------------------------------
2+
// Copyright (c) 2012 GarageGames, LLC
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to
6+
// deal in the Software without restriction, including without limitation the
7+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
// sell copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
// IN THE SOFTWARE.
21+
//-----------------------------------------------------------------------------
22+
#pragma once
23+
24+
#ifndef GUIRENDERTARGETVIZCTRL_H
25+
#define GUIRENDERTARGETVIZCTRL_H
26+
27+
#ifndef _GUICONTROL_H_
28+
#include "gui/core/guiControl.h"
29+
#endif
30+
#ifndef _TEXTARGETBIN_MGR_H_
31+
#include "renderInstance/renderTexTargetBinManager.h"
32+
#endif
33+
34+
class GuiRenderTargetVizCtrl : public GuiControl
35+
{
36+
typedef GuiControl Parent;
37+
38+
RenderTexTargetBinManager* mRTTManager;
39+
40+
SimObject* mCameraObject;
41+
42+
StringTableEntry mTargetName;
43+
GFXFormat mTargetFormat;
44+
Point2I mTargetSize;
45+
46+
GFXTextureTargetRef mTarget;
47+
GFXTexHandle mTargetTexture;
48+
49+
public:
50+
DECLARE_CONOBJECT(GuiRenderTargetVizCtrl);
51+
GuiRenderTargetVizCtrl();
52+
bool onWake();
53+
void onRender(Point2I offset, const RectI &updateRect);
54+
55+
static void initPersistFields();
56+
};
57+
58+
#endif //GUIRENDERTARGETVIZCTRL_H

Engine/source/materials/matTextureTarget.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,16 @@ void NamedTexTarget::getShaderMacros( Vector<GFXShaderMacro> *outMacros )
145145
macro.value = uncondMethod;
146146
outMacros->push_back( macro );
147147
}
148-
}
148+
}
149+
150+
DefineEngineFunction(getNamedTargetList, String, (), , "")
151+
{
152+
String targetList = "";
153+
NamedTexTarget::TargetMap targets = NamedTexTarget::getTargetMap();
154+
for (NamedTexTarget::TargetMap::Iterator iter = targets.begin(); iter != targets.end(); iter++)
155+
{
156+
targetList += iter->value->getName() + " ";
157+
}
158+
159+
return targetList;
160+
}

Engine/source/materials/matTextureTarget.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ class NamedTexTarget : public WeakRefBase
117117
ConditionerFeature* getConditioner() const { return mConditioner; }
118118
void getShaderMacros( Vector<GFXShaderMacro> *outMacros );
119119

120+
typedef Map<String, NamedTexTarget*> TargetMap;
121+
122+
static TargetMap getTargetMap() {
123+
return smTargets;
124+
}
125+
120126
protected:
121-
122-
typedef Map<String,NamedTexTarget*> TargetMap;
123127

124128
///
125129
static TargetMap smTargets;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function ToggleRenderTargetVisualizer()
2+
{
3+
if(RenderTargetVisualizer.isAwake())
4+
{
5+
Canvas.popDialog(RenderTargetVisualizer);
6+
}
7+
else
8+
{
9+
Canvas.pushDialog(RenderTargetVisualizer);
10+
}
11+
}
12+
13+
function RenderTargetVisualizer::onWake(%this)
14+
{
15+
%targetsList = getNamedTargetList();
16+
17+
%targetsCount = getWordCount(%targetsList);
18+
for(%i=0; %i < %targetsCount; %i++)
19+
{
20+
%targetName = getWord(%targetsList, %i);
21+
RenderTargetsList.add(%targetName, %i);
22+
}
23+
24+
RenderTargetsList.setSelected( 0, false );
25+
RenderTargetVizCtrl.RenderTargetName = RenderTargetsList.getValue();
26+
}
27+
28+
function RenderTargetsList::updateTarget(%this)
29+
{
30+
%target = RenderTargetsList.getValue();
31+
32+
RenderTargetVizCtrl.RenderTargetName = %target;
33+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//--- OBJECT WRITE BEGIN ---
2+
%guiContent = new GuiControl(RenderTargetVisualizer) {
3+
position = "0 0";
4+
extent = "1024 768";
5+
minExtent = "8 2";
6+
horizSizing = "right";
7+
vertSizing = "bottom";
8+
profile = "GuiModelessDialogProfile";
9+
visible = "1";
10+
active = "1";
11+
tooltipProfile = "GuiToolTipProfile";
12+
hovertime = "1000";
13+
isContainer = "1";
14+
canSave = "1";
15+
canSaveDynamicFields = "1";
16+
17+
new GuiWindowCtrl(RenderTargetVizWindow) {
18+
text = "Render Target Visualizer";
19+
resizeWidth = "1";
20+
resizeHeight = "1";
21+
canMove = "1";
22+
canClose = "1";
23+
canMinimize = "1";
24+
canMaximize = "1";
25+
canCollapse = "0";
26+
closeCommand = "Canvas.popDialog(RenderTargetVisualizer);";
27+
edgeSnap = "1";
28+
margin = "0 0 0 0";
29+
padding = "0 0 0 0";
30+
anchorTop = "1";
31+
anchorBottom = "0";
32+
anchorLeft = "1";
33+
anchorRight = "0";
34+
position = "189 96";
35+
extent = "637 535";
36+
minExtent = "8 2";
37+
horizSizing = "right";
38+
vertSizing = "bottom";
39+
profile = "GuiWindowProfile";
40+
visible = "1";
41+
active = "1";
42+
tooltipProfile = "GuiToolTipProfile";
43+
hovertime = "1000";
44+
isContainer = "1";
45+
canSave = "1";
46+
canSaveDynamicFields = "0";
47+
48+
new GuiRenderTargetVizCtrl(RenderTargetVizCtrl) {
49+
position = "0 38";
50+
extent = "636 496";
51+
minExtent = "8 2";
52+
horizSizing = "width";
53+
vertSizing = "height";
54+
profile = "GuiDefaultProfile";
55+
visible = "1";
56+
active = "1";
57+
tooltipProfile = "GuiToolTipProfile";
58+
hovertime = "1000";
59+
isContainer = "0";
60+
canSave = "1";
61+
canSaveDynamicFields = "0";
62+
RenderTargetName = "AL_FormatToken";
63+
};
64+
new GuiPopUpMenuCtrl(RenderTargetsList) {
65+
maxPopupHeight = "200";
66+
sbUsesNAColor = "0";
67+
reverseTextList = "0";
68+
bitmapBounds = "16 16";
69+
text = "AL_FormatToken";
70+
maxLength = "1024";
71+
margin = "0 0 0 0";
72+
padding = "0 0 0 0";
73+
anchorTop = "1";
74+
anchorBottom = "0";
75+
anchorLeft = "1";
76+
anchorRight = "0";
77+
position = "0 20";
78+
extent = "636 18";
79+
minExtent = "8 2";
80+
horizSizing = "width";
81+
vertSizing = "bottom";
82+
profile = "GuiPopUpMenuProfile";
83+
visible = "1";
84+
active = "1";
85+
command = "RenderTargetsList.updateTarget();";
86+
tooltipProfile = "GuiToolTipProfile";
87+
hovertime = "1000";
88+
isContainer = "1";
89+
canSave = "1";
90+
canSaveDynamicFields = "0";
91+
};
92+
};
93+
};
94+
//--- OBJECT WRITE END ---

Templates/BaseGame/game/tools/worldEditor/main.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function initializeWorldEditor()
4343
exec("./gui/AddFMODProjectDlg.ed.gui");
4444
exec("./gui/SelectObjectsWindow.ed.gui");
4545
exec("./gui/ProceduralTerrainPainterGui.gui" );
46+
exec("tools/gui/renderTargetVisualizer.ed.gui");
4647
exec("./gui/shadowViz.gui" );
4748
exec("./gui/probeBakeDlg.gui" );
4849

@@ -75,6 +76,7 @@ function initializeWorldEditor()
7576
exec("./scripts/visibility/miscViz.cs");
7677

7778
exec("tools/gui/postFxEditor.cs" );
79+
exec("tools/gui/renderTargetVisualizer.ed.cs");
7880

7981
// Load Custom Editors
8082
loadDirectory(expandFilename("./scripts/editors"));

0 commit comments

Comments
 (0)