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.

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