aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/utils/rgb_color.cpp64
-rw-r--r--src/utils/rgb_color.hpp13
2 files changed, 75 insertions, 2 deletions
diff --git a/src/utils/rgb_color.cpp b/src/utils/rgb_color.cpp
index ea8327e1..2e8954c0 100644
--- a/src/utils/rgb_color.cpp
+++ b/src/utils/rgb_color.cpp
@@ -27,15 +27,47 @@
namespace usdx
{
RgbColor::RgbColor(int red, int green, int blue)
- : red(red / 255.0f), green(green / 255.0f), blue(blue / 255.0f)
+ : red(red / 255.0f), green(green / 255.0f), blue(blue / 255.0f),
+ array(NULL), array_length(0)
{
}
RgbColor::RgbColor(float red, float green, float blue)
- : red(red), green(green), blue(blue)
+ : red(red), green(green), blue(blue), array(NULL), array_length(0)
{
}
+ RgbColor::RgbColor(const RgbColor& color)
+ : red(color.red), green(color.green), blue(color.blue), array(NULL),
+ array_length(0)
+ {
+ }
+
+ RgbColor::~RgbColor()
+ {
+ if (array != NULL) {
+ delete[] array;
+ array = NULL;
+ }
+ }
+
+ RgbColor& RgbColor::operator=(const RgbColor& color)
+ {
+ if (this != &color) {
+ red = color.red;
+ green = color.green;
+ blue = color.blue;
+ array_length = 0;
+
+ if (array != NULL) {
+ delete[] array;
+ array = NULL;
+ }
+ }
+
+ return *this;
+ }
+
float RgbColor::get_red(void) const
{
return red;
@@ -50,4 +82,32 @@ namespace usdx
{
return blue;
}
+
+ const GLubyte* RgbColor::get_array(size_t len) const
+ {
+ if (array_length != len && array != NULL) {
+ delete[] array;
+ array = NULL;
+ array_length = 0;
+ }
+
+ if (array == NULL) {
+ int components = get_array_comonent_count();
+ array = new GLubyte[len * components];
+ array_length = len;
+
+ for (size_t i = 0; i < len; i++) {
+ array[i*components] = red * 255.0f;
+ array[(i*components) + 1] = green * 255.0f;
+ array[(i*components) + 2] = blue * 255.0f;
+ }
+ }
+
+ return array;
+ }
+
+ int RgbColor::get_array_comonent_count(void) const
+ {
+ return 3;
+ }
};
diff --git a/src/utils/rgb_color.hpp b/src/utils/rgb_color.hpp
index 4c06e765..36a5b42c 100644
--- a/src/utils/rgb_color.hpp
+++ b/src/utils/rgb_color.hpp
@@ -25,6 +25,8 @@
#ifndef RGB_COLOR_HPP
#define RGB_COLOR_HPP
+#include <GL/gl.h>
+
namespace usdx
{
class RgbColor
@@ -33,13 +35,24 @@ namespace usdx
float red;
float green;
float blue;
+
+ protected:
+ mutable GLubyte *array;
+ mutable size_t array_length;
+
public:
RgbColor(int red, int green, int blue);
RgbColor(float red, float green, float blue);
+ RgbColor(const RgbColor& color);
+ virtual ~RgbColor();
+ RgbColor& operator=(const RgbColor& color);
float get_red(void) const;
float get_green(void) const;
float get_blue(void) const;
+
+ virtual const GLubyte* get_array(size_t len) const;
+ int get_array_comonent_count(void) const;
};
};