refactoring
This commit is contained in:
@@ -25,10 +25,6 @@
|
||||
namespace thermion
|
||||
{
|
||||
|
||||
typedef std::chrono::time_point time_point_t;
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
class RenderTicker
|
||||
{
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ extern "C"
|
||||
};
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TMaterialInstance *Material_createInstance(TMaterial *tMaterial);
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createImageMaterial();
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createGridMaterial();
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createImageMaterial(TEngine *tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createGridMaterial(TEngine *tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE bool Material_hasParameter(TMaterial *tMaterial, const char *propertyName);
|
||||
EMSCRIPTEN_KEEPALIVE bool MaterialInstance_isStencilWriteEnabled(TMaterialInstance *materialInstance);
|
||||
EMSCRIPTEN_KEEPALIVE void MaterialInstance_setStencilWrite(TMaterialInstance *materialInstance, bool enabled);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void RenderLoop_create();
|
||||
EMSCRIPTEN_KEEPALIVE void RenderLoop_destroy();
|
||||
EMSCRIPTEN_KEEPALIVE void RenderLoop_requestAnimationFrame(void (*onComplete));
|
||||
EMSCRIPTEN_KEEPALIVE void RenderLoop_requestAnimationFrame(void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void RenderTicker_renderRenderThread(TRenderTicker *tRenderTicker, uint64_t frameTimeInNanos, void (*onComplete)());
|
||||
// EMSCRIPTEN_KEEPALIVE void RenderLoop_addTask(TRenderLoop* tRenderLoop, void (*task)());
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace thermion
|
||||
TTextureFormat format,
|
||||
void (*onComplete)(TTexture*)
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyTextureRenderThread(TEngine *engine, TTexture* tTexture, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_createFenceRenderThread(TEngine *tEngine, void (*onComplete)(TFence*));
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyFenceRenderThread(TEngine *tEngine, TFence *tFence, void (*onComplete)());
|
||||
@@ -175,18 +176,6 @@ namespace thermion
|
||||
EMSCRIPTEN_KEEPALIVE void Image_getHeightRenderThread(TLinearImage *tLinearImage, void (*onComplete)(uint32_t));
|
||||
EMSCRIPTEN_KEEPALIVE void Image_getChannelsRenderThread(TLinearImage *tLinearImage, void (*onComplete)(uint32_t));
|
||||
|
||||
// Texture methods
|
||||
EMSCRIPTEN_KEEPALIVE void Texture_buildRenderThread(TEngine *engine,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t depth,
|
||||
uint8_t levels,
|
||||
uint16_t tUsage,
|
||||
intptr_t import,
|
||||
TTextureSamplerType sampler,
|
||||
TTextureFormat format,
|
||||
void (*onComplete)(TTexture *)
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Texture_loadImageRenderThread(
|
||||
TEngine *tEngine,
|
||||
@@ -292,8 +281,6 @@ namespace thermion
|
||||
void (*onComplete)()
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void AnimationManager_updateBoneMatricesRenderThread(TSceneManager *sceneManager,
|
||||
EntityId asset, void (*callback)(bool));
|
||||
EMSCRIPTEN_KEEPALIVE void AnimationManager_setBoneTransformRenderThread(
|
||||
TAnimationManager *tAnimationManager,
|
||||
EntityId asset,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <utils/Entity.h>
|
||||
#include <filament/Box.h>
|
||||
#include <filament/Engine.h>
|
||||
|
||||
@@ -37,10 +37,6 @@ public:
|
||||
void addAllEntities(Scene* scene) override;
|
||||
void removeAllEntities(Scene* scene) override;
|
||||
|
||||
void setPriority(RenderableManager& rm, int priority) override;
|
||||
void setLayer(RenderableManager& rm, int layer) override;
|
||||
|
||||
|
||||
size_t getInstanceCount() override { return _instances.size(); }
|
||||
SceneAsset* getInstanceByEntity(utils::Entity entity) override;
|
||||
SceneAsset* getInstanceAt(size_t index) override;
|
||||
|
||||
@@ -227,23 +227,7 @@ namespace thermion
|
||||
scene->remove(_gridEntity);
|
||||
// scene->remove(_sphereEntity);
|
||||
}
|
||||
|
||||
void GridOverlay::setPriority(RenderableManager &rm, int priority)
|
||||
{
|
||||
auto gridInstance = rm.getInstance(_gridEntity);
|
||||
rm.setPriority(gridInstance, priority);
|
||||
// auto sphereInstance = rm.getInstance(_sphereEntity);
|
||||
// rm.setPriority(sphereInstance, priority);
|
||||
}
|
||||
|
||||
void GridOverlay::setLayer(RenderableManager &rm, int layer)
|
||||
{
|
||||
auto gridInstance = rm.getInstance(_gridEntity);
|
||||
rm.setLayerMask(gridInstance, 0xFF, 1u << (uint8_t)layer);
|
||||
// auto sphereInstance = rm.getInstance(_sphereEntity);
|
||||
// rm.setLayerMask(sphereInstance, 0xFF, 1u << (uint8_t)layer);
|
||||
}
|
||||
|
||||
|
||||
SceneAsset *GridOverlay::getInstanceByEntity(utils::Entity entity)
|
||||
{
|
||||
for (auto &instance : _instances)
|
||||
|
||||
@@ -42,7 +42,6 @@ namespace thermion
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
using namespace utils;
|
||||
using namespace std::chrono;
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include <filament/Camera.h>
|
||||
#include <filament/ColorGrading.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Frustum.h>
|
||||
#include <filament/ToneMapper.h>
|
||||
#include <filament/View.h>
|
||||
#include <filament/Viewport.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/ToneMapper.h>
|
||||
#include <filament/ColorGrading.h>
|
||||
#include <filament/Camera.h>
|
||||
|
||||
#include <utils/Entity.h>
|
||||
|
||||
#include "c_api/ThermionDartApi.h"
|
||||
#include "c_api/TCamera.h"
|
||||
#include "Log.hpp"
|
||||
#include "MathUtils.hpp"
|
||||
@@ -32,8 +33,8 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_getFrustum(TCamera *tCamera, double *out) {
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
auto &frustum = camera->getFrustum();
|
||||
auto planes = frustum.getPlanes();
|
||||
auto frustum = camera->getFrustum();
|
||||
auto planes = frustum.getNormalizedPlanes();
|
||||
for(int i = 0; i < 6; i++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
out[(i*4) + j] = planes[i][j];
|
||||
@@ -41,18 +42,30 @@ namespace thermion
|
||||
}
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setLensProjection(TCamera *tCamera, double near, double far, double aspect, double focalLength) {
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
camera->setLensProjection(near, far, aspect, focalLength);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera *tCamera, double4x4 tModelMatrix) {
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
auto modelMatrix = convert_double4x4_to_mat4(tModelMatrix);
|
||||
camera->setModelMatrix(modelMatrix);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(TCamera *tCamera, double4x4 projectionMatrix, double near, double far)
|
||||
{
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
camera->setCustomProjection(convert_double4x4_to_mat4(projectionMatrix), near, far);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double Camera_getFocusDistance(TCamera *camera) {
|
||||
EMSCRIPTEN_KEEPALIVE double Camera_getFocusDistance(TCamera *tCamera) {
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
return camera->getFocusDistance();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setFocusDistance(TCamera *camera, float distance) {
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setFocusDistance(TCamera *tCamera, float distance) {
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
return camera->setFocusDistance(distance);
|
||||
}
|
||||
@@ -93,16 +106,16 @@ namespace thermion
|
||||
return camera->getCullingFar();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setProjection(TCamera *const tCamera, Projection projection, double left, double right,
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setProjection(TCamera *const tCamera, TProjection projection, double left, double right,
|
||||
double bottom, double top,
|
||||
double near, double far)
|
||||
{
|
||||
auto *camera = reinterpret_cast<Camera *>(tCamera);
|
||||
filament::Camera::Projection filamentProjection;
|
||||
switch(projection) {
|
||||
case Projection::Orthographic:
|
||||
case TProjection::Orthographic:
|
||||
filamentProjection = filament::Camera::Projection::ORTHO;
|
||||
case Projection::Perspective:
|
||||
case TProjection::Perspective:
|
||||
filamentProjection = filament::Camera::Projection::PERSPECTIVE;
|
||||
}
|
||||
camera->setProjection(filamentProjection, left, right, bottom, top, near, far);
|
||||
|
||||
@@ -47,15 +47,21 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TEngine *Engine_create(
|
||||
TBackend backend,
|
||||
void* platform,
|
||||
void* sharedContext,
|
||||
void* tPlatform,
|
||||
void* tSharedContext,
|
||||
uint8_t stereoscopicEyeCount,
|
||||
bool disableHandleUseAfterFreeCheck)
|
||||
{
|
||||
filament::Engine::Config config;
|
||||
config.stereoscopicEyeCount = stereoscopicEyeCount;
|
||||
config.disableHandleUseAfterFreeCheck = disableHandleUseAfterFreeCheck;
|
||||
auto *engine = filament::Engine::create(static_cast<filament::Engine::Backend>(backend), platform, sharedContext, &config);
|
||||
auto *platform = reinterpret_cast<filament::backend::Platform *>(tPlatform);
|
||||
auto *engine = filament::Engine::create(
|
||||
static_cast<filament::Engine::Backend>(backend),
|
||||
platform,
|
||||
tSharedContext,
|
||||
&config
|
||||
);
|
||||
return reinterpret_cast<TEngine *>(engine);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,12 +46,13 @@ EMSCRIPTEN_KEEPALIVE int LightManager_createLight(TEngine *tEngine, TLightManage
|
||||
}
|
||||
|
||||
filament::LightManager::Builder builder(lightType);
|
||||
auto entity = utils::EntityManager::create();
|
||||
auto result = builder.build(*engine, utils::Entity::import(entity));
|
||||
auto &em = utils::EntityManager::get();
|
||||
auto entity = em.create();
|
||||
auto result = builder.build(*engine, entity);
|
||||
if(result != filament::LightManager::Builder::Result::Success) {
|
||||
Log("Failed to create light");
|
||||
}
|
||||
return entity;
|
||||
return utils::Entity::smuggle(entity);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void LightManager_destroyLight(TLightManager *tLightManager, EntityId entity) {
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
#include <filament/MaterialInstance.h>
|
||||
#include <filament/Material.h>
|
||||
|
||||
#include <math/mat4.h>
|
||||
#include <math/vec4.h>
|
||||
#include <math/vec2.h>
|
||||
|
||||
#include "Log.hpp"
|
||||
#include "materials/image.h"
|
||||
|
||||
#include "material/image.h"
|
||||
#include "material/grid.h"
|
||||
|
||||
#include "c_api/TMaterialInstance.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -26,7 +30,7 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createImageMaterial(TEngine *tEngine) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *material = Material::Builder()
|
||||
auto *material = filament::Material::Builder()
|
||||
.package(IMAGE_IMAGE_DATA, IMAGE_IMAGE_SIZE)
|
||||
.build(*engine);
|
||||
|
||||
@@ -35,10 +39,9 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createGridMaterial(TEngine *tEngine) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *material = Material::Builder()
|
||||
.package(GRID_GRID_DATA, GRID_GRID_SIZE)
|
||||
.build(*engine);
|
||||
|
||||
auto *material = filament::Material::Builder()
|
||||
.package(GRID_GRID_DATA, GRID_GRID_SIZE)
|
||||
.build(*engine);
|
||||
return reinterpret_cast<TMaterial *>(material);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace thermion
|
||||
if (!renderableInstance.isValid()) {
|
||||
return Aabb3 { };
|
||||
}
|
||||
auto box = renderableManager.getAxisAlignedBoundingBox(renderableInstance);
|
||||
auto box = renderableManager->getAxisAlignedBoundingBox(renderableInstance);
|
||||
return Aabb3{box.center.x, box.center.y, box.center.z, box.halfExtent.x, box.halfExtent.y, box.halfExtent.z};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "c_api/TTexture.h"
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Material.h>
|
||||
#include <filament/RenderTarget.h>
|
||||
@@ -15,6 +14,8 @@
|
||||
#include <filament/imageio/ImageDecoder.h>
|
||||
#include <filament/backend/DriverEnums.h>
|
||||
|
||||
#include "c_api/TTexture.h"
|
||||
|
||||
#include "Log.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -227,7 +228,7 @@ namespace thermion
|
||||
auto *engine = reinterpret_cast<::filament::Engine *>(tEngine);
|
||||
auto format = convertToFilamentFormat(tFormat);
|
||||
auto samplerType = static_cast<::filament::Texture::Sampler>(static_cast<int>(tSamplerType));
|
||||
auto usage = static_cast<::filament::Texture::Usage>(tUsage);
|
||||
auto usage = static_cast<TextureUsage>(tUsage);
|
||||
|
||||
if ((usage & TextureUsage::UPLOADABLE) == TextureUsage::UPLOADABLE) {
|
||||
TRACE("UPLOADABLE");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "RenderLoop.hpp"
|
||||
#include "rendering/RenderLoop.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <stdlib.h>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user