aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2019-04-24 10:36:20 -0400
committerGitHub <noreply@github.com>2019-04-24 10:36:20 -0400
commit4736b0f710021856fdfbcbef1d7b685d7eb363c7 (patch)
treece78e95facac0231d644e27b5c6272fb65695ee8 /samples
parentfffbb43bded183d6ee1b90e9ef765ba5e4168710 (diff)
downloadamber-4736b0f710021856fdfbcbef1d7b685d7eb363c7.tar.gz
Add push constant graphics tests. (#492)
Currently all the push constant tests are compute based. This CL adds a graphics push constant test in both VkScript and AmberScript. (Along the way, the error message for outputting an image buffer was cleaned up to make it clearer what failed.)
Diffstat (limited to 'samples')
-rw-r--r--samples/png.cc6
-rw-r--r--samples/ppm.cc17
-rw-r--r--samples/ppm.h9
3 files changed, 21 insertions, 11 deletions
diff --git a/samples/png.cc b/samples/png.cc
index bddb3a7..b23e002 100644
--- a/samples/png.cc
+++ b/samples/png.cc
@@ -50,7 +50,11 @@ amber::Result ConvertToPNG(uint32_t width,
uint32_t height,
const std::vector<amber::Value>& values,
std::vector<uint8_t>* buffer) {
- assert(values.size() == width * height);
+ if (values.size() != (width * height)) {
+ return amber::Result("Values size (" + std::to_string(values.size()) +
+ ") != " + "width * height (" +
+ std::to_string(width * height) + ")");
+ }
std::vector<uint8_t> data;
diff --git a/samples/ppm.cc b/samples/ppm.cc
index db53835..9cd3ae8 100644
--- a/samples/ppm.cc
+++ b/samples/ppm.cc
@@ -20,7 +20,6 @@
#include "amber/value.h"
namespace ppm {
-
namespace {
const uint32_t kMaximumColorValue = 255;
@@ -39,11 +38,15 @@ uint8_t byte2(uint32_t word) {
} // namespace
-void ConvertToPPM(uint32_t width,
- uint32_t height,
- const std::vector<amber::Value>& values,
- std::vector<uint8_t>* buffer) {
- assert(values.size() == width * height);
+amber::Result ConvertToPPM(uint32_t width,
+ uint32_t height,
+ const std::vector<amber::Value>& values,
+ std::vector<uint8_t>* buffer) {
+ if (values.size() != (width * height)) {
+ return amber::Result("Values size (" + std::to_string(values.size()) +
+ ") != " + "width * height (" +
+ std::to_string(width * height) + ")");
+ }
// Write PPM header
std::string image = "P6\n";
@@ -62,6 +65,8 @@ void ConvertToPPM(uint32_t width,
buffer->push_back(byte0(pixel)); // B
// PPM does not support alpha channel
}
+
+ return {};
}
} // namespace ppm
diff --git a/samples/ppm.h b/samples/ppm.h
index b8e680d..0ea01e4 100644
--- a/samples/ppm.h
+++ b/samples/ppm.h
@@ -20,16 +20,17 @@
#include <vector>
#include "amber/amber.h"
+#include "amber/result.h"
namespace ppm {
/// Converts the image of dimensions |width| and |height| and with pixels stored
/// in row-major order in |values| with format B8G8R8A8 into PPM format,
/// returning the PPM binary in |buffer|.
-void ConvertToPPM(uint32_t width,
- uint32_t height,
- const std::vector<amber::Value>& values,
- std::vector<uint8_t>* buffer);
+amber::Result ConvertToPPM(uint32_t width,
+ uint32_t height,
+ const std::vector<amber::Value>& values,
+ std::vector<uint8_t>* buffer);
} // namespace ppm