Skip to content

Commit 8ed4767

Browse files
authored
Merge branch 'master' into cameraSaveFix
2 parents 3cfb573 + 2229eb7 commit 8ed4767

File tree

6 files changed

+168
-57
lines changed

6 files changed

+168
-57
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace spire {
88

99
VarBuffer::VarBuffer() :
1010
mBuffer(1024),
11-
mBufferSize(1024)
11+
mBufferSize(1024)
1212
{
1313
RENDERER_LOG("VarBuffer ctor (mBufferSize {})", mBufferSize);
1414
mSerializer.reset(new spire::BSerialize(getBuffer(), mBufferSize));
1515
}
1616

17-
VarBuffer::VarBuffer(uint32_t size) :
17+
VarBuffer::VarBuffer(size_t size) :
1818
mBuffer(size),
1919
mBufferSize(size)
2020
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class SCISHARE VarBuffer final
2121
VarBuffer();
2222

2323
// Preallocate the variable buffer to the preset size.
24-
explicit VarBuffer(uint32_t size);
24+
explicit VarBuffer(size_t size);
2525

26-
/// \todo Add flag which will swap bytes when reading out of or into buffer.
26+
// todo Add flag which will swap bytes when reading out of or into buffer.
2727

28-
/// Writes \p numBytes of \p bytes.
28+
// Writes numBytes of bytes.
2929
void writeBytes(const char* bytes, size_t numBytes);
3030

3131
/// Writes a null terminated string.
@@ -53,7 +53,7 @@ class SCISHARE VarBuffer final
5353
size_t getBufferSize() const {return mSerializer->getOffset();}
5454

5555
/// Retrieves currently allocated size of the buffer.
56-
int getAllocatedSize() const {return mBufferSize;}
56+
size_t getAllocatedSize() const {return mBufferSize;}
5757

5858
private:
5959

@@ -65,7 +65,7 @@ class SCISHARE VarBuffer final
6565
static uint16_t deserializeUInt16(const char* msg, int msgLen, int* offset_out);
6666

6767
std::vector<char> mBuffer; ///< buffer
68-
int mBufferSize; ///< Absolute size of mBuffer in bytes.
68+
size_t mBufferSize; ///< Absolute size of mBuffer in bytes.
6969

7070
std::unique_ptr<spire::BSerialize> mSerializer;
7171
};

src/Graphics/Datatypes/GeometryImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace SCIRun {
8585
SpireVBO() : numElements(0), onGPU(false) {}
8686
SpireVBO(const std::string& vboName, const std::vector<AttributeData> attribs,
8787
std::shared_ptr<spire::VarBuffer> vboData,
88-
int64_t numVBOElements, const Core::Geometry::BBox& bbox, bool placeOnGPU) :
88+
size_t numVBOElements, const Core::Geometry::BBox& bbox, bool placeOnGPU) :
8989
name(vboName),
9090
attributes(attribs),
9191
data(vboData),
@@ -96,8 +96,8 @@ namespace SCIRun {
9696

9797
std::string name;
9898
std::vector<AttributeData> attributes;
99-
std::shared_ptr<spire::VarBuffer> data; // Change to unique_ptr w/ move semantics (possibly).
100-
int64_t numElements;
99+
std::shared_ptr<spire::VarBuffer> data; // Change to unique_ptr w/ move semantics (possibly).
100+
size_t numElements;
101101
Core::Geometry::BBox boundingBox;
102102
bool onGPU;
103103
};
@@ -123,7 +123,7 @@ namespace SCIRun {
123123
std::string name;
124124
size_t indexSize;
125125
PRIMITIVE prim;
126-
std::shared_ptr<spire::VarBuffer> data; // Change to unique_ptr w/ move semantics (possibly).
126+
std::shared_ptr<spire::VarBuffer> data; // Change to unique_ptr w/ move semantics (possibly).
127127
};
128128

129129
struct SpireText

src/Interface/Modules/Render/Tests/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#
22
# For more information, please see: http://software.sci.utah.edu
3-
#
3+
#
44
# The MIT License
5-
#
5+
#
66
# Copyright (c) 2015 Scientific Computing and Imaging Institute,
77
# University of Utah.
8-
#
9-
#
8+
#
9+
#
1010
# Permission is hereby granted, free of charge, to any person obtaining a
1111
# copy of this software and associated documentation files (the "Software"),
1212
# to deal in the Software without restriction, including without limitation
1313
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1414
# and/or sell copies of the Software, and to permit persons to whom the
1515
# Software is furnished to do so, subject to the following conditions:
16-
#
16+
#
1717
# The above copyright notice and this permission notice shall be included
18-
# in all copies or substantial portions of the Software.
19-
#
18+
# in all copies or substantial portions of the Software.
19+
#
2020
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2121
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2222
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
@@ -28,6 +28,7 @@
2828

2929
SET(Interface_Modules_Render_Tests_SRCS
3030
SRInterfaceTests.cc
31+
VarBufferTests.cc
3132
)
3233

3334
SCIRUN_ADD_UNIT_TEST(Interface_Modules_Render_Tests
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include <spire/var-buffer/VarBuffer.hpp>
2+
#include <bserialize/BSerialize.hpp>
3+
#include <gtest/gtest.h>
4+
#include <memory>
5+
#include <cstring>
6+
7+
using namespace spire;
8+
9+
TEST(VarBufferTest, BasicSerialization)
10+
{
11+
VarBuffer vb;
12+
13+
// Proceed close to 1024 limit.
14+
const size_t emptySize = 1020;
15+
char empty[emptySize];
16+
std::memset(empty, 0, emptySize);
17+
18+
vb.writeBytes(empty, emptySize);
19+
20+
// After this write, we are at 1024.
21+
uint32_t v1 = 3;
22+
double v2 = 5.483;
23+
float v3 = 8293.09;
24+
int32_t v4 = -323;
25+
uint16_t v5 = 8924;
26+
std::string v6 = "This is a test string.";
27+
uint8_t v7 = 98;
28+
29+
vb.write(v1);
30+
31+
// Continue writing.
32+
vb.write(v2);
33+
vb.write(v3);
34+
vb.write(v4);
35+
vb.writeNullTermString("Blah!");
36+
vb.write(v5);
37+
vb.write(v6);
38+
vb.write(v7);
39+
40+
// Now take the buffer and stuff it into BSerialize
41+
BSerialize sin(vb.getBuffer(), vb.getBufferSize());
42+
sin.readBytes(emptySize);
43+
EXPECT_EQ(v1, sin.read<uint32_t>());
44+
EXPECT_EQ(v2, sin.read<double>());
45+
EXPECT_EQ(v3, sin.read<float>());
46+
EXPECT_EQ(v4, sin.read<int32_t>());
47+
EXPECT_EQ(std::string("Blah!"), std::string(sin.readNullTermString()));
48+
EXPECT_EQ(v5, sin.read<uint16_t>());
49+
EXPECT_EQ(v6, sin.read<std::string>());
50+
EXPECT_EQ(v7, sin.read<uint8_t>());
51+
}
52+
53+
TEST(VarBufferTest, TestPreallocatedSize)
54+
{
55+
VarBuffer vb(5000);
56+
57+
EXPECT_EQ(5000, vb.getAllocatedSize());
58+
59+
// Proceed close to 1024 limit.
60+
const size_t emptySize = 1020;
61+
char empty[emptySize];
62+
std::memset(empty, 0, emptySize);
63+
64+
vb.writeBytes(empty, emptySize);
65+
66+
// After this write, we are at 1024.
67+
uint32_t v1 = 3;
68+
double v2 = 5.483;
69+
float v3 = 8293.09;
70+
int32_t v4 = -323;
71+
uint16_t v5 = 8924;
72+
std::string v6 = "This is a test string.";
73+
uint8_t v7 = 98;
74+
75+
vb.write(v1);
76+
77+
// Continue writing.
78+
vb.write(v2);
79+
vb.write(v3);
80+
vb.write(v4);
81+
vb.writeNullTermString("Blah!");
82+
vb.write(v5);
83+
vb.write(v6);
84+
vb.write(v7);
85+
86+
// Now take the buffer and stuff it into BSerialize
87+
BSerialize sin(vb.getBuffer(), vb.getBufferSize());
88+
sin.readBytes(emptySize);
89+
EXPECT_EQ(v1, sin.read<uint32_t>());
90+
EXPECT_EQ(v2, sin.read<double>());
91+
EXPECT_EQ(v3, sin.read<float>());
92+
EXPECT_EQ(v4, sin.read<int32_t>());
93+
EXPECT_EQ(std::string("Blah!"), std::string(sin.readNullTermString()));
94+
EXPECT_EQ(v5, sin.read<uint16_t>());
95+
EXPECT_EQ(v6, sin.read<std::string>());
96+
EXPECT_EQ(v7, sin.read<uint8_t>());
97+
98+
// Check to ensure that we are still at size 5000.
99+
EXPECT_EQ(5000, vb.getAllocatedSize());
100+
}
101+
102+
103+
//takes on the order of 10 second to run becasue of the large allocation size so I dsiabeld it for now
104+
TEST(VarBufferTest, DISABLED_TestLargeAllocation)
105+
{
106+
size_t size = 1ull << 32;
107+
EXPECT_GT(size, static_cast<size_t>(std::numeric_limits<uint32_t>::max()));
108+
VarBuffer vb(size);
109+
EXPECT_EQ(size, vb.getAllocatedSize());
110+
}

0 commit comments

Comments
 (0)