mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Add textures property to polyline
This commit is contained in:
parent
2b07daa976
commit
2fe9af54d4
4 changed files with 35 additions and 9 deletions
|
@ -36,7 +36,6 @@ PolyLineEntityItem(entityItemID, properties) {
|
|||
|
||||
gpu::PipelinePointer RenderablePolyLineEntityItem::_pipeline;
|
||||
gpu::Stream::FormatPointer RenderablePolyLineEntityItem::_format;
|
||||
gpu::TexturePointer RenderablePolyLineEntityItem::_texture;
|
||||
int32_t RenderablePolyLineEntityItem::PAINTSTROKE_GPU_SLOT;
|
||||
|
||||
void RenderablePolyLineEntityItem::createPipeline() {
|
||||
|
@ -44,9 +43,6 @@ void RenderablePolyLineEntityItem::createPipeline() {
|
|||
static const int COLOR_OFFSET = 24;
|
||||
static const int TEXTURE_OFFSET = 28;
|
||||
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
QString path = PathUtils::resourcesPath() + "images/paintStroke.png";
|
||||
_texture = textureCache->getImageTexture(path);
|
||||
_format.reset(new gpu::Stream::Format());
|
||||
_format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
||||
_format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET);
|
||||
|
@ -132,6 +128,13 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
|||
createPipeline();
|
||||
}
|
||||
|
||||
if (!_texture || _texturesChangedFlag) {
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
QString path = _textures.isEmpty() ? PathUtils::resourcesPath() + "images/paintStroke.png" : _textures;
|
||||
_texture = textureCache->getTexture(QUrl(path));
|
||||
_texturesChangedFlag = false;
|
||||
}
|
||||
|
||||
PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render");
|
||||
Q_ASSERT(getType() == EntityTypes::PolyLine);
|
||||
|
||||
|
@ -147,7 +150,11 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
|||
batch.setModelTransform(transform);
|
||||
|
||||
batch.setPipeline(_pipeline);
|
||||
batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture);
|
||||
if (_texture->isLoaded()) {
|
||||
batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture->getGPUTexture());
|
||||
} else {
|
||||
batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, args->_whiteTexture);
|
||||
}
|
||||
|
||||
batch.setInputFormat(_format);
|
||||
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
#ifndef hifi_RenderablePolyLineEntityItem_h
|
||||
#define hifi_RenderablePolyLineEntityItem_h
|
||||
|
||||
|
||||
#include <gpu/Batch.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <PolyLineEntityItem.h>
|
||||
#include "RenderableEntityItem.h"
|
||||
#include <GeometryCache.h>
|
||||
#include <TextureCache.h>
|
||||
|
||||
#include <QReadWriteLock>
|
||||
|
||||
|
||||
|
@ -29,9 +32,10 @@ public:
|
|||
|
||||
SIMPLE_RENDERABLE();
|
||||
|
||||
NetworkTexturePointer _texture;
|
||||
|
||||
static gpu::PipelinePointer _pipeline;
|
||||
static gpu::Stream::FormatPointer _format;
|
||||
static gpu::TexturePointer _texture;
|
||||
static int32_t PAINTSTROKE_GPU_SLOT;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -37,7 +37,8 @@ _pointsChanged(true),
|
|||
_points(QVector<glm::vec3>(0.0f)),
|
||||
_vertices(QVector<glm::vec3>(0.0f)),
|
||||
_normals(QVector<glm::vec3>(0.0f)),
|
||||
_strokeWidths(QVector<float>(0.0f))
|
||||
_strokeWidths(QVector<float>(0.0f)),
|
||||
_textures("")
|
||||
{
|
||||
_type = EntityTypes::PolyLine;
|
||||
_created = properties.getCreated();
|
||||
|
@ -56,6 +57,7 @@ EntityItemProperties PolyLineEntityItem::getProperties(EntityPropertyFlags desir
|
|||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures);
|
||||
|
||||
properties._glowLevel = getGlowLevel();
|
||||
properties._glowLevelChanged = false;
|
||||
|
@ -72,6 +74,7 @@ bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) {
|
|||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures);
|
||||
|
||||
if (somethingChanged) {
|
||||
bool wantDebug = false;
|
||||
|
@ -196,6 +199,7 @@ int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* da
|
|||
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
|
||||
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
|
||||
READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
|
||||
READ_ENTITY_PROPERTY(PROP_TEXTURES, QString, setTextures);
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
@ -209,6 +213,7 @@ EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParam
|
|||
requestedProperties += PROP_LINE_POINTS;
|
||||
requestedProperties += PROP_NORMALS;
|
||||
requestedProperties += PROP_STROKE_WIDTHS;
|
||||
requestedProperties += PROP_TEXTURES;
|
||||
return requestedProperties;
|
||||
}
|
||||
|
||||
|
@ -228,6 +233,7 @@ void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, Encode
|
|||
APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints());
|
||||
APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals());
|
||||
APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths());
|
||||
APPEND_ENTITY_PROPERTY(PROP_TEXTURES, getTextures());
|
||||
}
|
||||
|
||||
void PolyLineEntityItem::debugDump() const {
|
||||
|
|
|
@ -67,7 +67,14 @@ class PolyLineEntityItem : public EntityItem {
|
|||
|
||||
bool setStrokeWidths(const QVector<float>& strokeWidths);
|
||||
const QVector<float>& getStrokeWidths() const{ return _strokeWidths; }
|
||||
|
||||
|
||||
const QString& getTextures() const { return _textures; }
|
||||
void setTextures(const QString& textures) {
|
||||
if (_textures != textures) {
|
||||
_textures = textures;
|
||||
_texturesChangedFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; }
|
||||
|
||||
|
@ -90,6 +97,8 @@ class PolyLineEntityItem : public EntityItem {
|
|||
QVector<glm::vec3> _vertices;
|
||||
QVector<glm::vec3> _normals;
|
||||
QVector<float> _strokeWidths;
|
||||
QString _textures;
|
||||
bool _texturesChangedFlag { false };
|
||||
mutable QReadWriteLock _quadReadWriteLock;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue