Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
support layer per UEEntity and a bit mask of layers that a camera ren…
Browse files Browse the repository at this point in the history
…der (closes #64)
  • Loading branch information
Stephan Dilly committed Apr 15, 2015
1 parent b981a71 commit 5d3987c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
19 changes: 16 additions & 3 deletions source/unecht/core/components/_editor.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class UEEditorGismo : UEComponent {
super.onCreate;

import unecht.core.components.misc;

entity.layer = UELayer.editor;

auto renderer = this.entity.addComponent!UERenderer;
auto mesh = this.entity.addComponent!UEMesh;
Expand Down Expand Up @@ -550,14 +552,25 @@ final class EditorRootComponent : UEComponent {
{
if(_editorVisible)
{
// render regular but from editor camera pov
_editorCam.render();

import unecht.core.components.misc;
UERenderer.editorMaterial = editorMaterial;
{
// render wireframes
UERenderer.editorMaterial = editorMaterial;
scope(exit)UERenderer.editorMaterial = null;
_editorCam.clearBitColor=false;
scope(exit)_editorCam.clearBitColor=true;

_editorCam.render();
}

// render gismo
_editorCam.visibleLayers = 1<<UELayer.editor;
_editorCam.clearBitColor=false;
_editorCam.render();
_editorCam.clearBitColor=true;
UERenderer.editorMaterial = null;
_editorCam.visibleLayers = UECameraDefaultLayers;
}

_editorGUI.render();
Expand Down
15 changes: 12 additions & 3 deletions source/unecht/core/components/camera.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import unecht.core.components.misc;
import unecht.core.components.renderer;
import unecht.core.component;
import unecht.core.componentManager;
import unecht.core.entity;

import unecht.core.types;

Expand Down Expand Up @@ -53,6 +54,7 @@ final class UECamera : UEComponent
vec4 clearColor = vec4(0,0,0,1);
bool clearBitColor = true;
bool clearBitDepth = true;
int visibleLayers = UECameraDefaultLayers;

bool isOrthographic=false;
float orthoSize=1;
Expand Down Expand Up @@ -90,8 +92,11 @@ final class UECamera : UEComponent
if(clearBitColor) clearBits |= GL_COLOR_BUFFER_BIT;
if(clearBitDepth) clearBits |= GL_DEPTH_BUFFER_BIT;

glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(clearBits);
if(clearBits!=0)
{
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(clearBits);
}

UESize viewportSize = UESize(
cast(int)(viewport.size.x * ue.application.mainWindow.size.width),
Expand All @@ -101,7 +106,11 @@ final class UECamera : UEComponent
foreach(r; renderers)
{
if(r.enabled && r.sceneNode.enabled)
r.render(this);
{
import unecht.core.stdex;
if(testBit(visibleLayers, r.entity.layer))
r.render(this);
}
}
}

Expand Down
42 changes: 32 additions & 10 deletions source/unecht/core/entity.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,41 @@ import derelict.util.system;
import unecht;
import unecht.core.components.sceneNode;

///
enum UELayer : uint
{
all=0,
editor,
}

static immutable uint UECameraDefaultLayers = 0xffffffff ^ (1<<UELayer.editor);

import unecht.core.stdex;
static assert(false == testBit(UECameraDefaultLayers,UELayer.editor));
static assert(true == testBit(UECameraDefaultLayers,UELayer.all));

///
final class UEEntity
{
///
bool hideInEditor;
///
@nogc @property UESceneNode sceneNode() nothrow { return _sceneNode; }
///
@nogc @property bool destroyed() nothrow { return _destroyed; }
///
@nogc @property string name() const { return _name; }
///
@nogc @property void name(string v) { _name = v; }
///
@nogc @property UEComponent[] components() { return _components; }

@nogc @property{
///
UESceneNode sceneNode() nothrow { return _sceneNode; }
///
bool destroyed() nothrow { return _destroyed; }
///
string name() const { return _name; }
///
void name(string v) { _name = v; }
///
UELayer layer() const { return _layer; }
///
void layer(UELayer layer) { _layer = layer; }
///
UEComponent[] components() { return _components; }
}

///
void broadcast(string _method,ARG)(ARG _arg)
Expand Down Expand Up @@ -147,6 +167,8 @@ private:

bool _destroyed = false;

UELayer _layer = UELayer.all;

UESceneNode _sceneNode;

UEComponent[] _components;
Expand Down
23 changes: 15 additions & 8 deletions source/unecht/core/stdex.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ unittest
}

///
auto testBit(T)(in T v, size_t bit)
auto testBit(T)(in T v, size_t bitIdx)
{
return (v & bit) == bit;
auto bitMask = 1<<bitIdx;
return (v & bitMask) == bitMask;
}

///
auto testBitMask(T)(in T v, size_t bitMask)
{
return (v & bitMask) == bitMask;
}

unittest
{
assert(testBit(0,1) == false);
assert(testBit(1,1) == true);
assert(testBit(0b10,0b10) == true);
assert(testBit(0b1010,0b10) == true);
assert(testBit(0b1010,0b1) == false);
assert(testBit(0b1010,0b100) == false);
assert(testBitMask(0,1) == false);
assert(testBitMask(1,1) == true);
assert(testBitMask(0b10,0b10) == true);
assert(testBitMask(0b1010,0b10) == true);
assert(testBitMask(0b1010,0b1) == false);
assert(testBitMask(0b1010,0b100) == false);
}

0 comments on commit 5d3987c

Please sign in to comment.