Project

General

Profile

Download (3.63 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedFramebufferList.java @ dedacd82

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library;
21

    
22
import java.util.LinkedList;
23
import java.util.Iterator;
24

    
25
/**
26
 * List of all DistortedFramebuffer objects currently created by the application.
27
 *
28
 * The point: we need to be able to mark Framebuffers for deletion, and delete all marked
29
 * objects later at a convenient time (that's because we can only delete from a thread that
30
 * holds the OpenGL context so here we provide a framework where one is able to mark for deletion
31
 * at any place and actual deletion takes place on the next render).
32
 */
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
final class DistortedFramebufferList
37
  {
38
  private static boolean mMarked = false;
39
  private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  static synchronized void add(DistortedFramebuffer drt)
44
    {
45
    mList.add(drt);
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  static synchronized void markForDeletion()
51
    {
52
    mMarked = true;
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  static synchronized void release()
58
    {
59
    mMarked = false;
60
    mList.clear();
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
// must be called form a thread holding OpenGL Context
65

    
66
  static synchronized void deleteAllMarked()
67
    {
68
    if( mMarked )
69
      {
70
      DistortedFramebuffer tmp;
71
      Iterator<DistortedFramebuffer> iterator = mList.iterator();
72

    
73
      while(iterator.hasNext())
74
        {
75
        tmp = iterator.next();
76

    
77
        if( tmp.mMarked )
78
          {
79
          tmp.release();
80
          iterator.remove();
81
          }
82
        }
83

    
84
      mMarked = false;
85
      }
86
    }
87
  }
(7-7/19)