Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedRenderable.java @ 227ac49a

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 android.opengl.GLES30;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
abstract class DistortedRenderable
27
  {
28
  static final int FAILED_TO_CREATE = -1;
29
  static final int NOT_CREATED_YET  = -2;
30
  static final int DONT_CREATE      = -3;
31

    
32
  int[] mColorH = new int[1];
33
  int mSizeX, mSizeY;  // in screen space
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
  abstract void create();
38
  abstract void delete();
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  long getID()
43
    {
44
    return mColorH[0];
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  boolean setAsInput()
50
    {
51
    if( mColorH[0]>0 )
52
      {
53
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
54
      return true;
55
      }
56

    
57
    return false;
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
// PUBLIC API
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
/**
64
 * Returns the height of the Renderable.
65
 *
66
 * @return height of the object, in pixels.
67
 */
68
  public int getWidth()
69
    {
70
    return mSizeX;
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
/**
75
 * Returns the width of the Renderable.
76
 *
77
 * @return width of the Object, in pixels.
78
 */
79
  public int getHeight()
80
    {
81
    return mSizeY;
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
/**
86
 * Returns the depth of the Renderable.
87
 * <p>
88
 * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
89
 * 'depth' of a Renderable (bitmap really!) when rendered based only on the texture itself, that depends
90
 * on the Mesh it is rendered with.
91
 *
92
 * @return depth of the Object, in pixels.
93
 */
94
  public int getDepth(MeshObject mesh)
95
    {
96
    return mesh==null ? 0 : (int)(mSizeX*mesh.zFactor);
97
    }
98
  }
(4-4/17)