-
Notifications
You must be signed in to change notification settings - Fork 0
/
FullFrameRect.cs
86 lines (78 loc) · 2.74 KB
/
FullFrameRect.cs
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
84
85
86
using System;
namespace Grafika.GLES
{
/**
* This class essentially represents a viewport-sized sprite that will be rendered with
* a texture, usually from an external source like the camera or video decoder.
*/
public class FullFrameRect
{
private Drawable2d mRectDrawable = new Drawable2d(Drawable2d.Prefab.FULL_RECTANGLE);
private Texture2dProgram mProgram;
/**
* Prepares the object.
*
* @param program The program to use. FullFrameRect takes ownership, and will release
* the program when no longer needed.
*/
public FullFrameRect(Texture2dProgram program)
{
mProgram = program;
}
/**
* Releases resources.
* <p>
* This must be called with the appropriate EGL context current (i.e. the one that was
* current when the constructor was called). If we're about to destroy the EGL context,
* there's no value in having the caller make it current just to do this cleanup, so you
* can pass a flag that will tell this function to skip any EGL-context-specific cleanup.
*/
public void release(bool doEglCleanup)
{
if (mProgram != null)
{
if (doEglCleanup)
{
mProgram.release();
}
mProgram = null;
}
}
/**
* Returns the program currently in use.
*/
public Texture2dProgram getProgram()
{
return mProgram;
}
/**
* Changes the program. The previous program will be released.
* <p>
* The appropriate EGL context must be current.
*/
public void changeProgram(Texture2dProgram program)
{
mProgram.release();
mProgram = program;
}
/**
* Creates a texture object suitable for use with drawFrame().
*/
public int createTextureObject()
{
return mProgram.createTextureObject();
}
/**
* Draws a viewport-filling rect, texturing it with the specified texture object.
*/
public void drawFrame(int textureId, float[] texMatrix)
{
// Use the identity matrix for MVP so our 2x2 FULL_RECTANGLE covers the viewport.
mProgram.draw(GlUtil.IDENTITY_MATRIX, mRectDrawable.getVertexArray(), 0,
mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(),
mRectDrawable.getVertexStride(),
texMatrix, mRectDrawable.getTexCoordArray(), textureId,
mRectDrawable.getTexCoordStride());
}
}
}