mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-08 05:09:36 +02:00
Remove simple draw task uniforms
This commit is contained in:
parent
ac84a498b3
commit
c8eb4da6b6
5 changed files with 40 additions and 18 deletions
|
@ -13,12 +13,16 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include gpu/ShaderConstants.h@>
|
struct DrawColorParams {
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
layout(location=GPU_UNIFORM_COLOR) uniform vec4 color;
|
layout(binding=0) uniform drawColorParamsBuffer {
|
||||||
|
DrawColorParams params;
|
||||||
|
};
|
||||||
|
|
||||||
layout(location=0) out vec4 outFragColor;
|
layout(location=0) out vec4 outFragColor;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
outFragColor = color;
|
outFragColor = params.color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,19 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include gpu/ShaderConstants.h@>
|
|
||||||
|
|
||||||
layout(binding=0) uniform sampler2D colorMap;
|
layout(binding=0) uniform sampler2D colorMap;
|
||||||
layout(location=GPU_UNIFORM_COLOR) uniform vec4 color;
|
|
||||||
|
struct DrawColorParams {
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(binding=0) uniform drawColorParams {
|
||||||
|
DrawColorParams params;
|
||||||
|
};
|
||||||
|
|
||||||
layout(location=0) in vec2 varTexCoord0;
|
layout(location=0) in vec2 varTexCoord0;
|
||||||
layout(location=0) out vec4 outFragColor;
|
layout(location=0) out vec4 outFragColor;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
outFragColor = texture(colorMap, varTexCoord0) * color;
|
outFragColor = texture(colorMap, varTexCoord0) * params.color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,8 +184,13 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
|
||||||
_drawBuffer = std::make_shared<gpu::Buffer>(sizeOfItemBound);
|
_drawBuffer = std::make_shared<gpu::Buffer>(sizeOfItemBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
_drawBuffer->setData(numItems * sizeOfItemBound, (const gpu::Byte*) items.data());
|
if (!_paramsBuffer) {
|
||||||
|
_paramsBuffer = std::make_shared<gpu::Buffer>(sizeof(vec4), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawBuffer->setData(numItems * sizeOfItemBound, (const gpu::Byte*) items.data());
|
||||||
|
glm::vec4 color(glm::vec3(0.0f), -(float) numItems);
|
||||||
|
_paramsBuffer->setSubData(0, color);
|
||||||
gpu::doInBatch("DrawBounds::run", args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch("DrawBounds::run", args->_context, [&](gpu::Batch& batch) {
|
||||||
args->_batch = &batch;
|
args->_batch = &batch;
|
||||||
|
|
||||||
|
@ -202,7 +207,7 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
|
||||||
batch.setPipeline(getPipeline());
|
batch.setPipeline(getPipeline());
|
||||||
|
|
||||||
glm::vec4 color(glm::vec3(0.0f), -(float) numItems);
|
glm::vec4 color(glm::vec3(0.0f), -(float) numItems);
|
||||||
batch._glUniform4fv(gpu::slot::uniform::Color, 1, (const float*)(&color));
|
batch.setUniformBuffer(0, _paramsBuffer);
|
||||||
batch.setResourceBuffer(0, _drawBuffer);
|
batch.setResourceBuffer(0, _drawBuffer);
|
||||||
|
|
||||||
static const int NUM_VERTICES_PER_CUBE = 24;
|
static const int NUM_VERTICES_PER_CUBE = 24;
|
||||||
|
@ -212,9 +217,10 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
|
||||||
|
|
||||||
gpu::Stream::FormatPointer DrawQuadVolume::_format;
|
gpu::Stream::FormatPointer DrawQuadVolume::_format;
|
||||||
|
|
||||||
DrawQuadVolume::DrawQuadVolume(const glm::vec3& color) :
|
DrawQuadVolume::DrawQuadVolume(const glm::vec3& color) {
|
||||||
_color{ color } {
|
|
||||||
_meshVertices = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(glm::vec3) * 8, nullptr), gpu::Element::VEC3F_XYZ);
|
_meshVertices = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(glm::vec3) * 8, nullptr), gpu::Element::VEC3F_XYZ);
|
||||||
|
_params = std::make_shared<gpu::Buffer>(sizeof(glm::vec4), nullptr);
|
||||||
|
_params->setSubData(0, vec4(color, 1.0));
|
||||||
if (!_format) {
|
if (!_format) {
|
||||||
_format = std::make_shared<gpu::Stream::Format>();
|
_format = std::make_shared<gpu::Stream::Format>();
|
||||||
_format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
_format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
||||||
|
@ -248,8 +254,7 @@ void DrawQuadVolume::run(const render::RenderContextPointer& renderContext, cons
|
||||||
batch.setProjectionTransform(projMat);
|
batch.setProjectionTransform(projMat);
|
||||||
batch.setViewTransform(viewMat);
|
batch.setViewTransform(viewMat);
|
||||||
batch.setPipeline(getPipeline());
|
batch.setPipeline(getPipeline());
|
||||||
|
batch.setUniformBuffer(0, _params);
|
||||||
batch._glUniform4f(0, _color.x, _color.y, _color.z, 1.0f);
|
|
||||||
batch.setInputFormat(_format);
|
batch.setInputFormat(_format);
|
||||||
batch.setInputBuffer(gpu::Stream::POSITION, _meshVertices);
|
batch.setInputBuffer(gpu::Stream::POSITION, _meshVertices);
|
||||||
batch.setIndexBuffer(indices);
|
batch.setIndexBuffer(indices);
|
||||||
|
|
|
@ -66,6 +66,7 @@ private:
|
||||||
const gpu::PipelinePointer getPipeline();
|
const gpu::PipelinePointer getPipeline();
|
||||||
gpu::PipelinePointer _boundsPipeline;
|
gpu::PipelinePointer _boundsPipeline;
|
||||||
gpu::BufferPointer _drawBuffer;
|
gpu::BufferPointer _drawBuffer;
|
||||||
|
gpu::BufferPointer _paramsBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawQuadVolumeConfig : public render::JobConfig {
|
class DrawQuadVolumeConfig : public render::JobConfig {
|
||||||
|
@ -95,7 +96,7 @@ protected:
|
||||||
const gpu::BufferView& indices, int indexCount);
|
const gpu::BufferView& indices, int indexCount);
|
||||||
|
|
||||||
gpu::BufferView _meshVertices;
|
gpu::BufferView _meshVertices;
|
||||||
glm::vec3 _color;
|
gpu::BufferPointer _params;
|
||||||
bool _isUpdateEnabled{ true };
|
bool _isUpdateEnabled{ true };
|
||||||
|
|
||||||
static gpu::Stream::FormatPointer _format;
|
static gpu::Stream::FormatPointer _format;
|
||||||
|
|
|
@ -20,7 +20,14 @@
|
||||||
<@include gpu/Color.slh@>
|
<@include gpu/Color.slh@>
|
||||||
<$declareColorWheel()$>
|
<$declareColorWheel()$>
|
||||||
|
|
||||||
layout(location=GPU_UNIFORM_COLOR) uniform vec4 inColor;
|
struct DrawItemBoundsParams {
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(binding=0) uniform drawItemBoundsParamsBuffer {
|
||||||
|
DrawItemBoundsParams params;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ItemBound {
|
struct ItemBound {
|
||||||
vec4 id_boundPos;
|
vec4 id_boundPos;
|
||||||
|
@ -91,10 +98,10 @@ void main(void) {
|
||||||
TransformObject obj = getTransformObject();
|
TransformObject obj = getTransformObject();
|
||||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||||
|
|
||||||
if (inColor.w < 0.0) {
|
if (params.color.w < 0.0) {
|
||||||
varColor = vec4(colorWheel(float(boundID)/(-inColor.w)), 1.0);
|
varColor = vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0);
|
||||||
} else {
|
} else {
|
||||||
varColor = vec4(colorWheel(float(inColor.w)), 1.0);
|
varColor = vec4(colorWheel(float(params.color.w)), 1.0);
|
||||||
}
|
}
|
||||||
varTexcoord = vec2(cubeVec.w, length(boundDim));
|
varTexcoord = vec2(cubeVec.w, length(boundDim));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue