mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 00:13:53 +02:00
Fix the ssbo in GL4.5 and represent the workload proxies of the space and expose the workload engine to the JS api
This commit is contained in:
parent
e6d5f90847
commit
d91fb543f3
7 changed files with 88 additions and 96 deletions
|
@ -2701,6 +2701,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) {
|
|||
surfaceContext->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("Scene", DependencyManager::get<SceneScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("Render", _renderEngine->getConfiguration().get());
|
||||
surfaceContext->setContextProperty("Workload", _gameWorkload._engine->getConfiguration().get());
|
||||
surfaceContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface());
|
||||
surfaceContext->setContextProperty("Snapshot", DependencyManager::get<Snapshot>().data());
|
||||
|
||||
|
@ -6109,6 +6110,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
|
|||
|
||||
scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
|
||||
scriptEngine->registerGlobalObject("Render", _renderEngine->getConfiguration().get());
|
||||
scriptEngine->registerGlobalObject("Workload", _gameWorkload._engine->getConfiguration().get());
|
||||
|
||||
GraphicsScriptingInterface::registerMetaTypes(scriptEngine.data());
|
||||
scriptEngine->registerGlobalObject("Graphics", DependencyManager::get<GraphicsScriptingInterface>().data());
|
||||
|
|
|
@ -28,6 +28,8 @@ void GameWorkload::startup(const workload::SpacePointer& space, const render::Sc
|
|||
_engine.reset(new workload::Engine(std::make_shared<GameWorkloadContext>(space, scene)));
|
||||
|
||||
_engine->addJob<GameSpaceToRender>("SpaceToRender");
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GameWorkload::shutdown() {
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
#include "render-utils/drawWorkloadProxy_vert.h"
|
||||
#include "render-utils/drawWorkloadProxy_frag.h"
|
||||
|
||||
|
||||
void GameSpaceToRender::configure(const Config& config) {
|
||||
_showAllWorkspace = config.showAllWorkspace;
|
||||
}
|
||||
|
||||
void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext, Outputs& outputs) {
|
||||
auto gameWorkloadContext = std::dynamic_pointer_cast<GameWorkloadContext>(runContext);
|
||||
if (!gameWorkloadContext) {
|
||||
|
@ -28,6 +33,19 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
|
|||
return;
|
||||
}
|
||||
|
||||
auto visible = _showAllWorkspace;
|
||||
render::Transaction transaction;
|
||||
|
||||
// Nothing really needed, early exit
|
||||
if (!visible) {
|
||||
if (render::Item::isValidID(_spaceRenderItemID)) {
|
||||
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [](GameWorkloadRenderItem& item) {
|
||||
item.setVisible(false);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<workload::Space::Proxy> proxies(space->getNumAllocatedProxies());
|
||||
space->copyProxyValues(proxies.data(), (uint32_t)proxies.size());
|
||||
|
||||
|
@ -35,15 +53,16 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
|
|||
auto scene = gameWorkloadContext->_scene;
|
||||
|
||||
// Valid space, let's display its content
|
||||
render::Transaction transaction;
|
||||
if (!render::Item::isValidID(_spaceRenderItemID)) {
|
||||
_spaceRenderItemID = scene->allocateID();
|
||||
auto renderItem = std::make_shared<GameWorkloadRenderItem>();
|
||||
renderItem->editBound().setBox(glm::vec3(-100.0f), 200.0f);
|
||||
renderItem->setVisible(visible);
|
||||
renderItem->setAllProxies(proxies);
|
||||
transaction.resetItem(_spaceRenderItemID, std::make_shared<GameWorkloadRenderItem::Payload>(renderItem));
|
||||
} else {
|
||||
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [proxies](GameWorkloadRenderItem& item) {
|
||||
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [visible, proxies](GameWorkloadRenderItem& item) {
|
||||
item.setVisible(visible);
|
||||
item.setAllProxies(proxies);
|
||||
});
|
||||
}
|
||||
|
@ -52,7 +71,11 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
|
|||
|
||||
namespace render {
|
||||
template <> const ItemKey payloadGetKey(const GameWorkloadRenderItem::Pointer& payload) {
|
||||
return ItemKey::Builder::opaqueShape().withTagBits(render::ItemKey::TAG_BITS_0 | render::ItemKey::TAG_BITS_1);
|
||||
auto key = ItemKey::Builder::opaqueShape().withTagBits(render::ItemKey::TAG_BITS_0 | render::ItemKey::TAG_BITS_1);
|
||||
if (!payload->isVisible()) {
|
||||
key.withInvisible();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
template <> const Item::Bound payloadGetBound(const GameWorkloadRenderItem::Pointer& payload) {
|
||||
if (payload) {
|
||||
|
@ -74,8 +97,6 @@ namespace render {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GameWorkloadRenderItem::setAllProxies(const std::vector<workload::Space::Proxy>& proxies) {
|
||||
_myOwnProxies = proxies;
|
||||
static const uint32_t sizeOfProxy = sizeof(workload::Space::Proxy);
|
||||
|
@ -94,11 +115,11 @@ const gpu::PipelinePointer GameWorkloadRenderItem::getPipeline() {
|
|||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding("ssbo0Buffer", 11));
|
||||
slotBindings.insert(gpu::Shader::Binding("workloadProxiesBuffer", 0));
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||
/* state->setBlendFunction(true,
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);*/
|
||||
|
@ -125,30 +146,12 @@ void GameWorkloadRenderItem::render(RenderArgs* args) {
|
|||
// Bind program
|
||||
batch.setPipeline(getPipeline());
|
||||
|
||||
batch.setResourceBuffer(11, _allProxiesBuffer);
|
||||
// batch.setUniformBuffer(11, _allProxiesBuffer);
|
||||
batch.setResourceBuffer(0, _allProxiesBuffer);
|
||||
|
||||
static const int NUM_VERTICES_PER_QUAD = 3;
|
||||
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_QUAD * _numAllProxies, 0);
|
||||
|
||||
batch.setResourceBuffer(11, nullptr);
|
||||
// batch.setUniformBuffer(11, nullptr);
|
||||
|
||||
/*
|
||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||
GeometryCache::Shape geometryShape;
|
||||
glm::vec4 outColor;
|
||||
geometryShape = GeometryCache::Sphere;
|
||||
// geometryCache->renderShape(batch, geometryShape, outColor);
|
||||
|
||||
auto pipeline = geometryCache->getOpaqueShapePipeline();
|
||||
|
||||
for (int i = 0; i < _numAllProxies; i++) {
|
||||
auto sphere = _myOwnProxies[i].sphere;
|
||||
batch.setModelTransform(Transform(glm::quat(), glm::vec3(1.0), glm::vec3(sphere.x, sphere.y, sphere.z)));
|
||||
geometryCache->renderSolidShapeInstance(args, batch, geometryShape, outColor, pipeline);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,16 +12,32 @@
|
|||
|
||||
#include "GameWorkload.h"
|
||||
|
||||
class GameSpaceToRenderConfig : public workload::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool showAllWorkspace MEMBER showAllWorkspace NOTIFY dirty)
|
||||
public:
|
||||
|
||||
bool showAllWorkspace{ false };
|
||||
signals:
|
||||
void dirty();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
class GameSpaceToRender {
|
||||
public:
|
||||
using Config = GameSpaceToRenderConfig;
|
||||
using Outputs = render::Transaction;
|
||||
using JobModel = workload::Job::ModelO<GameSpaceToRender, Outputs>;
|
||||
using JobModel = workload::Job::ModelO<GameSpaceToRender, Outputs, Config>;
|
||||
|
||||
GameSpaceToRender() {}
|
||||
|
||||
void configure(const Config& config);
|
||||
void run(const workload::WorkloadContextPointer& renderContext, Outputs& outputs);
|
||||
|
||||
protected:
|
||||
render::ItemID _spaceRenderItemID{ render::Item::INVALID_ITEM_ID };
|
||||
bool _showAllWorkspace{ false };
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ int GL45Backend::makeResourceBufferSlots(GLuint glprogram, const Shader::Binding
|
|||
auto requestedBinding = slotBindings.find(info.name);
|
||||
if (requestedBinding != slotBindings.end()) {
|
||||
info.binding = (*requestedBinding)._location;
|
||||
glUniformBlockBinding(glprogram, info.index, info.binding);
|
||||
glShaderStorageBlockBinding(glprogram, info.index, info.binding);
|
||||
resourceBufferSlotMap[info.binding] = info.index;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ int GL45Backend::makeResourceBufferSlots(GLuint glprogram, const Shader::Binding
|
|||
auto slotIt = std::find_if(resourceBufferSlotMap.begin(), resourceBufferSlotMap.end(), GLBackend::isUnusedSlot);
|
||||
if (slotIt != resourceBufferSlotMap.end()) {
|
||||
info.binding = slotIt - resourceBufferSlotMap.begin();
|
||||
glUniformBlockBinding(glprogram, info.index, info.binding);
|
||||
glShaderStorageBlockBinding(glprogram, info.index, info.binding);
|
||||
} else {
|
||||
// This should never happen, an active ssbo cannot find an available slot among the max available?!
|
||||
info.binding = -1;
|
||||
|
|
|
@ -11,26 +11,20 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
<@include gpu/Paint.slh@>
|
||||
|
||||
in vec4 varColor;
|
||||
in vec2 varTexcoord;
|
||||
//out vec4 outFragColor;
|
||||
|
||||
void main(void) {
|
||||
/* outFragColor = vec4(1.0);
|
||||
float r = sqrt(dot(varTexcoord.xy,varTexcoord.xy));
|
||||
float a = paintStripe(r * varColor.w, 0.0, 1.0 / varColor.w, 0.05 / varColor.w);
|
||||
if (a <= 0.1 || r > 1.1) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5);
|
||||
|
||||
if (varColor.a == 0.0) {
|
||||
outFragColor = vec4(mix(vec3(0.0), varColor.xyz, var), mix(0.0, 1.0, var));
|
||||
|
||||
} else {
|
||||
outFragColor = vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a);
|
||||
}*/
|
||||
|
||||
|
||||
packDeferredFragmentUnlit(
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
1.0,
|
||||
vec3(1.0));
|
||||
varColor.rgb);
|
||||
}
|
||||
|
|
|
@ -27,88 +27,63 @@ struct WorkloadProxy {
|
|||
};
|
||||
|
||||
#if defined(GPU_GL410)
|
||||
uniform samplerBuffer ssbo0Buffer;
|
||||
uniform samplerBuffer workloadProxiesBuffer;
|
||||
WorkloadProxy getWorkloadProxy(int i) {
|
||||
int offset = 2 * i;
|
||||
WorkloadProxy proxy;
|
||||
proxy.sphere = texelFetch(ssbo0Buffer, offset);
|
||||
proxy.region = texelFetch(ssbo0Buffer, offset + 1);
|
||||
proxy.sphere = texelFetch(workloadProxiesBuffer, offset);
|
||||
proxy.region = texelFetch(workloadProxiesBuffer, offset + 1);
|
||||
return proxy;
|
||||
}
|
||||
#else
|
||||
layout(std140) buffer ssbo0Buffer {
|
||||
WorkloadProxy proxies[];
|
||||
layout(std140) buffer workloadProxiesBuffer {
|
||||
WorkloadProxy _proxies[];
|
||||
};
|
||||
WorkloadProxy getWorkloadProxy(int i) {
|
||||
WorkloadProxy proxy = proxies[i];
|
||||
WorkloadProxy proxy = _proxies[i];
|
||||
return proxy;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
uniform ssbo0Buffer {
|
||||
WorkloadProxy proxies[1024];
|
||||
};
|
||||
WorkloadProxy getWorkloadProxy(int index) {
|
||||
return proxies[index];
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
out vec4 varColor;
|
||||
out vec2 varTexcoord;
|
||||
|
||||
void main(void) {
|
||||
const vec4 UNIT_BOX[8] = vec4[8](
|
||||
vec4(0.0, 0.0, 0.0, 0.0),
|
||||
vec4(1.0, 0.0, 0.0, 1.0),
|
||||
vec4(0.0, 1.0, 0.0, 1.0),
|
||||
vec4(1.0, 1.0, 0.0, 2.0),
|
||||
vec4(0.0, 0.0, 1.0, 1.0),
|
||||
vec4(1.0, 0.0, 1.0, 2.0),
|
||||
vec4(0.0, 1.0, 1.0, 2.0),
|
||||
vec4(1.0, 1.0, 1.0, 3.0)
|
||||
const vec4 UNIT_SPRITE[3] = vec4[3](
|
||||
vec4(-1.0, -1.0, 0.0, 1.0),
|
||||
vec4(3.0, -1.0, 0.0, 1.0),
|
||||
vec4(-1.0, 3.0, 0.0, 1.0)
|
||||
);
|
||||
/* const int UNIT_BOX_LINE_INDICES[24] = int[24](
|
||||
0, 1,
|
||||
1, 3,
|
||||
3, 2,
|
||||
2, 0,
|
||||
4, 5,
|
||||
5, 7,
|
||||
7, 6,
|
||||
6, 4,
|
||||
2, 6,
|
||||
3, 7,
|
||||
0, 4,
|
||||
1, 5
|
||||
const int UNIT_SPRITE_INDICES[3] = int[3](
|
||||
0, 1, 2
|
||||
);
|
||||
|
||||
int proxyID = gl_VertexID / 24;
|
||||
int vertexID = gl_VertexID - proxyID * 24;*/
|
||||
|
||||
const int UNIT_BOX_LINE_INDICES[6] = int[6](
|
||||
0, 1, 2,
|
||||
2, 1, 3
|
||||
);
|
||||
|
||||
int proxyID = gl_VertexID / 3;
|
||||
int vertexID = gl_VertexID - proxyID * 3;
|
||||
|
||||
vec4 cubeVec = UNIT_BOX[UNIT_BOX_LINE_INDICES[vertexID]];
|
||||
vec4 spriteVert = UNIT_SPRITE[UNIT_SPRITE_INDICES[vertexID]];
|
||||
|
||||
WorkloadProxy proxy = getWorkloadProxy(proxyID);
|
||||
vec3 boundPos = proxy.sphere.xyz;
|
||||
// vec3 boundDim = vec3(proxy.sphere.w);
|
||||
vec3 boundDim = vec3(0.5);
|
||||
vec4 proxyPosWorld = vec4(proxy.sphere.xyz, 1.0);
|
||||
|
||||
vec4 pos = vec4(boundPos + boundDim * cubeVec.xyz, 1.0);
|
||||
|
||||
// standard transform
|
||||
// standard transform, bring proxy in view space
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||
vec4 proxyPosEye;
|
||||
<$transformModelToEyePos(cam, obj, proxyPosWorld, proxyPosEye)$>
|
||||
|
||||
varColor = vec4(colorWheel(float(proxyID)/(-inColor.w)), 1.0);
|
||||
// Define the billboarded space
|
||||
vec3 dirZ = -normalize(proxyPosEye.xyz);
|
||||
vec3 dirX = normalize(cross(vec3(0.0, 1.0, 0.0), dirZ));
|
||||
vec3 dirY = vec3(0.0, 1.0, 0.0);
|
||||
// vec3 dirY = normalize(cross(dirZ, vec3(1.0, 0.0, 0.0)));
|
||||
|
||||
varTexcoord = vec2(cubeVec.w, length(boundDim));
|
||||
vec4 pos = vec4(proxyPosEye.xyz + proxy.sphere.w * ( dirX * spriteVert.x + dirY * spriteVert.y /* + dirZ * spriteVert.z*/), 1.0);
|
||||
varTexcoord = spriteVert.xy;
|
||||
<$transformEyeToClipPos(cam, pos, gl_Position)$>
|
||||
|
||||
// Convert region to color
|
||||
|
||||
varColor = vec4(colorWheel(proxy.region.x), proxy.sphere.w);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue