From db7cadff2a88c23a691698f5ebcdb5f48a3305c6 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 12 Jan 2015 09:24:34 -0800 Subject: [PATCH] Introducing the render namespace and Item and Scene classes --- libraries/render-utils/src/render/Scene.cpp | 25 ++++ libraries/render-utils/src/render/Scene.h | 157 ++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100755 libraries/render-utils/src/render/Scene.cpp create mode 100755 libraries/render-utils/src/render/Scene.h diff --git a/libraries/render-utils/src/render/Scene.cpp b/libraries/render-utils/src/render/Scene.cpp new file mode 100755 index 0000000000..173ffc3eb8 --- /dev/null +++ b/libraries/render-utils/src/render/Scene.cpp @@ -0,0 +1,25 @@ +// +// Scene.cpp +// render/src/render +// +// Created by Sam Gateau on 1/11/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "Scene.h" + +using namespace render; + + +Item::ID Scene::addItem(Item::PayloadPtr& payload) { + + return 0; +} + +void removeItem(ID id) { +} + +void moveItem(ID id) { +} diff --git a/libraries/render-utils/src/render/Scene.h b/libraries/render-utils/src/render/Scene.h new file mode 100755 index 0000000000..09c79b8a82 --- /dev/null +++ b/libraries/render-utils/src/render/Scene.h @@ -0,0 +1,157 @@ +// +// Scene.h +// render/src/render +// +// Created by Sam Gateau on 1/11/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_render_Scene_h +#define hifi_render_Scene_h + +#include +#include +#include +#include +#include + +namespace render { + +class Context; + +class Item { +public: + typedef std::vector Vector; + typedef unsigned int ID; + + // State is the KEY to filter Items and create specialized lists + enum FlagBit { + TYPE_SHAPE = 0, // Item is a Shape + TYPE_LIGHT, // Item is a Light + TRANSLUCENT, // Translucent and not opaque + VIEW_SPACE, // Transformed in view space, and not in world space + DYNAMIC, // Dynamic and bound will change unlike static item + DEFORMED, // Deformed within bound, not solid + UNVISIBLE, // Visible or not? could be just here to cast shadow + SHADOW_CASTER, // Item cast shadows + PICKABLE, // Item can be picked/selected + + NUM_FLAGS, // Not a valid flag + }; + typedef std::bitset State; + + // Bound is the AABBox fully containing this item + typedef AABox Bound; + + // Stats records the life history and performances of this item while performing at rendering and updating. + // This is Used for monitoring and dynamically adjust the quality + class Stats { + public: + int _firstFrame; + }; + + // Payload is whatever is in this Item and implement the Payload Interface + class PayloadInterface { + public: + virtual const State&& getState() const = 0; + virtual const Bound&& getBound() const = 0; + virtual void render(Context& context) = 0; + + ~PayloadInterface() {} + protected: + }; + + template class Payload : public PayloadInterface { + public: + virtual const State&& getState() const { return getState(*this); } + virtual const Bound&& getBound() const { return getBound(*this); } + virtual void render(Context& context) { render(this*, context); } + protected: + }; + + typedef std::shared_ptr PayloadPtr; + + + Item(PayloadPtr& payload): + _payload(payload) {} + + ~Item() {} + + // Check heuristic flags of the state + const State& getState() const { return _state; } + + bool isOpaque() const { return !_state[TRANSLUCENT]; } + bool isTranslucent() const { return _state[TRANSLUCENT]; } + + bool isWorldSpace() const { return !_state[VIEW_SPACE]; } + bool isViewSpace() const { return _state[VIEW_SPACE]; } + + bool isStatic() const { return !_state[DYNAMIC]; } + bool isDynamic() const { return _state[DYNAMIC]; } + bool isDeformed() const { return _state[DEFORMED]; } + + bool isVisible() const { return !_state[UNVISIBLE]; } + bool isUnvisible() const { return _state[UNVISIBLE]; } + + bool isShadowCaster() const { return _state[SHADOW_CASTER]; } + + bool isPickable() const { return _state[PICKABLE]; } + + // Payload Interface + const Bound&& getBound() const { return _payload->getBound(); } + void render(Context& context) { _payload->render(context); } + +protected: + PayloadPtr _payload; + State _state; + + friend class Scene; +}; + +class Scene { +public: + typedef Item::Vector Items; + typedef Item::ID ID; + typedef std::vector ItemList; + typedef std::map ItemLists; + + enum ChangeType { + ADD = 0, + REMOVE, + MOVE, + RESET, + + NUM_CHANGE_TYPES, + }; + typedef ItemList ChangeLists[NUM_CHANGE_TYPES]; + class ChangePacket { + public: + ChangePacket(int frame) : + _frame(frame) {} + ~ChangePacket(); + + int _frame; + ChangeLists _changeLists; + protected: + }; + + Scene() {} + ~Scene() {} + + + ID addItem(Item::PayloadPtr& payload); + void removeItem(ID id); + void moveItem(ID id); + + +protected: + Items _items; + ItemLists _buckets; +}; + +} + +#endif // hifi_render_Scene_h