Skip to content

Commit c3a0076

Browse files
author
tpat
committed
Merge master into dipole_movement
2 parents 1436bcf + 0c4af00 commit c3a0076

File tree

22 files changed

+1382
-863
lines changed

22 files changed

+1382
-863
lines changed

src/Externals/spire/bserialize/BSerialize.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ class SCISHARE BSerialize
4545
{
4646
return detail::SerializeType<T>::write(mMsg, mMsgSize, &mOffset, val);
4747
}
48-
/// @}
48+
49+
template <typename T>
50+
inline void writeUnsafe(const T& val)
51+
{
52+
detail::writeTypeToMemoryUnsafe(mMsg, mOffset, val);
53+
}
4954

5055
/// Retrieves the current buffer offset. If we are writing to the buffer,
5156
/// then this is the size of the data currently written. If we are reading,

src/Externals/spire/bserialize/src/BSerializeDetail.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ bool writeTypeToMemory(char* msg, size_t msgSize, size_t* offset_out, const T& v
5252
return true;
5353
}
5454

55+
template <typename T>
56+
inline void writeTypeToMemoryUnsafe(char* msg, size_t& offset_out, const T& v)
57+
{
58+
std::memcpy(msg + offset_out, &v, sizeof(T));
59+
offset_out += sizeof(T);
60+
}
61+
5562
template <typename T>
5663
class SerializeType
5764
{
@@ -195,6 +202,9 @@ class SerializeType<float>
195202

196203
static bool write(char* msg, size_t msgSize, size_t* offset_out, const Type& in)
197204
{ return writeTypeToMemory<Type>(msg, msgSize, offset_out, in); }
205+
206+
// static bool writeUnsafe(char* msg, size_t* offset_out, const Type& in)
207+
// { return writeTypeToMemoryUnsafe<Type>(msg, offset_out, in); }
198208
};
199209

200210
//------------------------------------------------------------------------------

src/Externals/spire/es-render/TextureMan.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,51 @@ namespace ren {
159159
return tex;
160160
}
161161

162+
ren::Texture TextureMan::createTexture(
163+
const std::string& assetName,
164+
GLint internalformat,
165+
GLsizei width,
166+
GLsizei height,
167+
GLenum format,
168+
GLenum type,
169+
const std::vector<uint8_t>& data)
170+
{
171+
GLuint texID;
172+
auto it = mNameToGL.find(assetName);
173+
if (it != mNameToGL.end())
174+
{
175+
texID = it->second;
176+
}
177+
else
178+
{
179+
GL(glGenTextures(1, &texID));
180+
GL(glBindTexture(GL_TEXTURE_2D, texID));
181+
GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
182+
GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
183+
GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
184+
GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
185+
GL(glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type,
186+
(const GLvoid*)(&data[0])));
187+
188+
mGLToName.insert(std::make_pair(texID, assetName));
189+
mNameToGL.insert(std::make_pair(assetName, texID));
190+
191+
GL(glBindTexture(GL_TEXTURE_2D, 0));
192+
}
193+
194+
ren::Texture tex;
195+
tex.glid = texID;
196+
tex.textureType = GL_TEXTURE_2D;
197+
tex.textureWidth = width;
198+
tex.textureHeight = height;
199+
tex.textureDepth = 1;
200+
tex.internalFormat = internalformat;
201+
tex.format = format;
202+
tex.type = type;
203+
tex.filter = GL_LINEAR;
204+
return tex;
205+
}
206+
162207
bool TextureMan::resizeTexture(
163208
ren::Texture &tex, GLsizei textureWidth,
164209
GLsizei textureHeight)

src/Externals/spire/es-render/TextureMan.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ namespace ren {
4646
GLsizei textureWidth, GLsizei textureHeight,
4747
const std::vector<uint8_t>& bitmap);
4848

49+
ren::Texture createTexture(
50+
const std::string& assetName,
51+
GLint internalformat,
52+
GLsizei width,
53+
GLsizei height,
54+
GLenum format,
55+
GLenum type,
56+
const std::vector<uint8_t>& data);
57+
4958
//resize texture
5059
bool resizeTexture(
5160
ren::Texture &tex, GLsizei textureWidth,

src/Externals/spire/var-buffer/VarBuffer.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ VarBuffer::VarBuffer() :
1010
mBuffer(1024),
1111
mBufferSize(1024)
1212
{
13-
RENDERER_LOG("VarBuffer ctor (mBufferSize {})", mBufferSize);
1413
mSerializer.reset(new spire::BSerialize(getBuffer(), mBufferSize));
1514
}
1615

1716
VarBuffer::VarBuffer(size_t size) :
1817
mBuffer(size),
1918
mBufferSize(size)
2019
{
21-
RENDERER_LOG("VarBuffer ctor (mBufferSize {})", size);
2220
mSerializer.reset(new spire::BSerialize(getBuffer(), mBufferSize));
2321
}
2422

@@ -27,31 +25,20 @@ void VarBuffer::clear()
2725
mSerializer->setOffset(0);
2826
}
2927

30-
/// Writes \p numBytes of \p bytes.
3128
void VarBuffer::writeBytes(const char* bytes, size_t numBytes)
3229
{
33-
RENDERER_LOG("VarBuffer writeBytes (bytes {}, numBytes {})", bytes, numBytes);
34-
// Resize the buffer if necessary.
3530
while (mSerializer->getOffset() + numBytes > mBufferSize)
36-
{
3731
resize();
38-
}
3932

4033
mSerializer->writeBytes(bytes, numBytes);
4134
}
4235

43-
/// Writes a null terminated string.
4436
void VarBuffer::writeNullTermString(const char* str)
4537
{
46-
RENDERER_LOG("VarBuffer writeNullTermString (str {})", str);
47-
4838
size_t stringLength = std::strlen(str);
4939

50-
// Resize the buffer if necessary.
5140
while (mSerializer->getOffset() + stringLength + 1 > mBufferSize)
52-
{
5341
resize();
54-
}
5542

5643
mSerializer->writeNullTermString(str);
5744
}
@@ -61,12 +48,8 @@ void VarBuffer::resize()
6148
mBufferSize *= 2;
6249
mBuffer.resize(mBufferSize);
6350

64-
RENDERER_LOG("VarBuffer resize (oldSize {}, newSize {})", mBufferSize/2, mBufferSize);
65-
66-
// Record offset before we destroy and recreate the serializer.
6751
size_t bufferOffset = mSerializer->getOffset();
6852

69-
// Create a new serializer and reset its offset.
7053
mSerializer.reset(new spire::BSerialize(getBuffer(), mBufferSize));
7154
mSerializer->setOffset(bufferOffset);
7255
}

src/Externals/spire/var-buffer/VarBuffer.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class SCISHARE VarBuffer final
4242
}
4343
}
4444

45+
template <typename T>
46+
inline void writeUnsafe(const T& val)
47+
{
48+
mSerializer->writeUnsafe(val);
49+
}
50+
51+
4552
/// Clears all data currently written to the var buffer.
4653
void clear();
4754

src/Graphics/Datatypes/GeometryImpl.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,34 @@ void CompositeGeometryObject::addToList(GeometryBaseHandle handle, GeomList& lis
5050
list.insert(geoms_.begin(), geoms_.end());
5151
}
5252
}
53+
54+
void SpireSubPass::addUniform(const std::string& name, const glm::vec4& vector)
55+
{
56+
for (auto& i : mUniforms)
57+
{
58+
if (i.name == name && i.type == Uniform::UniformType::UNIFORM_VEC4)
59+
{
60+
i.data = vector;
61+
return;
62+
}
63+
}
64+
mUniforms.push_back(Uniform(name, vector));
65+
}
66+
67+
void SpireSubPass::addOrModifyUniform(const Uniform& uniform)
68+
{
69+
for (auto& i : mUniforms)
70+
{
71+
if (i.name == uniform.name && i.type == uniform.type)
72+
{
73+
i.data = uniform.data;
74+
return;
75+
}
76+
}
77+
mUniforms.push_back(uniform);
78+
}
79+
80+
void SpireSubPass::addUniform(const Uniform& uniform)
81+
{
82+
mUniforms.push_back(uniform);
83+
}

src/Graphics/Datatypes/GeometryImpl.h

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ namespace SCIRun {
145145
std::vector<uint8_t> bitmap;
146146
};
147147

148+
struct SpireTexture2D
149+
{
150+
SpireTexture2D() : name(""), width(0), height(0) {}
151+
SpireTexture2D(std::string name , size_t width, size_t height, const char* data) :
152+
name(name),
153+
width(width),
154+
height(height)
155+
{
156+
size_t size = width*height*4;
157+
bitmap.resize(size);
158+
std::copy(data, data + size, bitmap.begin());
159+
}
160+
std::string name;
161+
size_t width;
162+
size_t height;
163+
std::vector<uint8_t> bitmap;
164+
};
165+
166+
148167
/// Defines a Spire object 'pass'.
149168
struct SpireSubPass
150169
{
@@ -153,7 +172,7 @@ namespace SCIRun {
153172
const std::string& iboName, const std::string& program,
154173
ColorScheme scheme, const RenderState& state,
155174
RenderType renType, const SpireVBO& vbo, const SpireIBO& ibo,
156-
const SpireText& text) :
175+
const SpireText& text, const SpireTexture2D& texture = SpireTexture2D()) :
157176
passName(name),
158177
vboName(vboName),
159178
iboName(iboName),
@@ -163,6 +182,7 @@ namespace SCIRun {
163182
vbo(vbo),
164183
ibo(ibo),
165184
text(text),
185+
texture(texture),
166186
scalar(1.0),
167187
mColorScheme(scheme)
168188
{}
@@ -184,8 +204,10 @@ namespace SCIRun {
184204
SpireVBO vbo;
185205
SpireIBO ibo;
186206
SpireText text;//draw a string (usually single character) on geometry
207+
SpireTexture2D texture;
187208
double scalar;
188209

210+
189211
struct Uniform
190212
{
191213
enum class UniformType
@@ -195,16 +217,17 @@ namespace SCIRun {
195217
};
196218

197219
Uniform() : type(UniformType::UNIFORM_SCALAR) {}
198-
Uniform(const std::string& nameIn, float d) :
220+
221+
Uniform(const std::string& nameIn, float scalar) :
199222
name(nameIn),
200223
type(UniformType::UNIFORM_SCALAR),
201-
data(d, 0.0f, 0.0f, 0.0f)
224+
data(scalar, 0.0f, 0.0f, 0.0f)
202225
{}
203226

204-
Uniform(const std::string& nameIn, const glm::vec4& vec) :
227+
Uniform(const std::string& nameIn, const glm::vec4& vector) :
205228
name(nameIn),
206229
type(UniformType::UNIFORM_VEC4),
207-
data(vec)
230+
data(vector)
208231
{}
209232

210233
std::string name;
@@ -215,40 +238,9 @@ namespace SCIRun {
215238
std::vector<Uniform> mUniforms;
216239
ColorScheme mColorScheme;
217240

218-
void addUniform(const std::string& name, float scalar)
219-
{
220-
bool existed = false;
221-
for (auto& i : mUniforms)
222-
{
223-
if (i.name == name && i.type == Uniform::UniformType::UNIFORM_SCALAR)
224-
{
225-
i.data.x = scalar;
226-
existed = true;
227-
}
228-
}
229-
if (!existed)
230-
mUniforms.push_back(Uniform(name, scalar));
231-
}
232-
233-
void addUniform(const std::string& name, const glm::vec4& vector)
234-
{
235-
bool existed = false;
236-
for (auto& i : mUniforms)
237-
{
238-
if (i.name == name && i.type == Uniform::UniformType::UNIFORM_VEC4)
239-
{
240-
i.data = vector;
241-
existed = true;
242-
}
243-
}
244-
if (!existed)
245-
mUniforms.push_back(Uniform(name, vector));
246-
}
247-
248-
void addUniform(const Uniform& uniform)
249-
{
250-
mUniforms.push_back(uniform);
251-
}
241+
void addUniform(const std::string& name, const glm::vec4& vector);
242+
void addOrModifyUniform(const Uniform& uniform);
243+
void addUniform(const Uniform& uniform);
252244
};
253245

254246
using VBOList = std::list<SpireVBO>;
@@ -268,21 +260,18 @@ namespace SCIRun {
268260
const PassList& passes() const { return mPasses; }
269261
PassList& passes() { return mPasses; }
270262

271-
bool isClippable() const { return isClippable_; }
263+
bool isClippable() const {return isClippable_;}
272264

273-
void setColorMap(const std::string& name) { mColorMap = name; }
265+
void setColorMap(const std::string& name) { }
274266
boost::optional<std::string> colorMap() const { return mColorMap; }
267+
275268
private:
276269
VBOList mVBOs; ///< Array of vertex buffer objects.
277270
IBOList mIBOs; ///< Array of index buffer objects.
278-
279-
/// List of passes to setup.
280-
PassList mPasses;
281-
282-
/// Optional colormap name.
271+
PassList mPasses; /// List of passes to setup.
272+
bool isClippable_;
283273
boost::optional<std::string> mColorMap;
284274

285-
bool isClippable_;
286275
};
287276

288277
typedef boost::shared_ptr<GeometryObjectSpire> GeometryHandle;

0 commit comments

Comments
 (0)