Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Bernal <jbernalmartinez@gmail.com>2015-06-16 01:05:25 +0300
committerJorge Bernal <jbernalmartinez@gmail.com>2015-06-16 01:05:25 +0300
commit6d634467104fc53701d77c7aeb1382a3c198b6d2 (patch)
tree9212fe9e63a148caa45a79b3c72e532ac35e50df /source/gameengine/VideoTexture
parent53e3e4633244facb76740a58f1b2b9b6c1e2a00d (diff)
BGE: Fix for precision lost in setBackground/getBackground at Video Texture
Now internally the variables are processed as floats avoiding int->float->char conversions that are causing precision lost. A check for int numbers is maintained to keep compatibility with old behaviour. Reviewers: ben2610, campbellbarton, moguri, hg1 Reviewed By: moguri, hg1 Subscribers: campbellbarton Projects: #game_engine Differential Revision: https://developer.blender.org/D1301
Diffstat (limited to 'source/gameengine/VideoTexture')
-rw-r--r--source/gameengine/VideoTexture/ImageRender.cpp43
-rw-r--r--source/gameengine/VideoTexture/ImageRender.h4
2 files changed, 27 insertions, 20 deletions
diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp
index 2b2a6e0778b..66bb160a624 100644
--- a/source/gameengine/VideoTexture/ImageRender.cpp
+++ b/source/gameengine/VideoTexture/ImageRender.cpp
@@ -90,14 +90,19 @@ ImageRender::~ImageRender (void)
m_camera->Release();
}
+// get background color
+float ImageRender::getBackground (int idx)
+{
+ return (idx < 0 || idx > 3) ? 0.0f : m_background[idx] * 255.0f;
+}
// set background color
-void ImageRender::setBackground (int red, int green, int blue, int alpha)
+void ImageRender::setBackground (float red, float green, float blue, float alpha)
{
- m_background[0] = (red < 0) ? 0.f : (red > 255) ? 1.f : float(red)/255.f;
- m_background[1] = (green < 0) ? 0.f : (green > 255) ? 1.f : float(green)/255.f;
- m_background[2] = (blue < 0) ? 0.f : (blue > 255) ? 1.f : float(blue)/255.f;
- m_background[3] = (alpha < 0) ? 0.f : (alpha > 255) ? 1.f : float(alpha)/255.f;
+ m_background[0] = (red < 0.0f) ? 0.0f : (red > 255.0f) ? 1.0f : red / 255.0f;
+ m_background[1] = (green < 0.0f) ? 0.0f : (green > 255.0f) ? 1.0f : green / 255.0f;
+ m_background[2] = (blue < 0.0f) ? 0.0f : (blue > 255.0f) ? 1.0f : blue / 255.0f;
+ m_background[3] = (alpha < 0.0f) ? 0.0f : (alpha > 255.0f) ? 1.0f : alpha / 255.0f;
}
// set background color from scene
@@ -105,10 +110,12 @@ void ImageRender::setBackgroundFromScene (KX_Scene *scene)
{
if (scene) {
const float *background_color = scene->GetWorldInfo()->getBackColor();
- setBackground((int) (background_color[0] * 255.0f), (int) (background_color[1] * 255.0f), (int) (background_color[2] * 255.0f), 255);
+ copy_v3_v3(m_background, background_color);
+ m_background[3] = 1.0f;
}
else {
- setBackground(0, 0, 255, 255);
+ const float blue_color[] = {0.0f, 0.0f, 1.0f, 1.0f};
+ copy_v4_v4(m_background, blue_color);
}
}
@@ -360,7 +367,7 @@ static int ImageRender_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
// get background color
static PyObject *getBackground (PyImage *self, void *closure)
{
- return Py_BuildValue("[BBBB]",
+ return Py_BuildValue("[ffff]",
getImageRender(self)->getBackground(0),
getImageRender(self)->getBackground(1),
getImageRender(self)->getBackground(2),
@@ -372,20 +379,20 @@ static int setBackground(PyImage *self, PyObject *value, void *closure)
{
// check validity of parameter
if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 4
- || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0))
- || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1))
- || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 2))
- || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 3)))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 4 integer between 0 and 255");
+ || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 0)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)))
+ || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 1)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
+ || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 2)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 2)))
+ || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 3)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 3)))) {
+
+ PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 4 floats or ints between 0.0 and 255.0");
return -1;
}
// set background color
getImageRender(self)->setBackground(
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1))),
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 2))),
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 3))));
+ PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0)),
+ PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1)),
+ PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 2)),
+ PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 3)));
// success
return 0;
}
diff --git a/source/gameengine/VideoTexture/ImageRender.h b/source/gameengine/VideoTexture/ImageRender.h
index bdf442c82d0..ef55e4dea84 100644
--- a/source/gameengine/VideoTexture/ImageRender.h
+++ b/source/gameengine/VideoTexture/ImageRender.h
@@ -55,9 +55,9 @@ public:
virtual ~ImageRender (void);
/// get background color
- int getBackground (int idx) { return (idx < 0 || idx > 3) ? 0 : int(m_background[idx]*255.f); }
+ float getBackground (int idx);
/// set background color
- void setBackground (int red, int green, int blue, int alpha);
+ void setBackground (float red, float green, float blue, float alpha);
/// clipping distance
float getClip (void) { return m_clip; }