diff --git a/librtt/Renderer/Rtt_FrameBufferObject.h b/librtt/Renderer/Rtt_FrameBufferObject.h index 9b00fd2bc..fcd5a5b87 100644 --- a/librtt/Renderer/Rtt_FrameBufferObject.h +++ b/librtt/Renderer/Rtt_FrameBufferObject.h @@ -18,6 +18,7 @@ namespace Rtt { +class BufferBitmap; class Texture; // ---------------------------------------------------------------------------- @@ -42,6 +43,8 @@ class FrameBufferObject : public CPUResource U8 GetDepthBits() const { return fDepthBits; } U8 GetStencilBits() const { return fStencilBits; } bool GetMustClear() const { return fMustClear; } + + static void Capture( BufferBitmap& bitmap, S32 x_in_pixels, S32 y_in_pixels, S32 w_in_pixels, S32 h_in_pixels ); private: Texture* fTexture; diff --git a/librtt/Renderer/Rtt_GLFrameBufferObject.cpp b/librtt/Renderer/Rtt_GLFrameBufferObject.cpp index ae5e73b75..220b86320 100644 --- a/librtt/Renderer/Rtt_GLFrameBufferObject.cpp +++ b/librtt/Renderer/Rtt_GLFrameBufferObject.cpp @@ -21,6 +21,8 @@ #include #include "Rtt_Profiling.h" +#include "Display/Rtt_BufferBitmap.h" + // ---------------------------------------------------------------------------- #define ENABLE_DEBUG_PRINT 0 @@ -272,8 +274,117 @@ GLFrameBufferObject::Blit( int srcX0, int srcY0, int srcX1, int srcY1, int dstX0 sBlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ); } +static GLenum +GPU_GetPixelFormat( PlatformBitmap::Format format ) +{ +# ifdef Rtt_OPENGLES + + switch ( format ) + { + case PlatformBitmap::kRGBA: + return GL_RGBA; + case PlatformBitmap::kMask: + return GL_ALPHA; + case PlatformBitmap::kRGB: + case PlatformBitmap::kBGRA: + case PlatformBitmap::kARGB: + default: + Rtt_ASSERT_NOT_IMPLEMENTED(); + return GL_ALPHA; + } + +# else // Not Rtt_OPENGLES. + + switch ( format ) + { + case PlatformBitmap::kBGRA: + case PlatformBitmap::kARGB: + return GL_BGRA; + case PlatformBitmap::kRGBA: + return GL_RGBA; + case PlatformBitmap::kRGB: + return GL_BGR; + case PlatformBitmap::kMask: + return GL_ALPHA; + default: + Rtt_ASSERT_NOT_IMPLEMENTED(); + return GL_ALPHA; + } + +# endif // Rtt_OPENGLES +} + +static GLenum +GPU_GetPixelType( PlatformBitmap::Format format ) +{ +# ifdef Rtt_OPENGLES + + switch( format ) + { + case PlatformBitmap::kMask: + return GL_UNSIGNED_BYTE; + case PlatformBitmap::kBGRA: + case PlatformBitmap::kARGB: + case PlatformBitmap::kRGBA: + default: + Rtt_ASSERT_NOT_IMPLEMENTED(); + return GL_UNSIGNED_BYTE; + } + +# else // Not Rtt_OPENGLES. + + switch( format ) + { + case PlatformBitmap::kBGRA: + #ifdef Rtt_BIG_ENDIAN + return GL_UNSIGNED_INT_8_8_8_8_REV; + #else + return GL_UNSIGNED_INT_8_8_8_8; + #endif + case PlatformBitmap::kARGB: + #ifdef Rtt_BIG_ENDIAN + return GL_UNSIGNED_INT_8_8_8_8; + #else + return GL_UNSIGNED_INT_8_8_8_8_REV; + #endif + case PlatformBitmap::kRGBA: + #ifdef Rtt_BIG_ENDIAN + return GL_UNSIGNED_INT_8_8_8_8_REV; + #else + return GL_UNSIGNED_INT_8_8_8_8; + #endif + case PlatformBitmap::kMask: + return GL_UNSIGNED_BYTE; + default: + Rtt_ASSERT_NOT_IMPLEMENTED(); + return GL_UNSIGNED_BYTE; + } + +# endif // Rtt_OPENGLES +} + +void FrameBufferObject::Capture( BufferBitmap& bitmap, S32 x_in_pixels, S32 y_in_pixels, S32 w_in_pixels, S32 h_in_pixels ) +{ +#ifdef Rtt_OPENGLES + const GLenum kFormat = GL_RGBA; + const GLenum kType = GL_UNSIGNED_BYTE; +#else + PlatformBitmap::Format format = bitmap.GetFormat(); + const GLenum kFormat = GPU_GetPixelFormat( format ); + GLenum kType = GPU_GetPixelType( format ); +#endif + + glReadPixels( x_in_pixels, + y_in_pixels, + w_in_pixels, + h_in_pixels, + kFormat, + kType, + bitmap.WriteAccess() ); +} + // ---------------------------------------------------------------------------- } // namespace Rtt -// ---------------------------------------------------------------------------- \ No newline at end of file +// ---------------------------------------------------------------------------- diff --git a/librtt/Renderer/Rtt_Renderer.cpp b/librtt/Renderer/Rtt_Renderer.cpp index 2812ffbce..cd9fb6dc5 100644 --- a/librtt/Renderer/Rtt_Renderer.cpp +++ b/librtt/Renderer/Rtt_Renderer.cpp @@ -300,11 +300,14 @@ Renderer::BeginDrawing() void Renderer::CaptureFrameBuffer( RenderingStream & stream, BufferBitmap & bitmap, S32 x_in_pixels, S32 y_in_pixels, S32 w_in_pixels, S32 h_in_pixels ) { +/* stream.CaptureFrameBuffer( bitmap, x_in_pixels, y_in_pixels, w_in_pixels, h_in_pixels ); +*/ + FrameBufferObject::Capture(bitmap, x_in_pixels, y_in_pixels, w_in_pixels, h_in_pixels); } void diff --git a/librtt/Rtt_GPU.h b/librtt/Rtt_GPU.h index e17c010ee..858c419df 100644 --- a/librtt/Rtt_GPU.h +++ b/librtt/Rtt_GPU.h @@ -162,6 +162,10 @@ class GPU #define GPUError() do {} while(0) #endif +#ifdef OLD_GRAPHICS + #error Details now moved to non-librtt code (tachyon) +#endif + // ---------------------------------------------------------------------------- } // namespace Rtt diff --git a/librtt/Rtt_GPUStream.cpp b/librtt/Rtt_GPUStream.cpp index 2c6dc9cd4..d577b1972 100644 --- a/librtt/Rtt_GPUStream.cpp +++ b/librtt/Rtt_GPUStream.cpp @@ -21,7 +21,7 @@ #include "Display/Rtt_VertexCache.h" #include "Renderer/Rtt_RenderTypes.h" -#if defined( Rtt_WIN_DESKTOP_ENV ) && !defined( Rtt_POWERVR_ENV ) +#if defined( OLD_GRAPHICS ) && defined( Rtt_WIN_DESKTOP_ENV ) && !defined( Rtt_POWERVR_ENV ) #if defined(Rtt_EMSCRIPTEN_ENV) #include #elif defined(Rtt_LINUX_ENV) @@ -140,6 +140,8 @@ GLModeForMode( RenderTypes::Mode mode ) #endif // ---------------------------------------------------------------------------- +#ifdef OLD_GRAPHICS + int GPUStream::GetMaxTextureUnits() { @@ -161,16 +163,22 @@ GPUStream::GetMaxTextureUnits() static const GLenum kDataType = GL_FLOAT; #endif +#endif + #ifdef Rtt_DEBUG static int sTextureStackSize = -1; #endif +#ifdef OLD_GRAPHICS + GLenum GPUStream::GetDataType() { return kDataType; } +#endif + GPUStream::GPUStream( Rtt_Allocator* pAllocator ) : Super(), fCurrentPaint( NULL ), @@ -200,7 +208,7 @@ GPUStream::GPUStream( Rtt_Allocator* pAllocator ) { memset( & fColor, 0xFF, sizeof( fColor ) ); -#if defined( Rtt_WIN_DESKTOP_ENV ) && !defined( Rtt_POWERVR_ENV ) +#if defined( OLD_GRAPHICS ) && defined( Rtt_WIN_DESKTOP_ENV ) && !defined( Rtt_POWERVR_ENV ) if ( glActiveTexture == NULL ) { glActiveTexture = (PFNGLACTIVETEXTUREPROC) wglGetProcAddress("glActiveTexture"); glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC) wglGetProcAddress("glClientActiveTexture"); @@ -1373,6 +1381,8 @@ GPUStream::SetAlpha( U8 newValue, bool accumuluate ) return result; } +#ifdef OLD_GRAPHICS + GLenum GPU_GetPixelFormat( PlatformBitmap::Format format ) { @@ -1462,10 +1472,14 @@ GPU_GetPixelType( PlatformBitmap::Format format ) # endif // Rtt_OPENGLES } +#endif + // Performs a screen capture and outputs the image to the given "outBuffer" bitmap. void GPUStream::CaptureFrameBuffer( BufferBitmap& outBuffer, S32 xScreen, S32 yScreen, S32 wScreen, S32 hScreen ) { +#ifdef OLD_GRAPHICS /* details moved to Rtt_FrameBufferObject / Rtt_GLFrameBufferObject */ + // GLint x = Rtt_RealToInt( bounds.xMin ); // GLint y = Rtt_RealToInt( bounds.yMin ); // GLint w = Rtt_RealToInt( bounds.xMax ) - x; @@ -1486,6 +1500,7 @@ GPUStream::CaptureFrameBuffer( BufferBitmap& outBuffer, S32 xScreen, S32 yScreen kFormat, kType, outBuffer.WriteAccess() ); +#endif } void diff --git a/librtt/Rtt_GPUStream.h b/librtt/Rtt_GPUStream.h index a595ef724..4311e8578 100644 --- a/librtt/Rtt_GPUStream.h +++ b/librtt/Rtt_GPUStream.h @@ -15,7 +15,7 @@ #include "Rtt_RenderingStream.h" #include "Display/Rtt_Paint.h" -#include "Rtt_GPU.h" +/* #include "Rtt_GPU.h" */ // TODO: created annoying dependencies, and seemed to be mostly dead code (probably safe to remove) #if defined( Rtt_AUTHORING_SIMULATOR ) || defined( Rtt_ANDROID_ENV ) #define RTT_SURFACE_ROTATION @@ -48,12 +48,16 @@ class GPUStream : public RenderingStream kMaxTextureStackDepth = 32 }; +#ifdef OLD_GRAPHICS + public: static int GetMaxTextureUnits(); public: static GLenum GetDataType(); +#endif + public: GPUStream( Rtt_Allocator* ); virtual ~GPUStream(); @@ -176,8 +180,16 @@ class GPUStream : public RenderingStream TextureStackFrame fTextureStack[kMaxTextureStackDepth]; private: - GLint fWindowWidth; - GLint fWindowHeight; + #ifdef OLD_GRAPHICS /* window dimensions and clear components; the old versions drag in GL dependencies */ + typedef GLint wdInt; + typedef GLclampf ccFloat; + #else + typedef int wdInt; + typedef float ccFloat; + #endif + + wdInt fWindowWidth; + wdInt fWindowHeight; S32 fRenderedContentWidth; // width of rect in which content is rendered (not necessarily same as content width) S32 fRenderedContentHeight; // height of rect in which content is rendered (not necessarily same as content height) @@ -196,10 +208,10 @@ class GPUStream : public RenderingStream TextureFunction fTextureFunction; // Clear color - GLclampf fClearR; - GLclampf fClearG; - GLclampf fClearB; - GLclampf fClearA; + ccFloat fClearR; + ccFloat fClearG; + ccFloat fClearB; + ccFloat fClearA; protected: Rtt_Allocator* fAllocator; diff --git a/librtt/Rtt_LuaLibSystem.cpp b/librtt/Rtt_LuaLibSystem.cpp index 6ae2e081b..2016b41f3 100644 --- a/librtt/Rtt_LuaLibSystem.cpp +++ b/librtt/Rtt_LuaLibSystem.cpp @@ -20,7 +20,7 @@ #include "Rtt_MPlatformDevice.h" #include "Rtt_Runtime.h" -#include "Rtt_GPU.h" +/* #include "Rtt_GPU.h" */ // TODO: created annoying dependencies, and seemed to be mostly dead code (probably safe to remove) #include "Rtt_GPUStream.h" #include "Rtt_PhysicsWorld.h" #include "Rtt_PlatformInAppStore.h" diff --git a/librtt/Rtt_PlatformSurface.cpp b/librtt/Rtt_PlatformSurface.cpp index 693909bde..bfd6f6e94 100644 --- a/librtt/Rtt_PlatformSurface.cpp +++ b/librtt/Rtt_PlatformSurface.cpp @@ -114,7 +114,9 @@ PlatformSurface::SetDelegate( PlatformSurfaceDelegate* delegate ) // ---------------------------------------------------------------------------- // TODO: Replace platform ifdef's with a feature ifdef: Rtt_OFFSCREEN_SURFACE in Rtt_Config.h -#if ! defined( Rtt_ANDROID_ENV ) && !defined( Rtt_WIN_ENV ) && !defined( Rtt_EMSCRIPTEN_ENV ) && !defined( Rtt_NXS_ENV ) +// TODO (follow-up): seems to be dead code; probably can be removed altogether +#if defined( OLD_GRAPHICS ) && \ + ! defined( Rtt_ANDROID_ENV ) && !defined( Rtt_WIN_ENV ) && !defined( Rtt_EMSCRIPTEN_ENV ) && !defined( Rtt_NXS_ENV ) OffscreenGPUSurface::OffscreenGPUSurface( const PlatformSurface& parent ) : fWidth( parent.Width() ), diff --git a/librtt/Rtt_PlatformSurface.h b/librtt/Rtt_PlatformSurface.h index ddefb6d54..6012d5aeb 100644 --- a/librtt/Rtt_PlatformSurface.h +++ b/librtt/Rtt_PlatformSurface.h @@ -92,16 +92,19 @@ class PlatformSurface // ---------------------------------------------------------------------------- // TODO: Remove this when OffscreenGPUSurface is moved to a separate file -#include "Rtt_GPU.h" +// TODO (follow-up): was dead code anyway? +/* #include "Rtt_GPU.h" */ namespace Rtt { // ---------------------------------------------------------------------------- -#if ! defined( Rtt_ANDROID_ENV ) && ! defined( Rtt_EMSCRIPTEN_ENV ) +#if defined( OLD_GRAPHICS) && \ + ! defined( Rtt_ANDROID_ENV ) && ! defined( Rtt_EMSCRIPTEN_ENV ) // TODO: Move to a separate file +// TODO (follow-up): seems to be dead code; probably can be removed altogether // GPU-specific class OffscreenGPUSurface : public PlatformSurface { diff --git a/platform/apple/Rtt_ApplePlatform.mm b/platform/apple/Rtt_ApplePlatform.mm index 4fda6c5bf..aa87cbac6 100644 --- a/platform/apple/Rtt_ApplePlatform.mm +++ b/platform/apple/Rtt_ApplePlatform.mm @@ -621,7 +621,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err PlatformSurface* ApplePlatform::CreateOffscreenSurface( const PlatformSurface& parent ) const { -#ifdef Rtt_NO_GUI +#if defined( Rtt_NO_GUI ) || !defined( OLD_GRAPHICS ) // n.b. seems to be dead code return NULL; #else OffscreenGPUSurface *result = Rtt_NEW( Allocator(), OffscreenGPUSurface( parent ) );