/
FrameBuffer.java
83 lines (74 loc) · 3.28 KB
/
FrameBuffer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.badlogic.gdx.graphics.glutils;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
/** <p>
* Encapsulates OpenGL ES 2.0 frame buffer objects. This is a simple helper class which should cover most FBO uses. It will
* automatically create a texture for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the
* texture by {@link FrameBuffer#getColorBufferTexture()}. This class will only work with OpenGL ES 2.0.
* </p>
*
* <p>
* FrameBuffers are managed. In case of an OpenGL context loss, which only happens on Android when a user switches to another
* application or receives an incoming call, the framebuffer will be automatically recreated.
* </p>
*
* <p>
* A FrameBuffer must be disposed if it is no longer needed
* </p>
*
* @author mzechner, realitix */
public class FrameBuffer extends GLFrameBuffer<Texture> {
/** Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.
*
* @param format
* @param width
* @param height
* @param hasDepth
*/
public FrameBuffer (Pixmap.Format format, int width, int height, boolean hasDepth) {
this(format, width, height, hasDepth, false);
}
/** Creates a new FrameBuffer having the given dimensions and potentially a depth and a stencil buffer attached.
*
* @param format the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are
* color-renderable
* @param width the width of the framebuffer in pixels
* @param height the height of the framebuffer in pixels
* @param hasDepth whether to attach a depth buffer
* @throws com.badlogic.gdx.utils.GdxRuntimeException in case the FrameBuffer could not be created */
public FrameBuffer (Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil) {
super(format, width, height, hasDepth, hasStencil);
}
@Override
protected Texture createColorTexture () {
Texture result = new Texture(width, height, format);
result.setFilter(TextureFilter.Linear, TextureFilter.Linear);
result.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
return result;
}
@Override
protected void disposeColorTexture (Texture colorTexture) {
colorTexture.dispose();
}
/** See {@link GLFrameBuffer#unbind()} */
public static void unbind () {
GLFrameBuffer.unbind();
}
}