mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 03:56:32 +02:00
Add layering to renderGrid, draw edit grid not layered
This commit is contained in:
parent
791d295578
commit
fd6aa9a78b
5 changed files with 25 additions and 19 deletions
|
@ -25,7 +25,7 @@ Grid = function(opts) {
|
|||
var gridOverlay = Overlays.addOverlay("grid", {
|
||||
dimensions: { x: scale, y: scale, z: scale },
|
||||
visible: false,
|
||||
drawInFront: true,
|
||||
drawInFront: false,
|
||||
color: colors[0],
|
||||
alpha: gridAlpha,
|
||||
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
|
||||
|
@ -132,9 +132,7 @@ Grid = function(opts) {
|
|||
|
||||
|
||||
that.setPosition = function(newPosition, noUpdate) {
|
||||
origin = newPosition;
|
||||
origin.x = 0;
|
||||
origin.z = 0;
|
||||
origin = { x: 0, y: newPosition.y, z: 0 };
|
||||
updateGrid();
|
||||
|
||||
if (!noUpdate) {
|
||||
|
|
|
@ -131,7 +131,7 @@ void AudioScope::render(RenderArgs* renderArgs, int width, int height) {
|
|||
// Grid uses its own pipeline, so draw it before setting another
|
||||
const float GRID_EDGE = 0.005f;
|
||||
geometryCache->renderGrid(batch, glm::vec2(x, y), glm::vec2(x + w, y + h),
|
||||
gridRows, gridCols, GRID_EDGE, gridColor, _audioScopeGrid);
|
||||
gridRows, gridCols, GRID_EDGE, gridColor, true, _audioScopeGrid);
|
||||
|
||||
geometryCache->useSimpleDrawPipeline(batch);
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
|
|
|
@ -76,7 +76,7 @@ void Grid3DOverlay::render(RenderArgs* args) {
|
|||
DependencyManager::get<GeometryCache>()->renderGrid(*batch, minCorner, maxCorner,
|
||||
_minorGridRowDivisions, _minorGridColDivisions, MINOR_GRID_EDGE,
|
||||
_majorGridRowDivisions, _majorGridColDivisions, MAJOR_GRID_EDGE,
|
||||
gridColor);
|
||||
gridColor, _drawInFront);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -569,7 +569,7 @@ void GeometryCache::renderWireSphere(gpu::Batch& batch) {
|
|||
void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||
int majorRows, int majorCols, float majorEdge,
|
||||
int minorRows, int minorCols, float minorEdge,
|
||||
const glm::vec4& color, int id) {
|
||||
const glm::vec4& color, bool isLayered, int id) {
|
||||
static const glm::vec2 MIN_TEX_COORD(0.0f, 0.0f);
|
||||
static const glm::vec2 MAX_TEX_COORD(1.0f, 1.0f);
|
||||
|
||||
|
@ -606,7 +606,7 @@ void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, co
|
|||
}
|
||||
|
||||
// Set the grid pipeline
|
||||
useGridPipeline(batch, registered ? _registeredGridBuffers[id] : _gridBuffers[key]);
|
||||
useGridPipeline(batch, registered ? _registeredGridBuffers[id] : _gridBuffers[key], isLayered);
|
||||
|
||||
renderQuad(batch, minCorner, maxCorner, MIN_TEX_COORD, MAX_TEX_COORD, color, id);
|
||||
}
|
||||
|
@ -1656,20 +1656,27 @@ void GeometryCache::useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend) {
|
|||
}
|
||||
}
|
||||
|
||||
void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer) {
|
||||
void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bool isLayered) {
|
||||
if (!_gridPipeline) {
|
||||
auto vs = gpu::Shader::createVertex(std::string(standardTransformPNTC_vert));
|
||||
auto ps = gpu::Shader::createPixel(std::string(grid_frag));
|
||||
auto program = gpu::Shader::createProgram(vs, ps);
|
||||
gpu::Shader::makeProgram((*program));
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
|
||||
|
||||
_gridPipeline = gpu::Pipeline::create(program, state);
|
||||
_gridSlot = program->getBuffers().findLocation("gridBuffer");
|
||||
|
||||
auto stateLayered = std::make_shared<gpu::State>();
|
||||
stateLayered->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
|
||||
_gridPipelineLayered = gpu::Pipeline::create(program, stateLayered);
|
||||
|
||||
auto state = std::make_shared<gpu::State>(stateLayered->getValues());
|
||||
const float DEPTH_BIAS = 0.001f;
|
||||
state->setDepthBias(DEPTH_BIAS);
|
||||
state->setDepthTest(true, false, gpu::LESS_EQUAL);
|
||||
_gridPipeline = gpu::Pipeline::create(program, state);
|
||||
}
|
||||
batch.setPipeline(_gridPipeline);
|
||||
|
||||
gpu::PipelinePointer pipeline = isLayered ? _gridPipelineLayered : _gridPipeline;
|
||||
batch.setPipeline(pipeline);
|
||||
batch.setUniformBuffer(_gridSlot, gridBuffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -207,10 +207,10 @@ public:
|
|||
void renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||
int majorRows, int majorCols, float majorEdge,
|
||||
int minorRows, int minorCols, float minorEdge,
|
||||
const glm::vec4& color, int id = UNKNOWN_ID);
|
||||
const glm::vec4& color, bool isLayered, int id = UNKNOWN_ID);
|
||||
void renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||
int rows, int cols, float edge, const glm::vec4& color, int id = UNKNOWN_ID) {
|
||||
renderGrid(batch, minCorner, maxCorner, rows, cols, edge, 0, 0, 0.0f, color, id);
|
||||
int rows, int cols, float edge, const glm::vec4& color, bool isLayered, int id = UNKNOWN_ID) {
|
||||
renderGrid(batch, minCorner, maxCorner, rows, cols, edge, 0, 0, 0.0f, color, isLayered, id);
|
||||
}
|
||||
|
||||
void renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id = UNKNOWN_ID);
|
||||
|
@ -325,8 +325,9 @@ private:
|
|||
glm::vec4 edge;
|
||||
};
|
||||
using GridBuffer = gpu::BufferView;
|
||||
void useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer);
|
||||
void useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bool isLayered);
|
||||
gpu::PipelinePointer _gridPipeline;
|
||||
gpu::PipelinePointer _gridPipelineLayered;
|
||||
int _gridSlot;
|
||||
|
||||
class BatchItemDetails {
|
||||
|
|
Loading…
Reference in a new issue