This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
+341
View File
@@ -0,0 +1,341 @@
#pragma once
#include <string>
#include "GfxBase/Type.h"
#include "GfxBase/TextureProxyBase.h"
#include "Util/Extents.h"
#include "Util/G3DCore.h"
#include "Util/ContentId.h"
#include "Util/Rotation2D.h"
#include "rbx/signal.h"
#include "rbx/Declarations.h"
namespace RBX {
class I3DLinearFunc;
class RenderCaps;
class Camera;
struct Canvas
{
Canvas(Vector2 viewPort)
:size(viewPort)
{}
Vector2 size;
Vector2 toPixelSize(const Vector2& percent) const; // std screen is 100% wide and 75% tall
int normalizedFontSize(int fontSize) const;
};
// RBX::Adorn is a base class used to decorate other objects using 2D or 3D
// basic shapes.
class RBXBaseClass Adorn
{
public:
enum Material
{
Material_Default,
Material_NoLighting,
Material_SelfLit,
Material_SelfLitHighlight,
Material_AALine,
Material_Outline,
Material_Count
};
Adorn(): ignoreTexture(false), vr(false), currentMaterial(Material_Default) {}
Canvas getCanvas() const { return getViewport().wh(); }
bool isVR() const { return vr; }
virtual const Camera* getCamera() const = 0;
virtual ~Adorn() {}
virtual TextureProxyBaseRef createTextureProxy(const ContentId& id,
bool& waiting, bool bBlocking = false, const std::string& context = "") = 0;
// Listen to this signal if you need a hint about when to release your
// TextureProxys.
virtual rbx::signal<void()>& getUnbindResourcesSignal() = 0;
// Called to perform any preparations before the render pass begins.
virtual void prepareRenderPass() {}
// Called to perform any cleanup after every 2D/3D render pass.
virtual void finishRenderPass() {}
virtual void preSubmitPass() {}
virtual void postSubmitPass() {}
virtual bool useFontSmoothScalling() { return false; }
void setMaterial(Material material_)
{
currentMaterial = material_;
}
Material getMaterial() const { return currentMaterial; }
/////////////////////////////////////////////////
//
// Viewport
// Returns the Adorn's viewport area.
//
// Note that this viewport doesn't always represent the area where the
// game is being displayed.
virtual Rect2D getViewport() const = 0;
// Hack - buffering the GuiRect here - ultimately need to clip the
// "User Gui Space" with the ROBLOX Gui stuff.
void setUserGuiInset(const Vector4& value) { userGuiInset = value; }
Rect2D getUserGuiRect() const
{
Rect2D vp = getViewport();
return Rect2D::xyxy(vp.x0() + userGuiInset.x, vp.y0() + userGuiInset.y, vp.x1() - userGuiInset.z,
vp.y1() - userGuiInset.w);
}
/////////////////////////////////////////////////
//
// Textures, Draw Rectangles, Lines
void setIgnoreTexture(bool ignore) {ignoreTexture = ignore;}
bool getIgnoreTexture() const {return ignoreTexture;}
// Sets the texture used by the Adorn.
virtual void setTexture(
int id,
const RBX::TextureProxyBaseRef& texture) = 0;
// Gets the size of the texture being used by the Adorn.
virtual Rect2D getTextureSize(
const RBX::TextureProxyBaseRef& texture) const = 0;
// Draws a line on the screen.
virtual void line2d(
const Vector2& p0,
const Vector2& p1,
const Color4& color) = 0;
// Draws a hollow rectangle on the screen.
void outlineRect2d(const Rect2D& rect, float thick, const Color4& color);
void outlineRect2d(const Rect2D& rect, float thick, const Color4& color, const Rotation2D& rotation);
void outlineRect2d(const Rect2D& rect, float thick, const Color4& color, const Rect2D& clipRect);
// Draws a solid rectangle on the screen.
void rect2d(const Rect2D& rect, const Color4& color);
void rect2d(const Rect2D& rect, const Color4& color, const Rotation2D& rotation);
void rect2d(const Rect2D& rect, const Color4& color, const Rect2D& clipRect);
void rect2d(const Rect2D& rect, const Vector2& texul, const Vector2& texbr, const Color4& color);
void rect2d(const Rect2D& rect, const Vector2& texul, const Vector2& texbr, const Color4& color, const Rotation2D& rotation);
void rect2d(const Rect2D& rect, const Vector2& texul, const Vector2& texbr, const Color4& color, const Rect2D& clipRect);
// Rectangle drawing implementation
virtual void rect2dImpl(const Vector2& x0y0, const Vector2& x1y0, const Vector2& x0y1, const Vector2& x1y1, const Vector2& tex0, const Vector2& tex1, const Color4 & color) = 0;
/////////////////////////////////////////////////
//
// Draw Fonts
// Retrieves the boundaries (in pixels) of a string, if it were to be
// drawn on screen.
virtual Vector2 get2DStringBounds(
const std::string& s,
float size,
Text::Font font = Text::FONT_LEGACY,
const Vector2& availableSpace = Vector2::zero()) const = 0;
// Draws a string using this Adorn.
Vector2 drawFont2D(
const std::string& s,
const Vector2& position,
float size,
bool autoScale,
const Color4& color = Color3::black(),
const Color4& outline = Color4::clear(),
Text::Font font = Text::FONT_LEGACY,
Text::XAlign xalign = Text::XALIGN_LEFT,
Text::YAlign yalign = Text::YALIGN_TOP,
const Vector2& availableSpace = Vector2::zero(),
const Rect2D& clippingRect = RBX::Rect2D::xyxy(-1,-1,-1,-1),
const Rotation2D& rotation = Rotation2D());
virtual Vector2 drawFont2DImpl(
Adorn* target,
const std::string& s,
const Vector2& position,
float size,
bool autoScale,
const Color4& color,
const Color4& outline,
Text::Font font,
Text::XAlign xalign,
Text::YAlign yalign,
const Vector2& availableSpace,
const Rect2D& clippingRect,
const Rotation2D& rotation) = 0;
/////////////////////////////////////////////////
//
// 3D stuff - procedural
virtual void line3d(
const Vector3& startPoint,
const Vector3& endPoint,
const RBX::Color4& color) = 0;
virtual void line3dAA(
const Vector3& startPoint,
const Vector3& endPoint,
const RBX::Color4& color,
float thickness,
int zIndex,
bool alwaysOnTop) = 0;
// Sets the adorn's coordinate frame.
virtual void setObjectToWorldMatrix(
const CoordinateFrame& c) = 0;
// Draws an axis aligned bounding box on the adorn.
virtual void box(
const AABox& box,
const Color4& solidColor = Color4(1,.2f,.2f,.5f)) = 0;
// Draws a box on the adorn.
void box(
const Extents& extents,
const Color4& solidColor = Color4(1,.2f,.2f,.5f))
{
AABox aaBox(extents.min(), extents.max());
box(aaBox, solidColor);
}
virtual void box(
const CoordinateFrame& cFrame,
const Vector3& size,
const Color4& color,
int zIndex,
bool alwaysOnTop) = 0;
// Draws a sphere on the adorn.
virtual void sphere(
const Sphere& sphere,
const Color4& solidColor = Color4(1, 1, 0, .5f)) = 0;
virtual void sphere(
const CoordinateFrame& cFrame,
float radius,
const Color4& color,
int zIndex,
bool alwaysOnTop) = 0;
// Draws an explosion on the adorn.
virtual void explosion(const Sphere& sphere) = 0;
virtual void cylinder(
const CoordinateFrame& cFrame,
float radius,
float height,
const Color4& color,
int zIndex,
bool alwaysOnTop) = 0;
// Draws a cylinder along the adorn's x axis.
virtual void cylinderAlongX(
float radius,
float length,
const Color4& solidColor,
bool cap = true) = 0;
virtual void cone(
const CoordinateFrame& cFrame,
float radius,
float height,
const Color4& color,
int zIndex,
bool alwaysOnTop) = 0;
// Draws a ray from the adorn.
virtual void ray(
const RbxRay& ray,
const Color4& color = Color3::orange()) = 0;
// Draws the x, y, z axis of the adorn.
virtual void axes(
const Color4& xColor = Color3::red(),
const Color4& yColor = Color3::green(),
const Color4& zColor = Color3::blue(),
float scale = 1.0f) = 0;
// Draws a quad on the adorn.
//
// v0 The first point to form the quad.
// v1 The second point to form the quad.
// v2 The third point to form the quad.
// v3 The fourth point to form the quad.
// color The color used to draw the quad.
// v0tex UV coordinates used on the first polygon.
// v2tex UV coordinates used on the second polygon.
// opt The material options to use when drawing the quad.
virtual void quad(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
const Color4& color = Color3::blue(),
const Vector2& v0tex = Vector2::zero(),
const Vector2& v2tex = Vector2::zero(),
int zIndex = -1,
bool alwaysOnTop = false) = 0;
// Draws a convex 3D polygon on the adorn.
//
// v The set of points that compose the polygon.
// countv The number of points that compose the polygon.
// color The color used when drawing the polygon.
// opt The material options to use when drawing the polygon.
virtual void convexPolygon(
const Vector3* v,
int countv,
const Color4& color) = 0;
// Draws a convex 2D polygon on the adorn.
//
// v The set of points that compose the polygon.
// countv The number of points that compose the polygon.
// color The color used when drawing the polygon.
// opt The material options to use when drawing the polygon.
virtual void convexPolygon2d(
const Vector2* v,
int countv,
const Color4& color) = 0;
// Evaluates extrusion, calling trajectory and profile func with domain [0..1].
// if closeTrajectory or closeProfile is true, func is only evaluated to [0..1[,
// and evaluation for f(0) is used again for f(1).
// Future: if closeTrajectory != closeProfile, that could indicate we need
// caps at the end.
virtual void extrusion(RBX::I3DLinearFunc* trajectory, int trajectorysegments,
RBX::I3DLinearFunc* profile, int profilesegments,
const Color4& color, bool closeTrajectory = true,
bool closeProfile = true) = 0;
virtual bool isVisible(const Extents& extents, const CoordinateFrame& cframe) { return true; }
static const int maximumZIndex = 10;
protected:
Vector4 userGuiInset;
bool ignoreTexture;
bool vr;
Material currentMaterial;
};
} // namespace RBX
@@ -0,0 +1,186 @@
#pragma once
#include "GfxBase/Adorn.h"
namespace RBX {
class ViewportBillboarder;
class AdornBillboarder: public Adorn
{
Adorn* parent;
Rect2D viewport;
bool alwaysOnTop;
public:
AdornBillboarder(Adorn* parent, const ViewportBillboarder& viewportBillboarder);
AdornBillboarder(Adorn* parent, const Rect2D& viewport, const CoordinateFrame& transform, bool alwaysOnTop = false);
/*override*/ TextureProxyBaseRef createTextureProxy(const ContentId& id, bool& waiting, bool bBlocking = false, const std::string& context = "") { return parent->createTextureProxy(id, waiting, bBlocking, context); };
/*override*/ rbx::signal<void()>& getUnbindResourcesSignal() { return parent->getUnbindResourcesSignal(); }
/////////////////////////////////////////////////
//
// Viewport
/*override*/ Rect2D getViewport() const;
virtual const Camera* getCamera() const { return NULL; }
/////////////////////////////////////////////////
//
// Textures, Draw Rectangles, Lines
/*override*/ void setTexture(
int id,
const RBX::TextureProxyBaseRef& texture) { parent->setTexture(id, texture); };
/*override*/ Rect2D getTextureSize(
const RBX::TextureProxyBaseRef& texture) const { return parent->getTextureSize(texture); };
virtual bool useFontSmoothScalling() { return true; }
virtual void line2d(
const Vector2& p0,
const Vector2& p1,
const Color4& color);
virtual void rect2dImpl(
const Vector2& x0y0, const Vector2& x1y0, const Vector2& x0y1, const Vector2& x1y1,
const Vector2& tex0, const Vector2& tex1, const Color4 & color);
virtual Vector2 get2DStringBounds(
const std::string& s,
float size,
Text::Font font,
const Vector2& availableSpace) const
{
return parent->get2DStringBounds(s, size, font, availableSpace);
}
virtual Vector2 drawFont2DImpl(
Adorn* target,
const std::string& s,
const Vector2& position,
float size,
bool autoScale,
const Color4& color,
const Color4& outline,
Text::Font font,
Text::XAlign xalign,
Text::YAlign yalign,
const Vector2& availableSpace,
const Rect2D& clippingRect,
const Rotation2D& rotation)
{
return parent->drawFont2DImpl(target, s, position, size, autoScale, color, outline, font, xalign, yalign, availableSpace, clippingRect, rotation);
}
/////////////////////////////////////////////////
//
// 3D stuff - procedural
/*override*/ void setObjectToWorldMatrix(
const CoordinateFrame& c) { throw std::runtime_error("Invalid operation"); };
/*override*/ void box(
const AABox& box,
const Color4& solidColor = Color4(1,.2f,.2f,.5f)) { throw std::runtime_error("Invalid operation"); };
/*override*/ void box(
const CoordinateFrame& cFrame,
const Vector3& size,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void sphere(
const Sphere& sphere,
const Color4& solidColor = Color4(1, 1, 0, .5f)) { throw std::runtime_error("Invalid operation"); };
/*override*/ void sphere(
const CoordinateFrame& cFrame,
float radius,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void explosion(const Sphere& sphere)
{
throw std::runtime_error("Invalid operation");
};
/*override*/ void cylinder(
const CoordinateFrame& cFrame,
float radius,
float height,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void cylinderAlongX(
float radius,
float length,
const Color4& solidColor,
bool cap = true) { throw std::runtime_error("Invalid operation"); };
/*override*/ void cone(
const CoordinateFrame& cFrame,
float radius,
float height,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void ray(
const RbxRay& ray,
const Color4& color = Color3::orange()) { throw std::runtime_error("Invalid operation"); };
/*override*/ void line3d(
const Vector3& startPoint,
const Vector3& endPoint,
const RBX::Color4& color) { throw std::runtime_error("Invalid operation"); };
/*override*/ virtual void line3dAA(
const Vector3& startPoint,
const Vector3& endPoint,
const RBX::Color4& color,
float thickness,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void axes(
const Color4& xColor = Color3::red(),
const Color4& yColor = Color3::green(),
const Color4& zColor = Color3::blue(),
float scale = 1.0f) { throw std::runtime_error("Invalid operation"); };
/*override*/ void quad(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
const Color4& color = Color3::blue(),
const Vector2& v0tex = Vector2::zero(),
const Vector2& v2tex = Vector2::zero(),
int zIndex = -1,
bool alwaysOnTop = false)
{ throw std::runtime_error("Invalid operation"); };
/*override*/ void convexPolygon2d(
const Vector2* v,
int countv,
const Color4& color);
/*override*/ void convexPolygon(
const Vector3* v,
int countv,
const Color4& color) { throw std::runtime_error("Invalid operation"); };
// evaluates extrusion, calling trajectory and profile func with domain [0..1].
// if closeTrajectory or closeProfile is true, func is only evaluated to [0..1[, and evaluation for f(0) is used again for f(1).
// future: if closeTrajectory != closeProfile, that could indicate we need caps at the end.
/*override*/ void extrusion(I3DLinearFunc* trajectory, int trajectorysegments,
I3DLinearFunc* profile, int profilesegments,
const Color4& color, bool closeTrajectory = true, bool closeProfile = true) { throw std::runtime_error("Invalid operation"); };
};
};
@@ -0,0 +1,185 @@
#pragma once
#include "GfxBase/Adorn.h"
namespace RBX {
class AdornBillboarder2D : public Adorn
{
protected:
Adorn* parent;
Rect2D viewport;
Vector2 screenOffset;
public:
AdornBillboarder2D(Adorn* parent, const Rect2D& viewport, const Vector2& screenOffset);
/*override*/ TextureProxyBaseRef createTextureProxy(const ContentId& id, bool& waiting, bool bBlocking = false, const std::string& context = "") { return parent->createTextureProxy(id, waiting, bBlocking, context); };
/*override*/ rbx::signal<void()>& getUnbindResourcesSignal() { return parent->getUnbindResourcesSignal(); }
/////////////////////////////////////////////////
//
// Viewport
/*override*/ Rect2D getViewport() const;
virtual const Camera* getCamera() const { return NULL; }
/////////////////////////////////////////////////
//
// Textures, Draw Rectangles, Lines
/*override*/ void setTexture(
int id,
const RBX::TextureProxyBaseRef& texture) { parent->setTexture(id, texture); };
/*override*/ Rect2D getTextureSize(
const RBX::TextureProxyBaseRef& texture) const { return parent->getTextureSize(texture); };
virtual bool useFontSmoothScalling() { return true; }
virtual void line2d(
const Vector2& p0,
const Vector2& p1,
const Color4& color);
virtual void rect2dImpl(
const Vector2& x0y0, const Vector2& x1y0, const Vector2& x0y1, const Vector2& x1y1,
const Vector2& tex0, const Vector2& tex1, const Color4 & color);
virtual Vector2 get2DStringBounds(
const std::string& s,
float size,
Text::Font font,
const Vector2& availableSpace) const
{
return parent->get2DStringBounds(s, size, font, availableSpace);
}
virtual Vector2 drawFont2DImpl(
Adorn* target,
const std::string& s,
const Vector2& position,
float size,
bool autoScale,
const Color4& color,
const Color4& outline,
Text::Font font,
Text::XAlign xalign,
Text::YAlign yalign,
const Vector2& availableSpace,
const Rect2D& clippingRect,
const Rotation2D& rotation)
{
return parent->drawFont2DImpl(target, s, position, size, autoScale, color, outline, font, xalign, yalign, availableSpace, clippingRect, rotation);
}
/////////////////////////////////////////////////
//
// 3D stuff - procedural
/*override*/ void setObjectToWorldMatrix(
const CoordinateFrame& c) { throw std::runtime_error("Invalid operation"); };
/*override*/ void box(
const AABox& box,
const Color4& solidColor = Color4(1,.2f,.2f,.5f)) { throw std::runtime_error("Invalid operation"); };
/*override*/ void box(
const CoordinateFrame& cFrame,
const Vector3& size,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void sphere(
const Sphere& sphere,
const Color4& solidColor = Color4(1, 1, 0, .5f)) { throw std::runtime_error("Invalid operation"); };
/*override*/ void sphere(
const CoordinateFrame& cFrame,
float radius,
const Color4& color,
int zIndex,
bool drawFront) { throw std::runtime_error("Invalid ooperation"); };
/*override*/ void explosion(const Sphere& sphere)
{
throw std::runtime_error("Invalid operation");
};
/*override*/ void cylinder(
const CoordinateFrame& cFrame,
float radius,
float height,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void cylinderAlongX(
float radius,
float length,
const Color4& solidColor,
bool cap = true) { throw std::runtime_error("Invalid operation"); };
/*override*/ void cone(
const CoordinateFrame& cFrame,
float radius,
float height,
const Color4& color,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void ray(
const RbxRay& ray,
const Color4& color = Color3::orange()) { throw std::runtime_error("Invalid operation"); };
/*override*/ void line3d(
const Vector3& startPoint,
const Vector3& endPoint,
const RBX::Color4& color) { throw std::runtime_error("Invalid operation"); };
/*override*/ virtual void line3dAA(
const Vector3& startPoint,
const Vector3& endPoint,
const RBX::Color4& color,
float thickness,
int zIndex,
bool alwaysOnTop) { throw std::runtime_error("Invalid operation"); };
/*override*/ void axes(
const Color4& xColor = Color3::red(),
const Color4& yColor = Color3::green(),
const Color4& zColor = Color3::blue(),
float scale = 1.0f) { throw std::runtime_error("Invalid operation"); };
/*override*/ void quad(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
const Color4& color = Color3::blue(),
const Vector2& v0tex = Vector2::zero(),
const Vector2& v2tex = Vector2::zero(),
int zIndex = -1,
bool alwaysOnTop = false)
{ throw std::runtime_error("Invalid operation"); };
/*override*/ void convexPolygon2d(
const Vector2* v,
int countv,
const Color4& color) { throw std::runtime_error("Invalid operation"); }
/*override*/ void convexPolygon(
const Vector3* v,
int countv,
const Color4& color) { throw std::runtime_error("Invalid operation"); };
// evaluates extrusion, calling trajectory and profile func with domain [0..1].
// if closeTrajectory or closeProfile is true, func is only evaluated to [0..1[, and evaluation for f(0) is used again for f(1).
// future: if closeTrajectory != closeProfile, that could indicate we need caps at the end.
/*override*/ void extrusion(I3DLinearFunc* trajectory, int trajectorysegments,
I3DLinearFunc* profile, int profilesegments,
const Color4& color, bool closeTrajectory = true, bool closeProfile = true) { throw std::runtime_error("Invalid operation"); };
};
};
@@ -0,0 +1,56 @@
#pragma once
#include "GfxBase/Adorn.h"
#include "V8DataModel/Workspace.h"
#include "util/UDim.h"
namespace RBX {
class AdornSurface : public Adorn
{
Adorn* parent;
Rect2D viewport;
bool alwaysOnTop;
public:
AdornSurface(Adorn* parent, const Rect2D& viewport, const CoordinateFrame& transform, bool alwaysOnTop = false);
virtual bool useFontSmoothScalling() { return false; }
void setTexture(int id, const RBX::TextureProxyBaseRef& texture);
Rect2D getTextureSize( const RBX::TextureProxyBaseRef& texture) const;
void line2d(const Vector2& p0, const Vector2& p1, const Color4& color);
virtual void rect2dImpl(const Vector2& x0y0, const Vector2& x1y0, const Vector2& x0y1, const Vector2& x1y1, const Vector2& tex0, const Vector2& tex1, const Color4 & color);
Vector2 get2DStringBounds(const std::string& s, float size, Text::Font font, const Vector2& availableSpace ) const;
Vector2 drawFont2DImpl(Adorn* target, const std::string& s, const Vector2& pos2D, float size, bool autoScale, const Color4& color, const Color4& outline, Text::Font font, Text::XAlign xalign, Text::YAlign yalign, const Vector2& availableSpace, const Rect2D& clippingRect, const Rotation2D& rotation );
const Camera* getCamera() const { return 0; }
TextureProxyBaseRef createTextureProxy(const ContentId& id, bool& waiting, bool bBlocking, const std::string& context = "") { return parent->createTextureProxy(id,waiting,bBlocking,context); }
rbx::signal<void()>& getUnbindResourcesSignal() { return parent->getUnbindResourcesSignal(); }
Rect2D getViewport() const;
void setObjectToWorldMatrix(const CoordinateFrame& c) { ; }
void line3d(const Vector3& startPoint, const Vector3& endPoint, const RBX::Color4& color) { ; }
void line3dAA(const Vector3& startPoint, const Vector3& endPoint, const RBX::Color4& color, float thickness, int zIndex, bool alwaysOnTop) { ; }
void box(const AABox& b, const Color4& solidColor) { ; }
void box(const CoordinateFrame& cFrame, const Vector3& size, const Color4& color, int zIndex, bool alwaysOnTop) { ; }
void sphere(const Sphere& s, const Color4& solidColor) { ; }
void sphere(const CoordinateFrame& cFrame, float radius, const Color4& color, int zIndex, bool alwaysOnTop) { ; }
void explosion(const Sphere& sphere) { ; }
void cylinder(const CoordinateFrame& cFrame, float radius, float height, const Color4& color, int zIndex, bool alwaysOnTop) { ; }
void cylinderAlongX(float radius, float length, const Color4& solidColor, bool cap) { ; }
void cone(const CoordinateFrame& cFrame, float radius, float height, const Color4& color, int zIndex, bool alwaysOnTop) { ; }
void ray(const RbxRay& ray, const Color4& color) { ; }
void axes(const Color4&, const Color4&, const Color4&, float) { ; }
void quad(const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Color4&, const Vector2&, const Vector2&, int zIndex, bool alwaysOnTop) { ; }
void convexPolygon(const Vector3*, int, const Color4&) { ; }
void convexPolygon2d(const Vector2*, int, const Color4&) { ; }
void extrusion(RBX::I3DLinearFunc*, int, RBX::I3DLinearFunc*, int, const Color4&, bool, bool) { ; }
};
}
@@ -0,0 +1,46 @@
#pragma once
#include "v8datamodel/contentprovider.h"
namespace RBX {
class AsyncResult
{
public:
AsyncResult()
: reqResult(RBX::AsyncHttpQueue::Succeeded)
{
};
// make result always more restrictive only.
// Succeeded < Waiting < Failed.
void returnResult(RBX::AsyncHttpQueue::RequestResult reqResult)
{
switch(reqResult)
{
case RBX::AsyncHttpQueue::Succeeded:
break;
case RBX::AsyncHttpQueue::Waiting:
if(this->reqResult == RBX::AsyncHttpQueue::Succeeded)
{
this->reqResult = reqResult;
}
break;
case RBX::AsyncHttpQueue::Failed:
this->reqResult = reqResult;
break;
}
}
void returnWaitingFor(const RBX::ContentId& id)
{
returnResult(RBX::AsyncHttpQueue::Waiting);
waitingFor.push_back(id);
}
RBX::AsyncHttpQueue::RequestResult reqResult;
std::vector<RBX::ContentId> waitingFor;
};
}
@@ -0,0 +1,24 @@
#pragma once
#include "MeshFileStructs.h"
#include "util/Object.h"
#include "util/G3DCore.h"
#include <vector>
namespace RBX
{
struct FileMeshData
{
std::vector<FileMeshVertexNormalTexture3d> vnts;
std::vector<FileMeshFace> faces;
AABox aabb;
};
shared_ptr<FileMeshData> ReadFileMesh(const std::string& data);
// writes the newest version always.
// remember: set ostream to binary!
void WriteFileMesh(std::ostream& f, const FileMeshData& mesh);
}
@@ -0,0 +1,201 @@
#pragma once
#include <vector>
#pragma warning (push)
#pragma warning( disable:4996 ) // disable -D_SCL_SECURE_NO_WARNING in ublas.
#include <boost/numeric/ublas/vector.hpp>
#pragma warning (pop)
#include "GfxBase/RenderSettings.h"
#include "rbx/RunningAverage.h"
#include <map>
namespace RBX {
class RenderCaps;
class Log;
enum SSAOLevel
{
ssaoNone = 0,
ssaoFullBlank,
ssaoFull
};
struct THROTTLE_LOCKSTEP;
class FrameRateManager
{
public:
FrameRateManager(void);
~FrameRateManager(void);
void configureFrameRateManager(CRenderSettings::FrameRateManagerMode mode, bool hasCharacter);
void setAggressivePerformance(bool value);
struct Metrics
{
bool AutoQuality;
int QualityLevel;
int NumberOfSettles;
double AverageSwitchesPerSettle;
double AverageFps;
};
// add to current frame counter.
void AddBlockQuota(int blocksInCluster, float sqDistanceToCamera, bool isInSpatialHash);
bool getGBufferSetting();
SSAOLevel getSSAOLevel();
bool isSSAOSupported() { return mSSAOSupported; }
float getShadingDistance() const;
float getShadingSqDistance() const;
int getTextureAnisotropy() const;
int getPhysicsThrottling() const;
float getLightGridRadius() const;
bool getLightingNonFixedEnabled() const;
unsigned getLightingChunkBudget() const;
void SubmitCurrentFrame(double frameTime, double renderTime, double prepareTime, double bonusTime);
// adjusts quality to try to fit rendering to this timespan.
void ThrottleTo(double rendertime_ms);
double getMetricValue(const std::string& metric);
int GetRecomputeDistanceDelay() { return mRecomputeDistanceDelay; }
float GetViewCullSqDistance();
float GetRenderCullSqDistance();
double GetMaxNextViewCullDistance(); // farthest cull distance possible in next frame.
int GetQualityLevel() { return mCurrentQualityLevel; }
bool IsBlockCullingEnabled() { return mBlockCullingEnabled; };
void SetBlockCullingEnabled(bool enabled) { mBlockCullingEnabled = enabled; };
// supply the framerate manager with some special information that can be
// used to formulate exceptions.
void Configure(const RenderCaps* renderCaps, CRenderSettings* settings);
// after calling Configure, this gives our determination of the best
// possible quality we can acheive with certain features, and with current settings
CRenderSettings::AntialiasingMode getAntialiasingMode();
void updateMaxSettings();
double GetVisibleBlockTarget() const { return mBlockTarget; }; // smoothed block target
double GetVisibleBlockCounter() const { return mLastBlockCounter; };
float GetTargetFrameTimeForNextLevel() const;
float GetTargetRenderTimeForNextLevel() const;
// counter that indicates how many frames have elapsed with the block count in a stable state.
void ResetStableFramesCounter() { mStableFramesCounter = 0; };
const int& GetStableFramesCounter() { return mStableFramesCounter; };
// returns overall particle throttle factor. Range ]0 .. 1] , 1 for full detail.
double GetParticleThrottleFactor();
double GetRenderTimeAverage();
double GetPrepareTimeAverage();
double GetFrameTimeAverage();
const WindowAverage<double,double>& GetRenderTimeStats();
const WindowAverage<double,double>& GetFrameTimeStats();
void StartCapturingMetrics();
Metrics GetMetrics();
void PauseAutoAdjustment();
void ResumeAutoAdjustment();
int GetQualityDelayUp() const { return mQualityDelayUp; }
int GetQualityDelayDown() const { return mQualityDelayDown; }
int GetBackoffCounter() const { return mBadBackoffFrameCounter; }
double GetBackoffAverage() const { return fastBackoffAverage.getStats().average; }
protected:
bool mSSAOSupported;
bool mAdjustmentOn;
CRenderSettings* mSettings;
const RenderCaps* mRenderCaps;
bool mBlockCullingEnabled;
bool mAggressivePerformance;
int mStableFramesCounter;
bool mThrottlingOn;
int mCurrentQualityLevel;
unsigned mQualityCount[CRenderSettings::QualityLevelMax];
int mQualityDelayUp;
int mQualityDelayDown;
int mRecomputeDistanceDelay;
bool mWasQualityUp;
int mSwitchCounter;
private:
float mSqDistance;
float mSqRenderDistance;
void UpdateStats(double frameTime, double renderTime, double prepareTime);
void AdjustQuality(double frameTime, double renderTime, bool adjustmentOn, double bonusTime);
void StepQuality(bool direction, bool isBackOff);
void UpdateQualitySettings();
void SendQualityLevelStats();
float GetAvarageQuality();
float GetTargetFrameTime(int level) const;
RBX::WindowAverage<double, double> frameTimeAverage;
RBX::WindowAverage<double, double> renderTimeAverage;
RBX::WindowAverage<double, double> prepareTimeAverage;
RBX::WindowAverage<double, double> frameTimeVarianceAverage;
RBX::WindowAverage<double, double> fastBackoffAverage;
int mBadBackoffFrameCounter;
Metrics mMetrics;
RBX::Timer<RBX::Time::Fast> mSettleTimer;
bool mIsStable;
bool mIsGatheringDistance;
int mBlockCounter;
int mBlockTarget;
int mLastBlockCounter;
class AvgFpsCounter
{
public:
AvgFpsCounter(): timeSumSec(0), frameCnt(0) {}
void Update(double deltaTimeMs)
{
if (deltaTimeMs < 1000)
{
timeSumSec += deltaTimeMs * 0.001;
++frameCnt;
}
}
double GetFPS() { return frameCnt ? 1.0 / (timeSumSec / frameCnt) : 0 ; }
private:
double timeSumSec;
unsigned frameCnt;
};
AvgFpsCounter mFPSCounter;
THROTTLE_LOCKSTEP* LockstepTable;
};
} // namespaces
+121
View File
@@ -0,0 +1,121 @@
#pragma once
#include "boost/shared_ptr.hpp"
#include "Util/SpatialRegion.h"
#include "V8Tree/Instance.h"
#include "v8world/BasicSpatialHashPrimitive.h"
#include "rbx/signal.h"
#include "reflection/Property.h"
namespace RBX {
class PartInstance;
class AsyncResult;
class GfxBinding
{
protected:
GfxBinding(const boost::shared_ptr<RBX::PartInstance>& part)
: partInstance(part)
{}
GfxBinding()
{}
virtual ~GfxBinding();
public:
RBX::PartInstance* getPartInstance() { return partInstance.get(); };
// unlinks from PartInstance.
// will cause delete on next updateEntity();
void zombify();
bool isBound();
// helper method. probably should be elsewhere.
static bool isInWorkspace(RBX::Instance* part);
virtual void invalidateEntity() {};
virtual void updateEntity(bool assetsUpdated = false) {};
virtual void updateChunk(const SpatialRegion::Id& pos, bool isWaterChunk) {};
virtual void onCoordinateFrameChanged() {};
virtual void onSizeChanged() { invalidateEntity(); };
virtual void onTransparencyChanged() { invalidateEntity(); };
virtual void onSpecialShapeChanged() { invalidateEntity(); }
// disconnects all event listeners.
virtual void unbind();
void cleanupStaleConnections();
// meant to connect all listeners relevant to this instance.
// basic implementation doesn't listen to much. overide and bind some more.
// virtual void bind();
// helper: connects property change event listeners.
void bindProperties(const shared_ptr<RBX::PartInstance>& part);
protected:
boost::shared_ptr<RBX::PartInstance> partInstance;
std::vector<rbx::signals::connection> connections;
private:
void onPropertyChanged(const RBX::Reflection::PropertyDescriptor* descriptor);
void onAncestorChanged(const shared_ptr<RBX::Instance>& ancestor);
void onChildAdded(const shared_ptr<RBX::Instance>& child);
void onChildRemoved(const shared_ptr<RBX::Instance>& child);
void onSpecialShapeChangedEx();
void onCombinedSignal(Instance::CombinedSignalType type, const Instance::ICombinedSignalData* data);
void onHumanoidChanged();
void onOutfitChanged();
void onDecalPropertyChanged(const RBX::Reflection::PropertyDescriptor* descriptor);
void onTexturePropertyChanged(const RBX::Reflection::PropertyDescriptor* descriptor);
};
// class used as a simple base class for linking PartInstances with graphics objects.
class GfxPart : public GfxBinding, public RBX::BasicSpatialHashPrimitive
{
public:
GfxPart(const boost::shared_ptr<RBX::PartInstance>& part)
: GfxBinding(part)
, lastFrustumVisibleFrameNumber(-1)
{}
GfxPart()
: lastFrustumVisibleFrameNumber(-1)
{}
// accessors?
int lastFrustumVisibleFrameNumber; // most recent frame where this object was within the view frustum
public:
virtual void updateCoordinateFrame(bool recalcLocalBounds = false) {};
virtual unsigned int getPartCount() { return 1; }
virtual void onSleepingChanged(bool sleeping, PartInstance* part) {};
virtual void onClumpChanged(PartInstance* part) {};
virtual Vector3 getCenter() const { return Vector3(); }
};
// serves to allow the gfx engine to have persistent gfxobject tracking the position of a part.
class GfxAttachment : public GfxBinding
{
public:
GfxAttachment(const boost::shared_ptr<RBX::PartInstance>& part)
: GfxBinding(part)
{}
protected:
GfxAttachment()
{}
public:
/*override*/ void unbind();
protected:
virtual void onSleepingChanged(bool sleeping) = 0;
public:
virtual void updateCoordinateFrame(bool recalcLocalBounds = false) = 0;
};
}
@@ -0,0 +1,71 @@
/* Copyright 2003-2005 ROBLOX Corporation, All Rights Reserved */
#pragma once
#include "Util/IndexArray.h"
#include "Util/Selectable.h"
#include "V8Tree/Instance.h"
#include "SelectState.h"
namespace RBX {
class IAdornableCollector;
class Adorn;
class Camera;
class RBXInterface IAdornable
: public Selectable
{
friend class IAdornableCollector;
private:
int index2d;
int index3d;
int index3dSorted;
int& indexFunc2d() {return index2d;}
int& indexFunc3d() {return index3d;}
int& indexFunc3dSorted() {return index3dSorted;}
IAdornableCollector* bucket;
protected:
virtual bool shouldRender2d() const {return false;}
virtual bool shouldRender3dAdorn() const {return false;}
virtual bool shouldRender3dSortedAdorn() const {return false;}
public:
IAdornable() : bucket(NULL), index2d(-1), index3d(-1), index3dSorted(-1)
{}
~IAdornable();
void shouldRenderSetDirty(); // sets this IAdornable dirty
float calculateDepth(const Camera* camera) const; // calculates the depth based on camera
virtual bool isVisible(const Rect2D& rect) const { return true; }
virtual void renderBackground2d(Adorn* adorn) {}
virtual void renderBackground2dContext(Adorn* adorn, const Instance* context) { renderBackground2d(adorn); }
virtual void render2d(Adorn* adorn) {}
virtual void render2dContext(Adorn* adorn, const Instance* context) { render2d(adorn); }
virtual void render3dAdorn(Adorn* adorn) {}
virtual void render3dSortedAdorn(Adorn* adorn) {}
virtual void render3dSelect(Adorn* adorn, SelectState selectState) {}
virtual Vector3 render3dSortedPosition() const { return Vector3(0,0,0); }
};
struct AdornableDepth
{
IAdornable* adornable;
float depth;
bool operator<(const AdornableDepth& o) const
{
return depth > o.depth;
}
};
} // namespace
@@ -0,0 +1,37 @@
/* Copyright 2003-2005 ROBLOX Corporation, All Rights Reserved */
#pragma once
#include "GfxBase/IAdornable.h"
#include "Util/IndexArray.h"
LOGGROUP(AdornRenderStats);
namespace RBX {
class Adorn;
class RBXInterface IAdornableCollector
{
friend class IAdornable;
private:
IndexArray<IAdornable, &IAdornable::indexFunc2d> renderable2ds;
IndexArray<IAdornable, &IAdornable::indexFunc3d> renderable3ds;
IndexArray<IAdornable, &IAdornable::indexFunc3dSorted> renderable3dSorteds;
public:
void onRenderableDescendantAdded(IAdornable* iR);
void onRenderableDescendantRemoving(IAdornable* iR);
void recomputeShouldRender(IAdornable* iR);
public:
IAdornableCollector()
{}
~IAdornableCollector();
void render2dItems(Adorn* adorn);
void render3dAdornItems(Adorn* adorn);
void append3dSortedAdornItems(std::vector<AdornableDepth>& destination, const Camera* camera) const;
};
} // namespace RBX
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include <stddef.h>
namespace RBX {
class Image
{
public:
virtual ~Image() {}
virtual size_t getSize() const = 0;
virtual int getOriginalWidth() const = 0;
virtual int getOriginalHeight() const = 0;
};
}
@@ -0,0 +1,36 @@
#pragma once
namespace RBX {
#pragma pack( push, 1)
// nb: keep backward/forward compatibility by only appending to these structs.
// stride information will keep this working.
struct FileMeshHeader
{
unsigned short cbSize;
unsigned char cbVerticesStride;
unsigned char cbFaceStride;
// ---dword boundary-----
unsigned int num_vertices;
unsigned int num_faces;
};
struct FileMeshVertexNormalTexture3d
{
float vx,vy,vz;
float nx,ny,nz;
float tu,tv,tw;
};
struct FileMeshFace
{
unsigned int a;
unsigned int b;
unsigned int c;
};
#pragma pack( pop )
}
@@ -0,0 +1,19 @@
#pragma once
#include "util/G3DCore.h"
namespace RBX {
class I3DLinearFunc
{
public:
virtual Vector3 eval(float t)=0;
// first derivative.
virtual Vector3 evalTangent(float t)=0; // (tangent, normal, binormal, in that order, should form a right handed space)
virtual Vector3 evalNormal(float t)=0;
virtual Vector3 evalBinormal(float t)=0;
//string that encodes this function in a unique way.
virtual std::string hashString()=0;
};
}
+67
View File
@@ -0,0 +1,67 @@
/* Copyright 2003-2005 ROBLOX Corporation, All Rights Reserved */
#pragma once
#include "Util/SurfaceType.h"
#include "Util/Vector6.h"
#include "G3D/Vector3.h"
#include "G3D/Color4.h"
#include "G3D/CoordinateFrame.h"
// Simple description of a part suitable for drawing, etc. Build Instance on top of this.
// Low level.
namespace RBX {
enum PartType { BALL_PART = 0,
BLOCK_PART,
CYLINDER_PART,
TRUSS_PART,
WEDGE_PART,
PRISM_PART,
PYRAMID_PART,
PARALLELRAMP_PART,
RIGHTANGLERAMP_PART,
CORNERWEDGE_PART,
MEGACLUSTER_PART,
OPERATION_PART };
class Part {
public:
// alpha order for simplification on dialogs
PartType type; // hash code hashes this block of data
G3D::Vector3 gridSize;
G3D::Color4 color;
Vector6<SurfaceType> surfaceType;
G3D::CoordinateFrame coordinateFrame;
Part() {}
Part(PartType _type,
const G3D::Vector3& _gridSize,
const G3D::Color4 _color,
const G3D::CoordinateFrame& c) :
type(_type),
gridSize(_gridSize),
color(_color),
surfaceType(NO_SURFACE),
coordinateFrame(c)
{}
Part(PartType type,
const G3D::Vector3& gridSize,
const G3D::Color4 color,
const Vector6<SurfaceType>& surfaceType,
const G3D::CoordinateFrame& c) :
type(type),
gridSize(gridSize),
color(color),
surfaceType(surfaceType),
coordinateFrame(c)
{}
};
} // namespace
@@ -0,0 +1,61 @@
#pragma once
#include "Util/TextureId.h"
#include "Util/G3DCore.h"
namespace RBX
{
class PartInstance;
class Humanoid;
class CharacterMesh;
class Accoutrement;
// if the part is a humanoid, get further details with this.
class HumanoidIdentifier
{
public:
explicit HumanoidIdentifier(RBX::Humanoid* humanoid);
Humanoid* humanoid;
PartInstance* head;
PartInstance* leftLeg;
PartInstance* rightLeg;
PartInstance* leftArm;
PartInstance* rightArm;
PartInstance* torso;
std::vector<Accoutrement*> accoutrements;
TextureId pants;
TextureId shirt;
TextureId shirtGraphic;
CharacterMesh* leftLegMesh;
CharacterMesh* rightLegMesh;
CharacterMesh* leftArmMesh;
CharacterMesh* rightArmMesh;
CharacterMesh* torsoMesh;
bool isBodyPart(RBX::PartInstance* part) const;
bool isBodyPartComposited(RBX::PartInstance* part) const;
bool isPartComposited(RBX::PartInstance* part) const;
bool isPartHead(RBX::PartInstance* part) const;
// helper
CharacterMesh* getRelevantMesh(RBX::PartInstance* bodyPart) const;
enum BodyPartType
{
PartType_Head,
PartType_Torso,
PartType_Arm,
PartType_Leg,
PartType_Unknown,
PartType_Count
};
BodyPartType getBodyPartType(RBX::PartInstance* bodyPart) const;
Vector3 getBodyPartScale(RBX::PartInstance* bodyPart) const;
};
}
@@ -0,0 +1,32 @@
#pragma once
#include <string>
#include "GfxBase/RenderSettings.h"
namespace RBX {
class RenderCaps
{
size_t vidMemSize;
std::string gfxCardName;
bool texturePowerOf2Only;
bool supportsGBuffer;
unsigned int skinningBoneCount;
public:
RenderCaps(std::string gfxCardName, size_t vidMemSize );
void setTexturePowerOf2Only(bool b) { texturePowerOf2Only = b; }
void setSupportsGBuffer(bool b) { supportsGBuffer = b; }
void setSkinningBoneCount(unsigned int v) { skinningBoneCount = v; }
size_t getVidMemSize() const { return vidMemSize; }
bool getTexturePowerOf2Only() const { return texturePowerOf2Only; }
const std::string& getGfxCardName() const { return gfxCardName; }
bool getSupportsGBuffer() const { return supportsGBuffer; }
unsigned int getSkinningBoneCount() const { return skinningBoneCount; }
};
}
@@ -0,0 +1,200 @@
#pragma once
#include <vector>
#include "util/G3DCore.h"
namespace RBX {
class CRenderSettings
{
public:
enum AASamples
{
NONE = 1,
AA4 = 4,
AA8 = 8,
};
static const AASamples defaultAASamples = NONE;
static const G3D::Vector2int16 defaultWindowSize;
static const G3D::Vector2int16 defaultFullscreenSize();
static const G3D::Vector2int16 minGameWindowSize;
typedef enum
{
UnknownGraphicsMode = 0,
AutoGraphicsMode = 1,
Direct3D11 = 2,
Direct3D9 = 3,
OpenGL,
NoGraphics
} GraphicsMode;
static GraphicsMode latchedGraphicsMode;
typedef enum
{
AntialiasingAuto = 0,
AntialiasingOn = 1,
AntialiasingOff = 2
} AntialiasingMode;
typedef enum
{
FrameRateManagerAuto = 0,
FrameRateManagerOn = 1,
FrameRateManagerOff = 2
} FrameRateManagerMode;
typedef enum
{
QualityAuto = 0,
QualityLevel1,
QualityLevel2,
QualityLevel3,
QualityLevel4,
QualityLevel5,
QualityLevel6,
QualityLevel7,
QualityLevel8,
QualityLevel9,
QualityLevel10,
QualityLevel11,
QualityLevel12,
QualityLevel13,
QualityLevel14,
QualityLevel15,
QualityLevel16,
QualityLevel17,
QualityLevel18,
QualityLevel19,
QualityLevel20,
QualityLevel21,
QualityLevelMax
} QualityLevel;
typedef enum
{
ResolutionAuto,
Resolution720x526,
Resolution800x600,
Resolution1024x600,
Resolution1024x768,
Resolution1280x720,
Resolution1280x768,
Resolution1152x864,
Resolution1280x800,
Resolution1360x768,
Resolution1280x960,
Resolution1280x1024,
Resolution1440x900,
Resolution1600x900,
Resolution1600x1024,
Resolution1600x1200,
Resolution1680x1050,
Resolution1920x1080,
Resolution1920x1200,
ResolutionMaxIndex
} ResolutionPreset;
struct RESOLUTIONENTRY
{
CRenderSettings::ResolutionPreset preset;
int width;
int height;
};
protected:
GraphicsMode graphicsMode;
AntialiasingMode antialiasingMode;
FrameRateManagerMode frameRateManagerMode;
QualityLevel qualityLevel;
QualityLevel editQualityLevel;
ResolutionPreset resolutionPreference;
int autoQualityLevel;
int maxQualityLevel;
int minCullDistance;
bool debugShowBoundingBoxes;
bool debugReloadAssets;
bool enableFRM;
bool objExportMergeByMaterial;
static AASamples aaSamples;
// filtered setting to use by app.
G3D::Vector2int16 fullscreenSize;
G3D::Vector2int16 windowSize;
bool showAggregation;
bool drawConnectors;
bool eagerBulkExecution;
// KB
unsigned int textureCacheSize;
unsigned int meshCacheSize;
public:
CRenderSettings();
bool getShowAggregation() const { return showAggregation; }
static AASamples getAASamplesSafe() { return aaSamples; } // Thread-safe
GraphicsMode getGraphicsMode() const { return graphicsMode; }
void setGraphicsMode(GraphicsMode value);
GraphicsMode getLatchedGraphicsMode()
{
if (latchedGraphicsMode == UnknownGraphicsMode)
latchedGraphicsMode = getGraphicsMode();
return latchedGraphicsMode;
}
AASamples getAASamples() const { return aaSamples; }
G3D::Vector2int16 getFullscreenSize() const { return fullscreenSize; }
G3D::Vector2int16 getWindowSize() const { return windowSize; }
FrameRateManagerMode getFrameRateManagerMode() const { return frameRateManagerMode; }
AntialiasingMode getAntialiasingMode() const { return antialiasingMode; }
QualityLevel getQualityLevel() const { return qualityLevel; }
QualityLevel getEditQualityLevel() const { return editQualityLevel; }
int getMaxQualityLevel() { return maxQualityLevel; }
int getAutoQualityLevel() const { return autoQualityLevel; }
ResolutionPreset getResolutionPreference() const { return resolutionPreference; }
const RESOLUTIONENTRY& getResolutionPreset(ResolutionPreset preset) const;
// FRM would like to report latest setting. Subclass is free to ignore it
virtual void setAutoQualityLevel(int level) {}
float getMaxFrameRate() const { return 60.0f; }
float getMinFrameRate() const { return 30.0f; }
bool getDrawConnectors() const { return drawConnectors; }
void setDrawConnectors(bool value) { drawConnectors = value; }
int getMinCullDistance() const { return minCullDistance; }
bool getDebugShowBoundingBoxes() const { return debugShowBoundingBoxes; }
bool getDebugReloadAssets() const { return debugReloadAssets; }
bool getObjExportMergeByMaterial() const { return objExportMergeByMaterial; }
bool getEnableFRM() const { return enableFRM; }
bool getEagerBulkExecution() const { return eagerBulkExecution; }
unsigned int getTextureCacheSize() const { return textureCacheSize; }
unsigned int getMeshCacheSize() const { return meshCacheSize; }
};
} // namespace RBX
@@ -0,0 +1,101 @@
/* Copyright 2003-2006 ROBLOX Corporation, All Rights Reserved */
#pragma once
#include "boost/scoped_ptr.hpp"
#include "util/Profiling.h"
namespace RBX {
namespace Profiling
{
class CodeProfiler;
}
struct RenderPassStats
{
unsigned int batches;
unsigned int faces;
unsigned int vertices;
unsigned int stateChanges;
unsigned int passChanges;
RenderPassStats()
: batches(0)
, faces(0)
, vertices(0)
, stateChanges(0)
, passChanges(0)
{
}
RenderPassStats& operator+=(const RenderPassStats& other)
{
batches += other.batches;
faces += other.faces;
vertices += other.vertices;
stateChanges += other.stateChanges;
passChanges += other.passChanges;
return *this;
}
RenderPassStats operator+(const RenderPassStats& other) const
{
RenderPassStats result = *this;
result += other;
return result;
}
};
struct ClusterStats
{
unsigned int clusters;
unsigned int parts;
ClusterStats()
: clusters(0)
, parts(0)
{
}
};
class RenderStats {
public:
boost::scoped_ptr<RBX::Profiling::CodeProfiler> cpuRenderTotal;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> culling;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> flip;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> renderObjects;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> updateLighting;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> adorn2D;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> adorn3D;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> visualEngineSceneUpdater;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> finishRendering;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> renderTargetUpdate;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> frameRateManager;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> textureCompositor;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> updateSceneGraph;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> updateAllInvalidParts;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> updateDynamicsAndAggregateStatics;
boost::scoped_ptr<RBX::Profiling::CodeProfiler> updateDynamicParts;
RenderPassStats passTotal;
RenderPassStats passScene;
RenderPassStats passShadow;
RenderPassStats passUI;
RenderPassStats pass3DAdorns;
ClusterStats clusterFast;
ClusterStats clusterFastFW;
ClusterStats clusterFastHumanoid;
ClusterStats lastFrameFast;
unsigned lastFrameMegaClusterChunks;
RenderStats();
~RenderStats();
};
}
@@ -0,0 +1,28 @@
#pragma once
#include <boost/shared_ptr.hpp>
#include "boost/enable_shared_from_this.hpp"
#include "g3d/Vector2.h"
#include <string>
namespace RBX {
typedef boost::shared_ptr<class TextureProxyBase> TextureProxyBaseRef;
class TextureProxyBase : public boost::enable_shared_from_this<TextureProxyBase>
{
private:
typedef boost::enable_shared_from_this<TextureProxyBase> Super;
public:
TextureProxyBase() {}
virtual ~TextureProxyBase() {}
virtual G3D::Vector2 getOriginalSize() = 0;
static const unsigned int numStrips = 32;
static float stripWidth() {
return 1.0f / (float) numStrips;
}
};
} // namespace
+16
View File
@@ -0,0 +1,16 @@
#include <boost/type_traits/is_floating_point.hpp>
#pragma once
namespace RBX {
namespace Text
{
enum Font {FONT_LEGACY, FONT_ARIAL, FONT_ARIALBOLD, FONT_SOURCESANS, FONT_SOURCESANSBOLD, FONT_SOURCESANSLIGHT, FONT_SOURCESANSITALIC, FONT_LAST};
// Font drawing params - copied from G3D
enum XAlign {XALIGN_RIGHT, XALIGN_LEFT, XALIGN_CENTER};
enum YAlign {YALIGN_TOP, /*YALIGN_BASELINE,*/ YALIGN_CENTER, YALIGN_BOTTOM};
}
}
@@ -0,0 +1,85 @@
#pragma once
#include "Util/G3DCore.h"
#include "Util/Rotation2D.h"
#include "GfxBase/Type.h"
namespace RBX {
class Adorn;
namespace Graphics {
class Texture;
class TextureManager;
class TextureAtlas;
};
//abstract base class
class Typesetter {
public:
virtual ~Typesetter() {}
virtual Vector2 draw(
Adorn* adorn,
const std::string& s,
const Vector2& position,
float size,
bool autoScale,
const Color4& color,
const Color4& outline,
RBX::Text::XAlign xalign = RBX::Text::XALIGN_LEFT,
RBX::Text::YAlign yalign = RBX::Text::YALIGN_TOP,
const Vector2& availableSpace = Vector2::zero(),
const Rect2D& clippingRect = Rect2D::xyxy(-1,-1,-1,-1),
const Rotation2D& rotation = Rotation2D()) const = 0;
virtual int getCursorPositionInText(
const std::string& s,
const RBX::Vector2& pos2D,
float size,
RBX::Text::XAlign xalign,
RBX::Text::YAlign yalign,
const RBX::Vector2& availableSpace,
const Rotation2D& rotation,
RBX::Vector2 cursorPos) const = 0;
/**
Useful for drawing centered text and boxes around text.
*/
virtual Vector2 measure(
const std::string& s,
float size,
const Vector2& availableSpace = Vector2::zero(),
bool* textFits = NULL
) const = 0;
virtual void loadResources(RBX::Graphics::TextureManager* textureManager, RBX::Graphics::TextureAtlas* glyphAtlas) = 0;
virtual void releaseResources() = 0;
virtual const shared_ptr<Graphics::Texture>& getTexture() const = 0;
static bool isCharNonWhitespace(char c)
{
return (c >= '!' && c <='~');
}
static bool isCharWhitespace(char c)
{
return (c == ' ' || c == '\t' || c == '\n');
}
static bool isCharSupported(char c)
{
return isCharNonWhitespace(c) || isCharWhitespace(c);
}
static bool isStringSupported(std::string& stringToCheck)
{
for (std::string::iterator iter = stringToCheck.begin(); iter != stringToCheck.end(); ++iter)
{
if (!isCharSupported(*iter))
{
return false;
}
}
return true;
}
};
}
@@ -0,0 +1,116 @@
#pragma once
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include "rbx/Declarations.h"
#include "GfxBase/RenderSettings.h"
namespace RBX {
class DataModel;
class ViewBase;
class FrameRateManager;
class CRenderSettings;
class RenderStats;
class RBXInterface IMetric;
class Instance;
enum ExporterFormat
{
ExporterFormat_Obj,
ExporterFormat_NumFormats
};
enum ExporterSaveType
{
ExporterSaveType_Everything,
ExporterSaveType_Selection,
ExporterSaveType_NumSaveTypes
};
struct OSContext
{
void* hWnd;
int width;
int height;
//insert OS specific stuff here.
OSContext()
: hWnd(0)
, width(640)
, height(480)
{
}
};
class IViewBaseFactory
{
public:
virtual ViewBase* Create(CRenderSettings::GraphicsMode mode,
OSContext* context, CRenderSettings* renderSettings) = 0;
};
class ViewBase
{
friend class Visit;
public:
static ViewBase* CreateView(CRenderSettings::GraphicsMode mode,
OSContext* context, CRenderSettings* renderSettings);
static void RegisterFactory(CRenderSettings::GraphicsMode mode,
IViewBaseFactory* factory);
// need this because we are statically linking.
static void InitPluginModules();
// it is bad form to need this. phase out please.
static void ShutdownPluginModules();
virtual void initResources() = 0;
virtual void bindWorkspace(boost::shared_ptr<RBX::DataModel> dataModel) = 0;
virtual void render(IMetric* metric, double timeJobStart);
virtual void renderPrepare(IMetric* metric) = 0;
virtual void renderPerform(double timeJobStart) = 0;
virtual void enableVR(bool enabled) = 0;
virtual void updateVR() = 0;
virtual const char* getVRDeviceName() = 0;
virtual void onResize(int cx, int cy) = 0;
virtual void buildGui(bool buildInGameGui = true) = 0;
virtual void renderThumb(unsigned char* data, int width, int height, bool crop, bool allowDolly) = 0;
virtual void garbageCollect() {}
virtual Instance* getWorkspace() = 0;
virtual RenderStats& getRenderStats() = 0;
virtual DataModel* getDataModel() = 0;
// use for pulling debug info only, please.
virtual FrameRateManager* getFrameRateManager() { return 0; }
virtual double getMetricValue(const std::string& s) { return -1; }
virtual bool getAndClearDoScreenshot() = 0;
virtual bool exportScene(const std::string& filePath, ExporterSaveType saveType, ExporterFormat format) = 0;
virtual bool exportSceneThumbJSON(ExporterSaveType saveType, ExporterFormat format, bool encodeBase64, std::string& strOut) = 0;
virtual void queueAssetReload(const std::string& filePath){};
virtual void immediateAssetReload(const std::string& filePath) = 0;
virtual void suspendView() = 0;
virtual void resumeView() = 0;
virtual std::pair<unsigned, unsigned> setFrameDataCallback(const boost::function<void(void*)>& callback);
virtual ~ViewBase() {}
};
} // namespace RBX
@@ -0,0 +1,58 @@
#pragma once
#include "V8DataModel/Workspace.h"
#include "util/UDim.h"
namespace RBX {
class ViewportBillboarder
{
private:
CoordinateFrame cframe;
Rect2D viewport;
bool visibleAndValid;
Vector2 screenOffset2D;
Vector2 getScreenOffset(const Rect2D& parentviewport, const RBX::Camera& camera, const CoordinateFrame& desiredModelView);
public:
Vector3 partExtentRelativeOffset;
Vector3 partStudsOffset;
Vector2 billboardSizeRelativeOffset;
UDim2 billboardSize;
const Vector2* guiScreenSize;
bool alwaysOnTop;
ViewportBillboarder();
ViewportBillboarder(const Vector3& partExtentRelativeOffset,
const Vector3& partStudsOffset,
const Vector2& billboardSizeRelativeOffset,
const UDim2& billboardSize, //studs* x + pixels
const Vector2* guiScreenSize //null for pixel-exact.
);
void update(const Rect2D& parentviewport, const Camera& camera, Vector3 partSize, CoordinateFrame partCFrame);
bool hitTest(const Vector2int16& mousePosition, const Vector2int16& windowSize,
RBX::Workspace* workspace, Vector2& billboardMousePosition);
const Vector2& getScreenOffset() const { return screenOffset2D; }
bool isVisibleAndValid() const
{
return visibleAndValid;
}
const Rect2D& getViewport() const
{
return viewport;
}
const CoordinateFrame& getCoordinateFrame() const
{
return cframe;
}
};
};