Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1081 - in trunk: Engine/Display Engine/Factory Image fox/afr_demo/Model/Cameras
- Date: Tue, 23 May 2006 15:41:47 -0600 (MDT)
Author: bigler
Date: Tue May 23 15:41:46 2006
New Revision: 1081
Modified:
trunk/Engine/Display/PureOpenGLDisplay.cc
trunk/Engine/Factory/RegisterKnownComponents.cc
trunk/Image/Pixel.h
trunk/Image/SimpleImage.h
trunk/Image/SimpleImage_special.cc
trunk/fox/afr_demo/Model/Cameras/AFRCamera.h
Log:
Engine/Display/PureOpenGLDisplay.cc
Engine/Factory/RegisterKnownComponents.cc
Added support for BGRA pixel format.
Image/Pixel.h
Added BGRA8Pixel.
Removed all the #if SLOWER_VERSION code. It had been in there since
the dawn of Manta and unused, so bye-bye.
Image/SimpleImage.h
Image/SimpleImage_special.cc
Added SSE version of SimpleImage<BGRA8Pixel>::set().
fox/afr_demo/Model/Cameras/AFRCamera.h
Updated to reflect recent addition of bookmarks to Camera's API.
Modified: trunk/Engine/Display/PureOpenGLDisplay.cc
==============================================================================
--- trunk/Engine/Display/PureOpenGLDisplay.cc (original)
+++ trunk/Engine/Display/PureOpenGLDisplay.cc Tue May 23 15:41:46 2006
@@ -277,6 +277,9 @@
} else if(typeid(*image) == typeid(SimpleImage<ARGB8Pixel>)){
format = GL_BGRA;
type = big_endian?GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_INT_8_8_8_8;
+ } else if(typeid(*image) == typeid(SimpleImage<BGRA8Pixel>)){
+ format = GL_BGRA;
+ type = GL_UNSIGNED_BYTE;
} else if(typeid(*image) == typeid(SimpleImage<RGBAfloatPixel>)){
format = GL_RGBA;
type = GL_FLOAT;
@@ -348,20 +351,8 @@
GLenum format;
GLenum type;
bool have_alpha = true;
- if(typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)){
- format = GL_RGBA;
- type = big_endian? GL_UNSIGNED_INT_8_8_8_8 : GL_UNSIGNED_INT_8_8_8_8_REV;
- } else if(typeid(*image) == typeid(SimpleImage<RGB8Pixel>)){
- format = GL_RGB;
- type = GL_UNSIGNED_BYTE;
- have_alpha = false;
- } else if(typeid(*image) == typeid(SimpleImage<ABGR8Pixel>)){
- format = GL_RGBA;
- type = big_endian? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_INT_8_8_8_8;
- } else if(typeid(*image) == typeid(SimpleImage<ARGB8Pixel>)){
- format = GL_BGRA;
- type = big_endian? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_INT_8_8_8_8;
- } else {
+
+ if (!glImageInfo(image, format, type, have_alpha)) {
return false;
}
@@ -592,6 +583,9 @@
} else if(typeid(*image) == typeid(SimpleImage<ARGB8Pixel>)){
format = GL_BGRA;
type = big_endian? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_INT_8_8_8_8;
+ } else if(typeid(*image) == typeid(SimpleImage<BGRA8Pixel>)){
+ format = GL_BGRA;
+ type = big_endian? GL_UNSIGNED_INT_8_8_8_8 : GL_UNSIGNED_INT_8_8_8_8_REV;
} else {
return false;
}
Modified: trunk/Engine/Factory/RegisterKnownComponents.cc
==============================================================================
--- trunk/Engine/Factory/RegisterKnownComponents.cc (original)
+++ trunk/Engine/Factory/RegisterKnownComponents.cc Tue May 23 15:41:46
2006
@@ -62,6 +62,7 @@
engine->registerComponent("rgb8", &SimpleImage<RGB8Pixel>::create);
engine->registerComponent("abgr8", &SimpleImage<ABGR8Pixel>::create);
engine->registerComponent("argb8", &SimpleImage<ARGB8Pixel>::create);
+ engine->registerComponent("bgra8", &SimpleImage<BGRA8Pixel>::create);
engine->registerComponent("rgbafloat",
&SimpleImage<RGBAfloatPixel>::create);
engine->registerComponent("rgbfloat",
Modified: trunk/Image/Pixel.h
==============================================================================
--- trunk/Image/Pixel.h (original)
+++ trunk/Image/Pixel.h Tue May 23 15:41:46 2006
@@ -6,6 +6,10 @@
#include <Core/Color/RGBColor.h>
namespace Manta {
+
+ /////////////////////////////////////////////////////////////////
+ // RGBA8Pixel
+
class RGBA8Pixel {
public:
unsigned char r;
@@ -27,19 +31,6 @@
b = b<0.f?0.f:b;
b = b>1.f?1.f:b;
p.b = (unsigned char)(b*255.f);
-#if SLOWER_VERSION
- float r = c.r() < 0.f?0.f: c.r() > 1.f? 1.f : c.r();
- float g = c.g() < 0.f?0.f: c.g() > 1.f? 1.f : c.g();
- float b = c.b() < 0.f?0.f: c.b() > 1.f? 1.f : c.b();
- p.r = (unsigned char)(r*255.f);
- p.g = (unsigned char)(g*255.f);
- p.b = (unsigned char)(b*255.f);
-#endif
-#if SLOWER_VERSION
- p.r = c.r() < 0?0: c.r() >= 1? 255:(int)c.r()*255.;
- p.g = c.g() < 0?0: c.g() >= 1? 255:(int)c.g()*255.;
- p.b = c.b() < 0?0: c.b() >= 1? 255:(int)c.b()*255.;
-#endif
p.a = 255;
}
@@ -50,6 +41,9 @@
c.setB(p.b*norm);
}
+ /////////////////////////////////////////////////////////////////
+ // ABGR8Pixel
+
class ABGR8Pixel {
public:
unsigned char a;
@@ -59,32 +53,19 @@
};
inline void convertToPixel(ABGR8Pixel& p, const RGBColor& c) {
- float r = c.r();
- r = r<0.f?0.f:r;
- r = r>1.f?1.f:r;
- p.r = (unsigned char)(r*255.f);
- float g = c.g();
- g = g<0.f?0.f:g;
- g = g>1.f?1.f:g;
- p.g = (unsigned char)(g*255.f);
+ p.a = 255;
float b = c.b();
b = b<0.f?0.f:b;
b = b>1.f?1.f:b;
p.b = (unsigned char)(b*255.f);
-#if SLOWER_VERSION
- float r = c.r() < 0.f?0.f: c.r() > 1.f? 1.f : c.r();
- float g = c.g() < 0.f?0.f: c.g() > 1.f? 1.f : c.g();
- float b = c.b() < 0.f?0.f: c.b() > 1.f? 1.f : c.b();
- p.r = (unsigned char)(r*255.f);
+ float g = c.g();
+ g = g<0.f?0.f:g;
+ g = g>1.f?1.f:g;
p.g = (unsigned char)(g*255.f);
- p.b = (unsigned char)(b*255.f);
-#endif
-#if SLOWER_VERSION
- p.r = c.r() < 0?0: c.r() >= 1? 255:(int)c.r()*255.;
- p.g = c.g() < 0?0: c.g() >= 1? 255:(int)c.g()*255.;
- p.b = c.b() < 0?0: c.b() >= 1? 255:(int)c.b()*255.;
-#endif
- p.a = 255;
+ float r = c.r();
+ r = r<0.f?0.f:r;
+ r = r>1.f?1.f:r;
+ p.r = (unsigned char)(r*255.f);
}
inline void convertToRGBColor(RGBColor& c, const ABGR8Pixel& p) {
@@ -94,6 +75,9 @@
c.setB(p.b*norm);
}
+ /////////////////////////////////////////////////////////////////
+ // ARGB8Pixel
+
class ARGB8Pixel {
public:
unsigned char a;
@@ -116,19 +100,6 @@
b = b<0.f?0.f:b;
b = b>1.f?1.f:b;
p.b = (unsigned char)(b*255.f);
-#if SLOWER_VERSION
- float r = c.r() < 0.f?0.f: c.r() > 1.f? 1.f : c.r();
- float g = c.g() < 0.f?0.f: c.g() > 1.f? 1.f : c.g();
- float b = c.b() < 0.f?0.f: c.b() > 1.f? 1.f : c.b();
- p.r = (unsigned char)(r*255.f);
- p.g = (unsigned char)(g*255.f);
- p.b = (unsigned char)(b*255.f);
-#endif
-#if SLOWER_VERSION
- p.r = c.r() < 0?0: c.r() >= 1? 255:(int)c.r()*255.;
- p.g = c.g() < 0?0: c.g() >= 1? 255:(int)c.g()*255.;
- p.b = c.b() < 0?0: c.b() >= 1? 255:(int)c.b()*255.;
-#endif
}
inline void convertToRGBColor(RGBColor& c, const ARGB8Pixel& p) {
@@ -138,6 +109,43 @@
c.setB(p.b*norm);
}
+ /////////////////////////////////////////////////////////////////
+ // BGRA8Pixel
+
+ class BGRA8Pixel {
+ public:
+ unsigned char b;
+ unsigned char g;
+ unsigned char r;
+ unsigned char a;
+ };
+
+ inline void convertToPixel(BGRA8Pixel& p, const RGBColor& c) {
+ float b = c.b();
+ b = b<0.f?0.f:b;
+ b = b>1.f?1.f:b;
+ p.b = (unsigned char)(b*255.f);
+ float g = c.g();
+ g = g<0.f?0.f:g;
+ g = g>1.f?1.f:g;
+ p.g = (unsigned char)(g*255.f);
+ float r = c.r();
+ r = r<0.f?0.f:r;
+ r = r>1.f?1.f:r;
+ p.r = (unsigned char)(r*255.f);
+ p.a = 255;
+ }
+
+ inline void convertToRGBColor(RGBColor& c, const BGRA8Pixel& p) {
+ ColorComponent norm = (ColorComponent)1/(ColorComponent)255;
+ c.setR(p.r*norm);
+ c.setG(p.g*norm);
+ c.setB(p.b*norm);
+ }
+
+ /////////////////////////////////////////////////////////////////
+ // RGB8Pixel
+
class RGB8Pixel {
public:
unsigned char r;
@@ -158,19 +166,6 @@
b = b<0.f?0.f:b;
b = b>1.f?1.f:b;
p.b = (unsigned char)(b*255.f);
-#if SLOWER_VERSION
- float r = c.r() < 0.f?0.f: c.r() > 1.f? 1.f : c.r();
- float g = c.g() < 0.f?0.f: c.g() > 1.f? 1.f : c.g();
- float b = c.b() < 0.f?0.f: c.b() > 1.f? 1.f : c.b();
- p.r = (unsigned char)(r*255.f);
- p.g = (unsigned char)(g*255.f);
- p.b = (unsigned char)(b*255.f);
-#endif
-#if SLOWER_VERSION
- p.r = c.r() < 0?0: c.r() >= 1? 255:(int)c.r()*255.;
- p.g = c.g() < 0?0: c.g() >= 1? 255:(int)c.g()*255.;
- p.b = c.b() < 0?0: c.b() >= 1? 255:(int)c.b()*255.;
-#endif
}
inline void convertToRGBColor(RGBColor& c, const RGB8Pixel& p) {
@@ -180,6 +175,9 @@
c.setB(p.b*norm);
}
+ /////////////////////////////////////////////////////////////////
+ // RGBfloatPixel
+
class RGBfloatPixel {
public:
float r;
@@ -198,6 +196,9 @@
c.setG(p.g);
c.setB(p.b);
}
+
+ /////////////////////////////////////////////////////////////////
+ // RGBAfloatPixel
class RGBAfloatPixel {
public:
Modified: trunk/Image/SimpleImage.h
==============================================================================
--- trunk/Image/SimpleImage.h (original)
+++ trunk/Image/SimpleImage.h Tue May 23 15:41:46 2006
@@ -126,6 +126,9 @@
template<>
void SimpleImage<ARGB8Pixel>::set(const Fragment& fragment);
+ template<>
+ void SimpleImage<BGRA8Pixel>::set(const Fragment& fragment);
+
template<class Pixel>
void SimpleImage<Pixel>::get(Fragment& fragment) const
{
Modified: trunk/Image/SimpleImage_special.cc
==============================================================================
--- trunk/Image/SimpleImage_special.cc (original)
+++ trunk/Image/SimpleImage_special.cc Tue May 23 15:41:46 2006
@@ -53,3 +53,67 @@
}
}
+template<>
+void SimpleImage<BGRA8Pixel>::set(const Fragment& fragment)
+{
+ if(fragment.getFlag(Fragment::ConsecutiveX|Fragment::ConstantEye) ==
+ Fragment::ConsecutiveX|Fragment::ConstantEye){
+ int b = fragment.begin();
+ BGRA8Pixel* pix =
eyeStart[fragment.getWhichEye(b)][fragment.getY(b)]+fragment.getX(b);
+#if MANTA_SSE
+ // If the fragment and the pixel are on an aligned boundary, use SSE
+ if(((fragment.pixelBegin | fragment.pixelEnd) & 0x3) == 0){
+ // Aligned for SSE
+ __m128 scale = _mm_set1_ps( 255.99999f );
+ int f = fragment.end()-3;
+ for(int i=fragment.begin(); i< f;i+=4){
+ __m128 r = _mm_load_ps(&fragment.color[0][i]);
+ __m128 g = _mm_load_ps(&fragment.color[1][i]);
+ __m128 b = _mm_load_ps(&fragment.color[2][i]);
+ r = _mm_mul_ps(r, scale);
+ g = _mm_mul_ps(g, scale);
+ b = _mm_mul_ps(b, scale);
+ __m128i alpha = _mm_set1_epi32(255); // alpha a0a1a2a3
+ __m128i r32 = _mm_cvttps_epi32(r); // 32 bits: r0r1r2r3
+ __m128i g32 = _mm_cvttps_epi32(g); // 32 bits: g0g1g2g3
+ __m128i b32 = _mm_cvttps_epi32(b); // 32 bits: b0b1b2b3
+
+ // 16 bits: b0b1b2b3r0r1r2r3
+ __m128i br16 = _mm_packs_epi32(b32, r32);
+
+ // 16 bits: g0g1g2g3a0a1a2a3
+ __m128i ga16 = _mm_packs_epi32(g32, alpha);
+
+ // 16 bits: b0g0b1g1b2g2b3g3
+ __m128i bg16 = _mm_unpacklo_epi16(br16, ga16);
+
+ // 16 bits: r0a0r1a1r2a2r3a3
+ __m128i ra16 = _mm_unpackhi_epi16(br16, ga16);
+
+ // 16 bits: b0g0r0a0b1g1r1a1
+ __m128i bgra16a = _mm_unpacklo_epi32(bg16, ra16);
+
+ // 16 bits: b2g2r2a2b3g3r3a3
+ __m128i bgra16b = _mm_unpackhi_epi32(bg16, ra16);
+
+ // 32 bits: b0g0r0a0 ... b3g3r3a3
+ __m128i result = _mm_packus_epi16(bgra16a, bgra16b);
+
+ // Copy data over
+ _mm_stream_si128((__m128i*)pix, result);
+
+ pix += 4;
+ }
+ } else
+#endif /* MANTA_SSE */
+ {
+ for(int i=fragment.begin(); i< fragment.end();i++)
+ convertToPixel(*pix++, fragment.getColor(i).convertRGB());
+ }
+ } else {
+ for(int i=fragment.begin();i<fragment.end();i++){
+
convertToPixel(eyeStart[fragment.getWhichEye(i)][fragment.getY(i)][fragment.getX(i)],
fragment.getColor(i).convertRGB());
+ }
+ }
+}
+
Modified: trunk/fox/afr_demo/Model/Cameras/AFRCamera.h
==============================================================================
--- trunk/fox/afr_demo/Model/Cameras/AFRCamera.h (original)
+++ trunk/fox/afr_demo/Model/Cameras/AFRCamera.h Tue May 23 15:41:46
2006
@@ -88,6 +88,17 @@
///////////////////////////////////////////////////////////////////////////
// Render stack method.
virtual void makeRays( RayPacket &rays ) const { getCurrent()->makeRays(
rays ); }
+ // Inherited from Camera
+ virtual void preprocess(const PreprocessContext& context) {
+ for(int i = 0; i < Size; ++i)
+ cam[i]->preprocess(context);
+ }
+ virtual void getBasicCameraData(BasicCameraData& cam) const {
+ getCurrent()->getBasicCameraData(cam);
+ }
+ virtual void setBasicCameraData(BasicCameraData cam) {
+ getCurrent()->setBasicCameraData(cam);
+ }
///////////////////////////////////////////////////////////////////////////
// Camera manipulation
- [MANTA] r1081 - in trunk: Engine/Display Engine/Factory Image fox/afr_demo/Model/Cameras, bigler, 05/23/2006
Archive powered by MHonArc 2.6.16.