diff --git a/extras/JuceDemo/Builds/MacOSX/Juce Demo.xcodeproj/project.pbxproj b/extras/JuceDemo/Builds/MacOSX/Juce Demo.xcodeproj/project.pbxproj index 5d55ed7923..892bbba26e 100644 --- a/extras/JuceDemo/Builds/MacOSX/Juce Demo.xcodeproj/project.pbxproj +++ b/extras/JuceDemo/Builds/MacOSX/Juce Demo.xcodeproj/project.pbxproj @@ -135,6 +135,7 @@ 16793951B75EADE5C08FD129 = { isa = PBXFileReference; lastKnownFileType = file.icns; name = Icon.icns; path = Icon.icns; sourceTree = "SOURCE_ROOT"; }; 16A6895439607DD8E651BA87 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_ByteOrder.h"; path = "../../../../modules/juce_core/memory/juce_ByteOrder.h"; sourceTree = "SOURCE_ROOT"; }; 171777847EB6194910E9CFEC = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_TableHeaderComponent.h"; path = "../../../../modules/juce_gui_basics/widgets/juce_TableHeaderComponent.h"; sourceTree = "SOURCE_ROOT"; }; + 17422D876DAAF091ED089B8D = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_OpenGLImage.h"; path = "../../../../modules/juce_opengl/opengl/juce_OpenGLImage.h"; sourceTree = "SOURCE_ROOT"; }; 1798F0BC1F2B2DF2F13193AB = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_SystemStats.cpp"; path = "../../../../modules/juce_core/system/juce_SystemStats.cpp"; sourceTree = "SOURCE_ROOT"; }; 18666AEC1FCCE5D1514EB1FD = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_KeyListener.cpp"; path = "../../../../modules/juce_gui_basics/keyboard/juce_KeyListener.cpp"; sourceTree = "SOURCE_ROOT"; }; 18D1181C39F5A59423AC7A3E = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_Initialisation.h"; path = "../../../../modules/juce_gui_basics/application/juce_Initialisation.h"; sourceTree = "SOURCE_ROOT"; }; @@ -824,6 +825,7 @@ E38DE271B32DCC95E52C72DA = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_DrawableButton.h"; path = "../../../../modules/juce_gui_basics/buttons/juce_DrawableButton.h"; sourceTree = "SOURCE_ROOT"; }; E3FC888CC9FAD650C469ACC5 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_TextButton.cpp"; path = "../../../../modules/juce_gui_basics/buttons/juce_TextButton.cpp"; sourceTree = "SOURCE_ROOT"; }; E453E312D607E60FAA6D1BF0 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_MultiDocumentPanel.cpp"; path = "../../../../modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp"; sourceTree = "SOURCE_ROOT"; }; + E46977801F19277F4D3B324B = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_OpenGLImage.cpp"; path = "../../../../modules/juce_opengl/opengl/juce_OpenGLImage.cpp"; sourceTree = "SOURCE_ROOT"; }; E5DC4602843749A071B17576 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_Slider.h"; path = "../../../../modules/juce_gui_basics/widgets/juce_Slider.h"; sourceTree = "SOURCE_ROOT"; }; E6B13A51A01032961340735D = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_StringPairArray.cpp"; path = "../../../../modules/juce_core/text/juce_StringPairArray.cpp"; sourceTree = "SOURCE_ROOT"; }; E6C582E67DC0C4D0CCA18166 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_ShapeButton.h"; path = "../../../../modules/juce_gui_basics/buttons/juce_ShapeButton.h"; sourceTree = "SOURCE_ROOT"; }; @@ -1866,6 +1868,8 @@ 43E4604C39E9A992216F6B98, D7239D5B984E07808E2DB28C, D2C40CDF46D894BFC72BDC56, + E46977801F19277F4D3B324B, + 17422D876DAAF091ED089B8D, B81FA2ED22BCC03D124031ED, FE9A5898294228EB7F439951, 4CFB262AA9778621B8B33A7D ); name = opengl; sourceTree = ""; }; diff --git a/extras/JuceDemo/Builds/VisualStudio2005/Juce Demo.vcproj b/extras/JuceDemo/Builds/VisualStudio2005/Juce Demo.vcproj index 0a8afcba9c..d73664adca 100644 --- a/extras/JuceDemo/Builds/VisualStudio2005/Juce Demo.vcproj +++ b/extras/JuceDemo/Builds/VisualStudio2005/Juce Demo.vcproj @@ -4230,6 +4230,17 @@ + + + + + + + + + + + + + + + + + + true + + true + true @@ -1574,6 +1577,7 @@ + diff --git a/extras/JuceDemo/Builds/VisualStudio2010/Juce Demo.vcxproj.filters b/extras/JuceDemo/Builds/VisualStudio2010/Juce Demo.vcxproj.filters index 7e680504d3..8eef80c211 100644 --- a/extras/JuceDemo/Builds/VisualStudio2010/Juce Demo.vcxproj.filters +++ b/extras/JuceDemo/Builds/VisualStudio2010/Juce Demo.vcxproj.filters @@ -1492,6 +1492,9 @@ Juce Modules\juce_opengl\opengl + + Juce Modules\juce_opengl\opengl + Juce Modules\juce_opengl\opengl @@ -2772,6 +2775,9 @@ Juce Modules\juce_opengl\opengl + + Juce Modules\juce_opengl\opengl + Juce Modules\juce_opengl\opengl diff --git a/extras/JuceDemo/Builds/iOS/Juce Demo.xcodeproj/project.pbxproj b/extras/JuceDemo/Builds/iOS/Juce Demo.xcodeproj/project.pbxproj index c61ed7b599..367905efcc 100644 --- a/extras/JuceDemo/Builds/iOS/Juce Demo.xcodeproj/project.pbxproj +++ b/extras/JuceDemo/Builds/iOS/Juce Demo.xcodeproj/project.pbxproj @@ -127,6 +127,7 @@ 16793951B75EADE5C08FD129 = { isa = PBXFileReference; lastKnownFileType = file.icns; name = Icon.icns; path = Icon.icns; sourceTree = "SOURCE_ROOT"; }; 16A6895439607DD8E651BA87 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_ByteOrder.h"; path = "../../../../modules/juce_core/memory/juce_ByteOrder.h"; sourceTree = "SOURCE_ROOT"; }; 171777847EB6194910E9CFEC = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_TableHeaderComponent.h"; path = "../../../../modules/juce_gui_basics/widgets/juce_TableHeaderComponent.h"; sourceTree = "SOURCE_ROOT"; }; + 17422D876DAAF091ED089B8D = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_OpenGLImage.h"; path = "../../../../modules/juce_opengl/opengl/juce_OpenGLImage.h"; sourceTree = "SOURCE_ROOT"; }; 1798F0BC1F2B2DF2F13193AB = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_SystemStats.cpp"; path = "../../../../modules/juce_core/system/juce_SystemStats.cpp"; sourceTree = "SOURCE_ROOT"; }; 18666AEC1FCCE5D1514EB1FD = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_KeyListener.cpp"; path = "../../../../modules/juce_gui_basics/keyboard/juce_KeyListener.cpp"; sourceTree = "SOURCE_ROOT"; }; 18D1181C39F5A59423AC7A3E = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_Initialisation.h"; path = "../../../../modules/juce_gui_basics/application/juce_Initialisation.h"; sourceTree = "SOURCE_ROOT"; }; @@ -810,6 +811,7 @@ E3D24CD61D75922457DB9642 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_win32_Midi.cpp"; path = "../../../../modules/juce_audio_devices/native/juce_win32_Midi.cpp"; sourceTree = "SOURCE_ROOT"; }; E3FC888CC9FAD650C469ACC5 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_TextButton.cpp"; path = "../../../../modules/juce_gui_basics/buttons/juce_TextButton.cpp"; sourceTree = "SOURCE_ROOT"; }; E453E312D607E60FAA6D1BF0 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_MultiDocumentPanel.cpp"; path = "../../../../modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp"; sourceTree = "SOURCE_ROOT"; }; + E46977801F19277F4D3B324B = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_OpenGLImage.cpp"; path = "../../../../modules/juce_opengl/opengl/juce_OpenGLImage.cpp"; sourceTree = "SOURCE_ROOT"; }; E48615F1F7D8213F6DC24FC9 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_ThreadPool.h"; path = "../../../../modules/juce_core/threads/juce_ThreadPool.h"; sourceTree = "SOURCE_ROOT"; }; E5DC4602843749A071B17576 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_Slider.h"; path = "../../../../modules/juce_gui_basics/widgets/juce_Slider.h"; sourceTree = "SOURCE_ROOT"; }; E6B13A51A01032961340735D = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_StringPairArray.cpp"; path = "../../../../modules/juce_core/text/juce_StringPairArray.cpp"; sourceTree = "SOURCE_ROOT"; }; @@ -1856,6 +1858,8 @@ 43E4604C39E9A992216F6B98, D7239D5B984E07808E2DB28C, D2C40CDF46D894BFC72BDC56, + E46977801F19277F4D3B324B, + 17422D876DAAF091ED089B8D, B81FA2ED22BCC03D124031ED, FE9A5898294228EB7F439951, 4CFB262AA9778621B8B33A7D ); name = opengl; sourceTree = ""; }; diff --git a/extras/audio plugin host/Builds/MacOSX/Plugin Host.xcodeproj/project.pbxproj b/extras/audio plugin host/Builds/MacOSX/Plugin Host.xcodeproj/project.pbxproj index 354a83c296..39b10f851d 100644 --- a/extras/audio plugin host/Builds/MacOSX/Plugin Host.xcodeproj/project.pbxproj +++ b/extras/audio plugin host/Builds/MacOSX/Plugin Host.xcodeproj/project.pbxproj @@ -302,6 +302,7 @@ 4C3B55EC342AD41B525ABEBE = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_FileOutputStream.h"; path = "../../../../modules/juce_core/files/juce_FileOutputStream.h"; sourceTree = "SOURCE_ROOT"; }; 4C46D1CE125E2770BF5D0E36 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_InterprocessConnectionServer.h"; path = "../../../../modules/juce_events/interprocess/juce_InterprocessConnectionServer.h"; sourceTree = "SOURCE_ROOT"; }; 4CAFE02422227FB8CDD130A5 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_AudioUnitPluginFormat.h"; path = "../../../../modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.h"; sourceTree = "SOURCE_ROOT"; }; + 4CE76ABC51CC5E019AED3C2B = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_OpenGLImage.h"; path = "../../../../modules/juce_opengl/opengl/juce_OpenGLImage.h"; sourceTree = "SOURCE_ROOT"; }; 4CEDF2832E38C0B313ED40D5 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_AudioProcessorGraph.h"; path = "../../../../modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h"; sourceTree = "SOURCE_ROOT"; }; 4D2D008FEC5F93DEFFBE4B56 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_ApplicationBase.h"; path = "../../../../modules/juce_events/messages/juce_ApplicationBase.h"; sourceTree = "SOURCE_ROOT"; }; 4D664CA1434E85BEA96E6E1B = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_Time.h"; path = "../../../../modules/juce_core/time/juce_Time.h"; sourceTree = "SOURCE_ROOT"; }; @@ -646,6 +647,7 @@ C08CEA80C09A398668B42CF9 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_Sampler.h"; path = "../../../../modules/juce_audio_formats/sampler/juce_Sampler.h"; sourceTree = "SOURCE_ROOT"; }; C0AB1E87CD628F5534F41588 = { isa = PBXFileReference; lastKnownFileType = file; name = "juce_module_info"; path = "../../../../modules/juce_events/juce_module_info"; sourceTree = "SOURCE_ROOT"; }; C0EAB8DB78CC1330EBFB1BB4 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_win32_FileChooser.cpp"; path = "../../../../modules/juce_gui_basics/native/juce_win32_FileChooser.cpp"; sourceTree = "SOURCE_ROOT"; }; + C0EECABDA5446EAD76E2578F = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_OpenGLImage.cpp"; path = "../../../../modules/juce_opengl/opengl/juce_OpenGLImage.cpp"; sourceTree = "SOURCE_ROOT"; }; C0F4014BD42C942094A65784 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_MouseCursor.cpp"; path = "../../../../modules/juce_gui_basics/mouse/juce_MouseCursor.cpp"; sourceTree = "SOURCE_ROOT"; }; C10210AA8B1DD67E6943A2D4 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_AffineTransform.h"; path = "../../../../modules/juce_graphics/geometry/juce_AffineTransform.h"; sourceTree = "SOURCE_ROOT"; }; C19ACBBBAFAB7161C4114966 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_LassoComponent.h"; path = "../../../../modules/juce_gui_basics/mouse/juce_LassoComponent.h"; sourceTree = "SOURCE_ROOT"; }; @@ -1788,6 +1790,8 @@ 438CA87567F47F9AF39788D1, 153D339EB2CCEC711215AD04, 9B4278735225CBEED635FF03, + C0EECABDA5446EAD76E2578F, + 4CE76ABC51CC5E019AED3C2B, 8BA1AF085755958342C9213A, 651055751E902F40B83EFD55, 09089786B542AEB678DDE38F ); name = opengl; sourceTree = ""; }; diff --git a/extras/audio plugin host/Builds/VisualStudio2005/Plugin Host.vcproj b/extras/audio plugin host/Builds/VisualStudio2005/Plugin Host.vcproj index 6709ef315c..26332f456d 100644 --- a/extras/audio plugin host/Builds/VisualStudio2005/Plugin Host.vcproj +++ b/extras/audio plugin host/Builds/VisualStudio2005/Plugin Host.vcproj @@ -4153,6 +4153,17 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + true + true @@ -1520,6 +1523,7 @@ + diff --git a/extras/static library/Builds/VisualStudio2010/juce.vcxproj.filters b/extras/static library/Builds/VisualStudio2010/juce.vcxproj.filters index 89734cfd47..3e542b28e7 100644 --- a/extras/static library/Builds/VisualStudio2010/juce.vcxproj.filters +++ b/extras/static library/Builds/VisualStudio2010/juce.vcxproj.filters @@ -1378,6 +1378,9 @@ Juce Modules\juce_opengl\opengl + + Juce Modules\juce_opengl\opengl + Juce Modules\juce_opengl\opengl @@ -2607,6 +2610,9 @@ Juce Modules\juce_opengl\opengl + + Juce Modules\juce_opengl\opengl + Juce Modules\juce_opengl\opengl diff --git a/modules/juce_opengl/juce_opengl.cpp b/modules/juce_opengl/juce_opengl.cpp index 0c2d7e811f..7a2bdddd31 100644 --- a/modules/juce_opengl/juce_opengl.cpp +++ b/modules/juce_opengl/juce_opengl.cpp @@ -122,6 +122,7 @@ #include "opengl/juce_OpenGLComponent.cpp" #include "opengl/juce_OpenGLFrameBuffer.cpp" #include "opengl/juce_OpenGLHelpers.cpp" +#include "opengl/juce_OpenGLImage.cpp" #include "opengl/juce_OpenGLTexture.cpp" // END_AUTOINCLUDE diff --git a/modules/juce_opengl/juce_opengl.h b/modules/juce_opengl/juce_opengl.h index 07cf0a14d2..60c9ccec7b 100644 --- a/modules/juce_opengl/juce_opengl.h +++ b/modules/juce_opengl/juce_opengl.h @@ -95,6 +95,9 @@ BEGIN_JUCE_NAMESPACE #ifndef __JUCE_OPENGLHELPERS_JUCEHEADER__ #include "opengl/juce_OpenGLHelpers.h" #endif +#ifndef __JUCE_OPENGLIMAGE_JUCEHEADER__ + #include "opengl/juce_OpenGLImage.h" +#endif #ifndef __JUCE_OPENGLPIXELFORMAT_JUCEHEADER__ #include "opengl/juce_OpenGLPixelFormat.h" #endif diff --git a/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp b/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp index 9fef6e6092..9b169e9754 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp @@ -48,6 +48,8 @@ void OpenGLHelpers::prepareFor2D (int width, int height) #else glOrtho (0.0, width, 0.0, height, 0, 1); #endif + + glViewport (0, 0, width, height); } void OpenGLHelpers::setPerspective (double fovy, double aspect, double zNear, double zFar) diff --git a/modules/juce_opengl/opengl/juce_OpenGLImage.cpp b/modules/juce_opengl/opengl/juce_OpenGLImage.cpp new file mode 100644 index 0000000000..e9fb160b29 --- /dev/null +++ b/modules/juce_opengl/opengl/juce_OpenGLImage.cpp @@ -0,0 +1,193 @@ +/* + ============================================================================== + + This file is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-11 by Raw Material Software Ltd. + + ------------------------------------------------------------------------------ + + JUCE can be redistributed and/or modified under the terms of the GNU General + Public License (Version 2), as published by the Free Software Foundation. + A copy of the license is included in the JUCE distribution, or can be found + online at www.gnu.org/licenses. + + JUCE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + ------------------------------------------------------------------------------ + + To release a closed-source product which uses JUCE, commercial licenses are + available: visit www.rawmaterialsoftware.com/juce for more information. + + ============================================================================== +*/ + +BEGIN_JUCE_NAMESPACE + +OpenGLFrameBufferImage::OpenGLFrameBufferImage (Image::PixelFormat format, int width, int height) + : Image::SharedImage (format, width, height), + pixelStride (4), + lineStride (width * pixelStride) +{ + frameBuffer.initialise (width, height); + frameBuffer.clear (Colours::transparentBlack); +} + +OpenGLFrameBufferImage::~OpenGLFrameBufferImage() {} + +LowLevelGraphicsContext* OpenGLFrameBufferImage::createLowLevelContext() +{ + return new LowLevelGraphicsSoftwareRenderer (Image (this)); +} + +Image::SharedImage* OpenGLFrameBufferImage::clone() +{ + OpenGLFrameBufferImage* im = new OpenGLFrameBufferImage (getPixelFormat(), getWidth(), getHeight()); + im->incReferenceCount(); + + { + Image newImage (im); + Graphics g (newImage); + g.drawImageAt (Image (this), 0, 0, false); + } + + im->resetReferenceCount(); + return im; +} + +Image::ImageType OpenGLFrameBufferImage::getType() const +{ + return Image::NativeImage; +} + +namespace OpenGLImageHelpers +{ + struct Dummy + { + Dummy (OpenGLFrameBuffer&, int, int, int, int) noexcept {} + static void read (OpenGLFrameBuffer&, Image::BitmapData& , int, int) noexcept {} + static void write (const void*) noexcept {} + }; + + struct Reader + { + static void read (OpenGLFrameBuffer& frameBuffer, Image::BitmapData& bitmapData, int x, int y) + { + if (frameBuffer.makeCurrentTarget()) + { + OpenGLHelpers::prepareFor2D (frameBuffer.getWidth(), frameBuffer.getHeight()); + + glPixelStorei (GL_PACK_ALIGNMENT, 4); + glReadPixels (x, y, bitmapData.width, bitmapData.height, GL_RGBA, GL_UNSIGNED_BYTE, bitmapData.data); + frameBuffer.releaseCurrentTarget(); + } + } + }; + + struct Writer + { + Writer (OpenGLFrameBuffer& frameBuffer_, int x, int y, int w, int h) noexcept + : frameBuffer (frameBuffer_), area (x, y, w, h) + {} + + void write (const void* const data) const noexcept + { + if (frameBuffer.makeCurrentTarget()) + { + OpenGLHelpers::prepareFor2D (frameBuffer.getWidth(), frameBuffer.getHeight()); + + glDisable (GL_DEPTH_TEST); + glDisable (GL_BLEND); + + #if JUCE_OPENGL_ES + // GLES has no glDrawPixels function, so we have to create a texture and draw it.. + GLuint temporaryTexture = 0; + glGenTextures (1, &temporaryTexture); + jassert (temporaryTexture != 0); // can't create a texture! + + if (temporaryTexture != 0) + { + glEnable (GL_TEXTURE_2D); + glBindTexture (GL_TEXTURE_2D, temporaryTexture); + + glPixelStorei (GL_UNPACK_ALIGNMENT, 4); + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, area.getWidth(), area.getHeight(), 0, + GL_BGRA_EXT, GL_UNSIGNED_BYTE, data); + + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + const int cropRect[4] = { 0, 0, area.getWidth(), area.getHeight() }; + glTexParameteriv (GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); + + glDrawTexiOES (area.getX(), area.getY(), 1, area.getWidth(), area.getHeight()); + + glBindTexture (GL_TEXTURE_2D, 0); + glDeleteTextures (1, &temporaryTexture); + } + + #else + glRasterPos2i (area.getX(), area.getY()); + glBindTexture (GL_TEXTURE_2D, 0); + glPixelStorei (GL_UNPACK_ALIGNMENT, 4); + glDrawPixels (area.getWidth(), area.getHeight(), GL_BGRA_EXT, GL_UNSIGNED_BYTE, data); + #endif + + frameBuffer.releaseCurrentTarget(); + } + } + + OpenGLFrameBuffer& frameBuffer; + const Rectangle area; + + JUCE_DECLARE_NON_COPYABLE (Writer); + }; + + template + struct DataReleaser : public Image::BitmapData::BitmapDataReleaser + { + DataReleaser (OpenGLFrameBuffer& frameBuffer, size_t dataSize, int x, int y, int w, int h) + : data (dataSize), + writer (frameBuffer, x, y, w, h) + {} + + ~DataReleaser() + { + writer.write (data); + } + + static void initialise (OpenGLFrameBuffer& frameBuffer, Image::BitmapData& bitmapData, int x, int y) + { + DataReleaser* r = new DataReleaser (frameBuffer, bitmapData.lineStride * bitmapData.height, + x, y, bitmapData.width, bitmapData.height); + bitmapData.dataReleaser = r; + bitmapData.data = r->data + x * bitmapData.pixelStride + y * bitmapData.lineStride; + + ReaderType::read (frameBuffer, bitmapData, x, y); + } + + HeapBlock data; + WriterType writer; + }; +} + +void OpenGLFrameBufferImage::initialiseBitmapData (Image::BitmapData& bitmapData, int x, int y, + Image::BitmapData::ReadWriteMode mode) +{ + using namespace OpenGLImageHelpers; + + bitmapData.pixelFormat = format; + bitmapData.lineStride = lineStride; + bitmapData.pixelStride = pixelStride; + + switch (mode) + { + case Image::BitmapData::writeOnly: DataReleaser::initialise (frameBuffer, bitmapData, x, y); break; + case Image::BitmapData::readOnly: DataReleaser ::initialise (frameBuffer, bitmapData, x, y); break; + case Image::BitmapData::readWrite: DataReleaser::initialise (frameBuffer, bitmapData, x, y); break; + default: jassertfalse; break; + } +} + +END_JUCE_NAMESPACE diff --git a/modules/juce_opengl/opengl/juce_OpenGLImage.h b/modules/juce_opengl/opengl/juce_OpenGLImage.h new file mode 100644 index 0000000000..3261b2850b --- /dev/null +++ b/modules/juce_opengl/opengl/juce_OpenGLImage.h @@ -0,0 +1,70 @@ +/* + ============================================================================== + + This file is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-11 by Raw Material Software Ltd. + + ------------------------------------------------------------------------------ + + JUCE can be redistributed and/or modified under the terms of the GNU General + Public License (Version 2), as published by the Free Software Foundation. + A copy of the license is included in the JUCE distribution, or can be found + online at www.gnu.org/licenses. + + JUCE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + ------------------------------------------------------------------------------ + + To release a closed-source product which uses JUCE, commercial licenses are + available: visit www.rawmaterialsoftware.com/juce for more information. + + ============================================================================== +*/ + +#ifndef __JUCE_OPENGLIMAGE_JUCEHEADER__ +#define __JUCE_OPENGLIMAGE_JUCEHEADER__ + + +//============================================================================== +/** + A type of Image::SharedImage that stores its image data in an OpenGL + framebuffer, allowing a JUCE Image object to wrap a framebuffer. + + By creating an Image from an instance of an OpenGLFrameBufferImage, + you can then use a Graphics object to draw into the framebuffer using normal + JUCE 2D operations. + + @see Image, Image::SharedImage, OpenGLFrameBuffer +*/ +class JUCE_API OpenGLFrameBufferImage : public Image::SharedImage +{ +public: + OpenGLFrameBufferImage (Image::PixelFormat format, int width, int height); + + /** Destructor. */ + ~OpenGLFrameBufferImage(); + + /** The underlying framebuffer. + Although this is exposed to allow access to use it as a texture, etc, be + careful not to change its size while the image is using it. + */ + OpenGLFrameBuffer frameBuffer; + + /** @internal */ + LowLevelGraphicsContext* createLowLevelContext(); + /** @internal */ + SharedImage* clone(); + /** @internal */ + Image::ImageType getType() const; + /** @internal */ + void initialiseBitmapData (Image::BitmapData&, int, int, Image::BitmapData::ReadWriteMode); + +private: + int pixelStride, lineStride; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLFrameBufferImage); +}; + +#endif // __JUCE_OPENGLIMAGE_JUCEHEADER__