An OpenGL texture. Handles async double-buffered PBO texture upload by default. Follows the same pattern as FBO --- create a texture by picking one of the growing number of static helpers in TextureSpecification that mask the complexity of OpenGL enums
| 45 | |
| 46 | /** |
| 47 | * An OpenGL texture. |
| 48 | * <p> |
| 49 | * Handles async double-buffered PBO texture upload by default. |
| 50 | * <p> |
| 51 | * Follows the same pattern as FBO --- create a texture by picking one of the growing number of static helpers in TextureSpecification that mask the complexity of OpenGL enums |
| 52 | */ |
| 53 | public class Texture extends BaseScene<Texture.State> implements Scene.Perform, OffersUniform<Integer>, BoxBrowser.HasMarkdownInformation { |
| 54 | |
| 55 | // global statistics on how much we're sending to OpennGL |
| 56 | static public int bytesUploaded = 0; |
| 57 | static FileAlterationMonitor ws = null; |
| 58 | public final TextureSpecification specification; |
| 59 | protected boolean bindless; |
| 60 | boolean isDoubleBuffered = true; |
| 61 | AtomicInteger pendingUploads = new AtomicInteger(0); |
| 62 | int boundCount = 0; |
| 63 | int uploadCount = 0; |
| 64 | AtomicReference<Runnable> postDrawQueue = new AtomicReference<>(); |
| 65 | |
| 66 | public Texture(TextureSpecification specification) { |
| 67 | this.specification = specification; |
| 68 | if (this.specification.forceSingleBuffered) setIsDoubleBuffered(false); |
| 69 | |
| 70 | if (specification.source != null) { |
| 71 | installReloadWatch(specification.source, this); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | private void installReloadWatch(String sourceFilename, Texture texture) { |
| 76 | |
| 77 | if (ws == null) { |
| 78 | ws = new FileAlterationMonitor(2000); |
| 79 | try { |
| 80 | ws.start(); |
| 81 | } catch (Exception e) { |
| 82 | e.printStackTrace(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | synchronized (ws) { |
| 88 | |
| 89 | String name = new File(sourceFilename).getName(); |
| 90 | |
| 91 | FileAlterationObserver o = new FileAlterationObserver(new File(sourceFilename).getParentFile(), |
| 92 | new NameFileFilter(name)); |
| 93 | try { |
| 94 | o.initialize(); |
| 95 | } catch (Exception e) { |
| 96 | e.printStackTrace(); |
| 97 | } |
| 98 | o.addListener(new FileAlterationListenerAdaptor() { |
| 99 | @Override |
| 100 | public void onFileChange(File file) { |
| 101 | if (file.getName().equals(name)) { |
| 102 | System.out.println(" automatic reload for texture :" + file); |
| 103 | texture.reloadFrom(file.getAbsolutePath()); |
| 104 | } |
no outgoing calls
no test coverage detected