Remove simple draw task uniforms

This commit is contained in:
Brad Davis 2018-08-23 15:36:32 -07:00
parent ac84a498b3
commit c8eb4da6b6
5 changed files with 40 additions and 18 deletions

View file

@ -13,12 +13,16 @@
// 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;
void main(void) {
outFragColor = color;
outFragColor = params.color;
}

View file

@ -13,14 +13,19 @@
// 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(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) out vec4 outFragColor;
void main(void) {
outFragColor = texture(colorMap, varTexCoord0) * color;
outFragColor = texture(colorMap, varTexCoord0) * params.color;
}

View file

@ -184,8 +184,13 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
_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) {
args->_batch = &batch;
@ -202,7 +207,7 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
batch.setPipeline(getPipeline());
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);
static const int NUM_VERTICES_PER_CUBE = 24;
@ -212,9 +217,10 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
gpu::Stream::FormatPointer DrawQuadVolume::_format;
DrawQuadVolume::DrawQuadVolume(const glm::vec3& color) :
_color{ color } {
DrawQuadVolume::DrawQuadVolume(const glm::vec3& color) {
_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) {
_format = std::make_shared<gpu::Stream::Format>();
_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.setViewTransform(viewMat);
batch.setPipeline(getPipeline());
batch._glUniform4f(0, _color.x, _color.y, _color.z, 1.0f);
batch.setUniformBuffer(0, _params);
batch.setInputFormat(_format);
batch.setInputBuffer(gpu::Stream::POSITION, _meshVertices);
batch.setIndexBuffer(indices);

View file

@ -66,6 +66,7 @@ private:
const gpu::PipelinePointer getPipeline();
gpu::PipelinePointer _boundsPipeline;
gpu::BufferPointer _drawBuffer;
gpu::BufferPointer _paramsBuffer;
};
class DrawQuadVolumeConfig : public render::JobConfig {
@ -95,7 +96,7 @@ protected:
const gpu::BufferView& indices, int indexCount);
gpu::BufferView _meshVertices;
glm::vec3 _color;
gpu::BufferPointer _params;
bool _isUpdateEnabled{ true };
static gpu::Stream::FormatPointer _format;

View file

@ -20,7 +20,14 @@
<@include gpu/Color.slh@>
<$declareColorWheel()$>
layout(location=GPU_UNIFORM_COLOR) uniform vec4 inColor;
struct DrawItemBoundsParams {
vec4 color;
};
layout(binding=0) uniform drawItemBoundsParamsBuffer {
DrawItemBoundsParams params;
};
struct ItemBound {
vec4 id_boundPos;
@ -91,10 +98,10 @@ void main(void) {
TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
if (inColor.w < 0.0) {
varColor = vec4(colorWheel(float(boundID)/(-inColor.w)), 1.0);
if (params.color.w < 0.0) {
varColor = vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0);
} else {
varColor = vec4(colorWheel(float(inColor.w)), 1.0);
varColor = vec4(colorWheel(float(params.color.w)), 1.0);
}
varTexcoord = vec2(cubeVec.w, length(boundDim));