The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

780 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. class OpenGLContext::CachedImage : public CachedComponentImage,
  19. public Thread
  20. {
  21. public:
  22. CachedImage (OpenGLContext& context_,
  23. Component& component_,
  24. const OpenGLPixelFormat& pixelFormat,
  25. const OpenGLContext* contextToShareWith)
  26. : Thread ("OpenGL Rendering"),
  27. context (context_), component (component_),
  28. #if JUCE_OPENGL_ES
  29. shadersAvailable (true),
  30. #else
  31. shadersAvailable (false),
  32. #endif
  33. needsUpdate (true)
  34. {
  35. nativeContext = new NativeContext (component, pixelFormat,
  36. contextToShareWith != nullptr ? contextToShareWith->nativeContext
  37. : nullptr);
  38. if (nativeContext->createdOk())
  39. {
  40. context.nativeContext = nativeContext;
  41. #if ! JUCE_ANDROID
  42. startThread (6);
  43. #endif
  44. }
  45. else
  46. {
  47. nativeContext = nullptr;
  48. }
  49. }
  50. ~CachedImage()
  51. {
  52. #if ! JUCE_ANDROID
  53. stopThread (10000);
  54. #endif
  55. }
  56. //==============================================================================
  57. void paint (Graphics&)
  58. {
  59. ComponentPeer* const peer = component.getPeer();
  60. if (peer != nullptr)
  61. peer->addMaskedRegion (peer->getComponent()->getLocalArea (&component, component.getLocalBounds()));
  62. }
  63. void invalidateAll()
  64. {
  65. validArea.clear();
  66. triggerRepaint();
  67. }
  68. void invalidate (const Rectangle<int>& area)
  69. {
  70. validArea.subtract (area);
  71. triggerRepaint();
  72. }
  73. void releaseResources() {}
  74. void triggerRepaint()
  75. {
  76. needsUpdate = true;
  77. #if JUCE_ANDROID
  78. if (nativeContext != nullptr)
  79. nativeContext->triggerRepaint();
  80. #else
  81. notify();
  82. #endif
  83. }
  84. //==============================================================================
  85. bool ensureFrameBufferSize (int width, int height)
  86. {
  87. const int fbW = cachedImageFrameBuffer.getWidth();
  88. const int fbH = cachedImageFrameBuffer.getHeight();
  89. if (fbW != width || fbH != height || ! cachedImageFrameBuffer.isValid())
  90. {
  91. if (! cachedImageFrameBuffer.initialise (context, width, height))
  92. return false;
  93. validArea.clear();
  94. JUCE_CHECK_OPENGL_ERROR
  95. }
  96. return true;
  97. }
  98. void clearRegionInFrameBuffer (const RectangleList& list)
  99. {
  100. glClearColor (0, 0, 0, 0);
  101. glEnable (GL_SCISSOR_TEST);
  102. const GLuint previousFrameBufferTarget = OpenGLFrameBuffer::getCurrentFrameBufferTarget();
  103. cachedImageFrameBuffer.makeCurrentRenderingTarget();
  104. for (RectangleList::Iterator i (list); i.next();)
  105. {
  106. const Rectangle<int>& r = *i.getRectangle();
  107. glScissor (r.getX(), component.getHeight() - r.getBottom(), r.getWidth(), r.getHeight());
  108. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  109. }
  110. glDisable (GL_SCISSOR_TEST);
  111. context.extensions.glBindFramebuffer (GL_FRAMEBUFFER, previousFrameBufferTarget);
  112. JUCE_CHECK_OPENGL_ERROR
  113. }
  114. bool renderFrame()
  115. {
  116. if (! context.makeActive())
  117. return false;
  118. NativeContext::Locker locker (*nativeContext);
  119. JUCE_CHECK_OPENGL_ERROR
  120. glViewport (0, 0, component.getWidth(), component.getHeight());
  121. if (context.renderer != nullptr)
  122. {
  123. context.renderer->renderOpenGL();
  124. clearGLError();
  125. }
  126. if (context.renderComponents)
  127. paintComponent();
  128. context.swapBuffers();
  129. return true;
  130. }
  131. void paintComponent()
  132. {
  133. if (needsUpdate)
  134. {
  135. MessageManagerLock mm (this);
  136. if (! mm.lockWasGained())
  137. return;
  138. needsUpdate = false;
  139. // you mustn't set your own cached image object when attaching a GL context!
  140. jassert (get (component) == this);
  141. const Rectangle<int> bounds (component.getLocalBounds());
  142. if (! ensureFrameBufferSize (bounds.getWidth(), bounds.getHeight()))
  143. return;
  144. RectangleList invalid (bounds);
  145. invalid.subtract (validArea);
  146. validArea = bounds;
  147. if (! invalid.isEmpty())
  148. {
  149. clearRegionInFrameBuffer (invalid);
  150. {
  151. ScopedPointer<LowLevelGraphicsContext> g (createOpenGLGraphicsContext (context, cachedImageFrameBuffer));
  152. g->clipToRectangleList (invalid);
  153. paintOwner (*g);
  154. JUCE_CHECK_OPENGL_ERROR
  155. }
  156. context.makeActive();
  157. }
  158. JUCE_CHECK_OPENGL_ERROR
  159. }
  160. #if ! JUCE_ANDROID
  161. glEnable (GL_TEXTURE_2D);
  162. clearGLError();
  163. #endif
  164. context.extensions.glActiveTexture (GL_TEXTURE0);
  165. glBindTexture (GL_TEXTURE_2D, cachedImageFrameBuffer.getTextureID());
  166. const Rectangle<int> cacheBounds (cachedImageFrameBuffer.getWidth(), cachedImageFrameBuffer.getHeight());
  167. context.copyTexture (cacheBounds, cacheBounds, context.getWidth(), context.getHeight());
  168. glBindTexture (GL_TEXTURE_2D, 0);
  169. JUCE_CHECK_OPENGL_ERROR
  170. }
  171. void paintOwner (LowLevelGraphicsContext& context)
  172. {
  173. Graphics g (&context);
  174. #if JUCE_ENABLE_REPAINT_DEBUGGING
  175. g.saveState();
  176. #endif
  177. JUCE_TRY
  178. {
  179. component.paintEntireComponent (g, false);
  180. }
  181. JUCE_CATCH_EXCEPTION
  182. #if JUCE_ENABLE_REPAINT_DEBUGGING
  183. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  184. // clearly when things are being repainted.
  185. g.restoreState();
  186. static Random rng;
  187. g.fillAll (Colour ((uint8) rng.nextInt (255),
  188. (uint8) rng.nextInt (255),
  189. (uint8) rng.nextInt (255),
  190. (uint8) 0x50));
  191. #endif
  192. }
  193. //==============================================================================
  194. void run()
  195. {
  196. {
  197. // Allow the message thread to finish setting-up the context before using it..
  198. MessageManagerLock mml (this);
  199. if (! mml.lockWasGained())
  200. return;
  201. }
  202. nativeContext->makeActive();
  203. initialiseOnThread();
  204. #if JUCE_USE_OPENGL_SHADERS && ! JUCE_OPENGL_ES
  205. shadersAvailable = OpenGLShaderProgram::getLanguageVersion() > 0;
  206. #endif
  207. while (! threadShouldExit())
  208. {
  209. const uint32 frameRenderStartTime = Time::getMillisecondCounter();
  210. if (renderFrame())
  211. waitForNextFrame (frameRenderStartTime);
  212. }
  213. shutdownOnThread();
  214. }
  215. void initialiseOnThread()
  216. {
  217. associatedObjectNames.clear();
  218. associatedObjects.clear();
  219. nativeContext->initialiseOnRenderThread();
  220. glViewport (0, 0, component.getWidth(), component.getHeight());
  221. context.extensions.initialise();
  222. if (context.renderer != nullptr)
  223. context.renderer->newOpenGLContextCreated();
  224. }
  225. void shutdownOnThread()
  226. {
  227. if (context.renderer != nullptr)
  228. context.renderer->openGLContextClosing();
  229. nativeContext->shutdownOnRenderThread();
  230. associatedObjectNames.clear();
  231. associatedObjects.clear();
  232. }
  233. void waitForNextFrame (const uint32 frameRenderStartTime)
  234. {
  235. const int defaultFPS = 60;
  236. const int elapsed = (int) (Time::getMillisecondCounter() - frameRenderStartTime);
  237. wait (jmax (1, (1000 / defaultFPS) - elapsed));
  238. }
  239. //==============================================================================
  240. static CachedImage* get (Component& c) noexcept
  241. {
  242. return dynamic_cast<CachedImage*> (c.getCachedComponentImage());
  243. }
  244. //==============================================================================
  245. ScopedPointer<NativeContext> nativeContext;
  246. OpenGLContext& context;
  247. Component& component;
  248. OpenGLFrameBuffer cachedImageFrameBuffer;
  249. RectangleList validArea;
  250. StringArray associatedObjectNames;
  251. ReferenceCountedArray<ReferenceCountedObject> associatedObjects;
  252. WaitableEvent canPaintNowFlag, finishedPaintingFlag;
  253. bool volatile shadersAvailable;
  254. bool volatile needsUpdate;
  255. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CachedImage);
  256. };
  257. //==============================================================================
  258. #if JUCE_ANDROID
  259. void OpenGLContext::NativeContext::contextCreatedCallback()
  260. {
  261. isInsideGLCallback = true;
  262. CachedImage* const c = CachedImage::get (component);
  263. jassert (c != nullptr);
  264. if (c != nullptr)
  265. c->initialiseOnThread();
  266. isInsideGLCallback = false;
  267. }
  268. void OpenGLContext::NativeContext::renderCallback()
  269. {
  270. isInsideGLCallback = true;
  271. CachedImage* const c = CachedImage::get (component);
  272. if (c != nullptr)
  273. c->renderFrame();
  274. isInsideGLCallback = false;
  275. }
  276. #endif
  277. //==============================================================================
  278. class OpenGLContext::Attachment : public ComponentMovementWatcher
  279. {
  280. public:
  281. Attachment (OpenGLContext& context_, Component& comp)
  282. : ComponentMovementWatcher (&comp), context (context_)
  283. {
  284. if (canBeAttached (comp))
  285. attach();
  286. }
  287. ~Attachment()
  288. {
  289. detach();
  290. }
  291. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  292. {
  293. Component* const comp = getComponent();
  294. if (isAttached (*comp) != canBeAttached (*comp))
  295. componentVisibilityChanged();
  296. context.width = comp->getWidth();
  297. context.height = comp->getHeight();
  298. if (comp->getWidth() > 0 && comp->getHeight() > 0
  299. && context.nativeContext != nullptr)
  300. {
  301. context.nativeContext->updateWindowPosition (comp->getTopLevelComponent()
  302. ->getLocalArea (comp, comp->getLocalBounds()));
  303. }
  304. }
  305. void componentPeerChanged()
  306. {
  307. detach();
  308. componentVisibilityChanged();
  309. }
  310. void componentVisibilityChanged()
  311. {
  312. Component* const comp = getComponent();
  313. if (canBeAttached (*comp))
  314. {
  315. if (! isAttached (*comp))
  316. attach();
  317. }
  318. else
  319. {
  320. detach();
  321. }
  322. }
  323. #if JUCE_DEBUG || JUCE_LOG_ASSERTIONS
  324. void componentBeingDeleted (Component& component)
  325. {
  326. /* You must call detach() or delete your OpenGLContext to remove it
  327. from a component BEFORE deleting the component that it is using!
  328. */
  329. jassertfalse;
  330. ComponentMovementWatcher::componentBeingDeleted (component);
  331. }
  332. #endif
  333. private:
  334. OpenGLContext& context;
  335. static bool canBeAttached (const Component& comp) noexcept
  336. {
  337. return comp.getWidth() > 0 && comp.getHeight() > 0 && comp.isShowing();
  338. }
  339. static bool isAttached (const Component& comp) noexcept
  340. {
  341. return comp.getCachedComponentImage() != nullptr;
  342. }
  343. void attach()
  344. {
  345. Component* const comp = getComponent();
  346. comp->setCachedComponentImage (new CachedImage (context, *comp,
  347. context.pixelFormat,
  348. context.contextToShareWith));
  349. }
  350. void detach()
  351. {
  352. getComponent()->setCachedComponentImage (nullptr);
  353. }
  354. };
  355. //==============================================================================
  356. OpenGLContext::OpenGLContext()
  357. : nativeContext (nullptr), renderer (nullptr), contextToShareWith (nullptr),
  358. width (0), height (0), renderComponents (true)
  359. {
  360. }
  361. OpenGLContext::~OpenGLContext()
  362. {
  363. detach();
  364. }
  365. void OpenGLContext::setRenderer (OpenGLRenderer* rendererToUse) noexcept
  366. {
  367. // This method must not be called when the context has already been attached!
  368. // Call it before attaching your context, or use detach() first, before calling this!
  369. jassert (nativeContext == nullptr);
  370. renderer = rendererToUse;
  371. }
  372. void OpenGLContext::setComponentPaintingEnabled (bool shouldPaintComponent) noexcept
  373. {
  374. // This method must not be called when the context has already been attached!
  375. // Call it before attaching your context, or use detach() first, before calling this!
  376. jassert (nativeContext == nullptr);
  377. renderComponents = shouldPaintComponent;
  378. }
  379. void OpenGLContext::setPixelFormat (const OpenGLPixelFormat& preferredPixelFormat) noexcept
  380. {
  381. // This method must not be called when the context has already been attached!
  382. // Call it before attaching your context, or use detach() first, before calling this!
  383. jassert (nativeContext == nullptr);
  384. pixelFormat = preferredPixelFormat;
  385. }
  386. void OpenGLContext::setContextToShareWith (const OpenGLContext* context) noexcept
  387. {
  388. // This method must not be called when the context has already been attached!
  389. // Call it before attaching your context, or use detach() first, before calling this!
  390. jassert (nativeContext == nullptr);
  391. contextToShareWith = context;
  392. }
  393. void OpenGLContext::attachTo (Component& component)
  394. {
  395. component.repaint();
  396. if (getTargetComponent() != &component)
  397. {
  398. detach();
  399. width = component.getWidth();
  400. height = component.getHeight();
  401. attachment = new Attachment (*this, component);
  402. }
  403. }
  404. void OpenGLContext::detach()
  405. {
  406. attachment = nullptr;
  407. nativeContext = nullptr;
  408. width = height = 0;
  409. }
  410. bool OpenGLContext::isAttached() const noexcept
  411. {
  412. return nativeContext != nullptr;
  413. }
  414. Component* OpenGLContext::getTargetComponent() const noexcept
  415. {
  416. return attachment != nullptr ? attachment->getComponent() : nullptr;
  417. }
  418. OpenGLContext* OpenGLContext::getCurrentContext()
  419. {
  420. #if JUCE_ANDROID
  421. NativeContext* const nc = NativeContext::getActiveContext();
  422. if (nc == nullptr)
  423. return nullptr;
  424. CachedImage* currentContext = CachedImage::get (nc->component);
  425. #else
  426. CachedImage* currentContext = dynamic_cast <CachedImage*> (Thread::getCurrentThread());
  427. #endif
  428. return currentContext != nullptr ? &currentContext->context : nullptr;
  429. }
  430. bool OpenGLContext::makeActive() const noexcept { return nativeContext != nullptr && nativeContext->makeActive(); }
  431. bool OpenGLContext::isActive() const noexcept { return nativeContext != nullptr && nativeContext->isActive(); }
  432. void OpenGLContext::triggerRepaint()
  433. {
  434. CachedImage* const currentContext
  435. = dynamic_cast <CachedImage*> (Thread::getCurrentThread());
  436. if (currentContext != nullptr)
  437. {
  438. currentContext->triggerRepaint();
  439. currentContext->component.repaint();
  440. }
  441. }
  442. void OpenGLContext::swapBuffers()
  443. {
  444. if (nativeContext != nullptr)
  445. nativeContext->swapBuffers();
  446. }
  447. unsigned int OpenGLContext::getFrameBufferID() const noexcept
  448. {
  449. return nativeContext != nullptr ? nativeContext->getFrameBufferID() : 0;
  450. }
  451. bool OpenGLContext::setSwapInterval (int numFramesPerSwap)
  452. {
  453. return nativeContext != nullptr && nativeContext->setSwapInterval (numFramesPerSwap);
  454. }
  455. int OpenGLContext::getSwapInterval() const
  456. {
  457. return nativeContext != nullptr ? nativeContext->getSwapInterval() : 0;
  458. }
  459. void* OpenGLContext::getRawContext() const noexcept
  460. {
  461. return nativeContext != nullptr ? nativeContext->getRawContext() : nullptr;
  462. }
  463. OpenGLContext::CachedImage* OpenGLContext::getCachedImage() const noexcept
  464. {
  465. Component* const comp = getTargetComponent();
  466. return comp != nullptr ? CachedImage::get (*comp) : nullptr;
  467. }
  468. bool OpenGLContext::areShadersAvailable() const
  469. {
  470. CachedImage* const c = getCachedImage();
  471. return c != nullptr && c->shadersAvailable;
  472. }
  473. ReferenceCountedObject* OpenGLContext::getAssociatedObject (const char* name) const
  474. {
  475. jassert (name != nullptr);
  476. CachedImage* const c = getCachedImage();
  477. // This method must only be called from an openGL rendering callback.
  478. jassert (c != nullptr && nativeContext != nullptr);
  479. jassert (getCurrentContext() != nullptr);
  480. const int index = c->associatedObjectNames.indexOf (name);
  481. return index >= 0 ? c->associatedObjects.getUnchecked (index) : nullptr;
  482. }
  483. void OpenGLContext::setAssociatedObject (const char* name, ReferenceCountedObject* newObject)
  484. {
  485. jassert (name != nullptr);
  486. CachedImage* const c = getCachedImage();
  487. // This method must only be called from an openGL rendering callback.
  488. jassert (c != nullptr && nativeContext != nullptr);
  489. jassert (getCurrentContext() != nullptr);
  490. const int index = c->associatedObjectNames.indexOf (name);
  491. if (index >= 0)
  492. {
  493. c->associatedObjects.set (index, newObject);
  494. }
  495. else
  496. {
  497. c->associatedObjectNames.add (name);
  498. c->associatedObjects.add (newObject);
  499. }
  500. }
  501. void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
  502. const Rectangle<int>& anchorPosAndTextureSize,
  503. const int contextWidth, const int contextHeight)
  504. {
  505. if (contextWidth <= 0 || contextHeight <= 0)
  506. return;
  507. JUCE_CHECK_OPENGL_ERROR
  508. glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  509. glEnable (GL_BLEND);
  510. #if JUCE_USE_OPENGL_SHADERS
  511. if (areShadersAvailable())
  512. {
  513. struct OverlayShaderProgram : public ReferenceCountedObject
  514. {
  515. OverlayShaderProgram (OpenGLContext& context)
  516. : program (context), builder (program), params (program)
  517. {}
  518. static const OverlayShaderProgram& select (OpenGLContext& context)
  519. {
  520. static const char programValueID[] = "juceGLComponentOverlayShader";
  521. OverlayShaderProgram* program = static_cast <OverlayShaderProgram*> (context.getAssociatedObject (programValueID));
  522. if (program == nullptr)
  523. {
  524. program = new OverlayShaderProgram (context);
  525. context.setAssociatedObject (programValueID, program);
  526. }
  527. program->program.use();
  528. return *program;
  529. }
  530. struct ProgramBuilder
  531. {
  532. ProgramBuilder (OpenGLShaderProgram& program)
  533. {
  534. program.addShader ("attribute " JUCE_HIGHP " vec2 position;"
  535. "uniform " JUCE_HIGHP " vec2 screenSize;"
  536. "varying " JUCE_HIGHP " vec2 pixelPos;"
  537. "void main()"
  538. "{"
  539. "pixelPos = position;"
  540. JUCE_HIGHP " vec2 scaled = position / (0.5 * screenSize.xy);"
  541. "gl_Position = vec4 (scaled.x - 1.0, 1.0 - scaled.y, 0, 1.0);"
  542. "}",
  543. GL_VERTEX_SHADER);
  544. program.addShader ("uniform sampler2D imageTexture;"
  545. "uniform " JUCE_HIGHP " float textureBounds[4];"
  546. "varying " JUCE_HIGHP " vec2 pixelPos;"
  547. "void main()"
  548. "{"
  549. JUCE_HIGHP " vec2 texturePos = (pixelPos - vec2 (textureBounds[0], textureBounds[1]))"
  550. "/ vec2 (textureBounds[2], textureBounds[3]);"
  551. "gl_FragColor = texture2D (imageTexture, vec2 (texturePos.x, 1.0 - texturePos.y));"
  552. "}",
  553. GL_FRAGMENT_SHADER);
  554. program.link();
  555. }
  556. };
  557. struct Params
  558. {
  559. Params (OpenGLShaderProgram& program)
  560. : positionAttribute (program, "position"),
  561. screenSize (program, "screenSize"),
  562. imageTexture (program, "imageTexture"),
  563. textureBounds (program, "textureBounds")
  564. {}
  565. void set (const float targetWidth, const float targetHeight, const Rectangle<float>& bounds) const
  566. {
  567. const GLfloat m[] = { bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() };
  568. textureBounds.set (m, 4);
  569. imageTexture.set (0);
  570. screenSize.set (targetWidth, targetHeight);
  571. }
  572. OpenGLShaderProgram::Attribute positionAttribute;
  573. OpenGLShaderProgram::Uniform screenSize, imageTexture, textureBounds;
  574. };
  575. OpenGLShaderProgram program;
  576. ProgramBuilder builder;
  577. Params params;
  578. };
  579. const GLshort left = (GLshort) targetClipArea.getX();
  580. const GLshort top = (GLshort) targetClipArea.getY();
  581. const GLshort right = (GLshort) targetClipArea.getRight();
  582. const GLshort bottom = (GLshort) targetClipArea.getBottom();
  583. const GLshort vertices[] = { left, bottom, right, bottom, left, top, right, top };
  584. const OverlayShaderProgram& program = OverlayShaderProgram::select (*this);
  585. program.params.set ((float) contextWidth, (float) contextHeight, anchorPosAndTextureSize.toFloat());
  586. extensions.glVertexAttribPointer (program.params.positionAttribute.attributeID, 2, GL_SHORT, GL_FALSE, 4, vertices);
  587. extensions.glEnableVertexAttribArray (program.params.positionAttribute.attributeID);
  588. JUCE_CHECK_OPENGL_ERROR
  589. glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
  590. extensions.glUseProgram (0);
  591. extensions.glDisableVertexAttribArray (program.params.positionAttribute.attributeID);
  592. }
  593. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  594. else
  595. #endif
  596. #endif
  597. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  598. {
  599. glEnable (GL_SCISSOR_TEST);
  600. glScissor (targetClipArea.getX(), contextHeight - targetClipArea.getBottom(),
  601. targetClipArea.getWidth(), targetClipArea.getHeight());
  602. JUCE_CHECK_OPENGL_ERROR
  603. glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
  604. glDisableClientState (GL_COLOR_ARRAY);
  605. glDisableClientState (GL_NORMAL_ARRAY);
  606. glEnableClientState (GL_VERTEX_ARRAY);
  607. glEnableClientState (GL_TEXTURE_COORD_ARRAY);
  608. OpenGLHelpers::prepareFor2D (contextWidth, contextHeight);
  609. JUCE_CHECK_OPENGL_ERROR
  610. const GLfloat textureCoords[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f };
  611. glTexCoordPointer (2, GL_FLOAT, 0, textureCoords);
  612. const GLshort left = (GLshort) anchorPosAndTextureSize.getX();
  613. const GLshort right = (GLshort) anchorPosAndTextureSize.getRight();
  614. const GLshort top = (GLshort) (contextHeight - anchorPosAndTextureSize.getY());
  615. const GLshort bottom = (GLshort) (contextHeight - anchorPosAndTextureSize.getBottom());
  616. const GLshort vertices[] = { left, bottom, right, bottom, left, top, right, top };
  617. glVertexPointer (2, GL_SHORT, 0, vertices);
  618. glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
  619. glDisable (GL_SCISSOR_TEST);
  620. }
  621. #endif
  622. JUCE_CHECK_OPENGL_ERROR
  623. }