Project

General

Profile

« Previous | Next » 

Revision 7cb8d4b0

Added by Leszek Koltunski about 2 years ago

Mode the 'iconMode' from static variable in ObjectControl to member varaible in TwistyObject (safer)

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
23 23
import javax.microedition.khronos.opengles.GL10;
24 24

  
25 25
import android.app.Activity;
26
import android.opengl.GLES31;
26 27
import android.opengl.GLSurfaceView;
27 28
import android.widget.Toast;
28 29

  
29 30
import org.distorted.dialogs.RubikDialogSaveBandaged;
31
import org.distorted.library.effect.PostprocessEffectBorder;
32
import org.distorted.library.main.DistortedEffects;
33
import org.distorted.library.main.DistortedFramebuffer;
30 34
import org.distorted.library.main.DistortedLibrary;
31 35
import org.distorted.library.main.DistortedNode;
32 36
import org.distorted.library.main.DistortedScreen;
33 37

  
38
import org.distorted.library.type.Static1D;
34 39
import org.distorted.library.type.Static3D;
35 40
import org.distorted.library.type.Static4D;
36 41
import org.distorted.objectlib.json.JsonWriter;
42
import org.distorted.objectlib.main.ObjectControl;
43
import org.distorted.objectlib.main.ShapeHexahedron;
37 44
import org.distorted.objectlib.main.TwistyObject;
38 45
import org.distorted.objectlib.objects.TwistyBandagedGeneric;
39 46
import org.json.JSONException;
......
41 48
import java.io.File;
42 49
import java.io.FileNotFoundException;
43 50
import java.io.IOException;
51
import java.nio.ByteBuffer;
52
import java.nio.ByteOrder;
44 53

  
45 54
///////////////////////////////////////////////////////////////////////////////////////////////////
46 55

  
47 56
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
48 57
{
58
   public static final float BRIGHTNESS = 0.333f;
49 59
   private static final int DURATION = 1000;
50 60

  
51 61
   static final int COLOR_DEFAULT = 0xffffff55;
......
95 105
   private float mScaleValue;
96 106
   private float mX, mY, mZ, mW;
97 107
   private boolean mResetQuats, mSetQuatT, mResettingObject;
108
   private int mSaveIcon;
109
   private DistortedFramebuffer mFramebuffer;
110
   private String mPath;
98 111

  
99 112
///////////////////////////////////////////////////////////////////////////////////////////////////
100 113

  
101 114
   BandagedCreatorRenderer(BandagedCreatorView v)
102 115
     {
103
     final float BRIGHTNESS = 0.333f;
104

  
105 116
     mQuatT = new Static4D(0,0,0,1);
106 117
     mQuatA = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
107 118

  
......
111 122
     mSetQuatT       = false;
112 123
     mResettingObject= false;
113 124

  
125
     mSaveIcon = -1;
126

  
114 127
     mScreen = new DistortedScreen();
115 128
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
116 129
     mScale = new Static3D(1,1,1);
......
216 229
       boolean done = continueResetting(time);
217 230
       if( done ) mResettingObject = false;
218 231
       }
232

  
233
     if( mSaveIcon>=0 ) mSaveIcon++;
234
     if( mSaveIcon>=2 ) { saveIcon(); mSaveIcon = -1; }
219 235
     }
220 236

  
221 237
///////////////////////////////////////////////////////////////////////////////////////////////////
......
347 363
     BandagedCreatorActivity act = (BandagedCreatorActivity) mView.getContext();
348 364

  
349 365
     boolean success = createObjectJson(obj,act);
366
     setupIconCreation(obj,act);
350 367

  
351 368
     if( success )
352 369
       {
......
411 428
     }
412 429

  
413 430
///////////////////////////////////////////////////////////////////////////////////////////////////
414
/*
415
   private void createIcon(TwistyObject object)
431

  
432
   private void setupIconCreation(TwistyObject object, Activity act)
416 433
     {
417
     if( !mIconActive )
418
       {
419
       mIconActive = true;
420

  
421
       ObjectControl control = getControl();
422
       DistortedEffects effects = object.getObjectEffects();
423

  
424
       Static4D defRot = ShapeHexahedron.DEFAULT_ROT;
425
       Static1D halo = new Static1D(5);
426
       control.rotateNow(defRot);
427
       float scale = 1.15f;
428
       control.scaleNow(scale);
429
       Static4D color = new Static4D(0,0,0,1);
430
       PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color);
431
       border.setHaloDepth(false);
432
       effects.apply(border);
433
       String objectName = object.getShortName();
434
       final String name = STORAGE+objectName+".png";
435
       renderer.setSaveIcon(name);
436
       }
434
/*
435
     // create framebuffer, attach object's node to it
436

  
437
     ObjectControl control = getControl();
438
     DistortedEffects effects = object.getObjectEffects();
439

  
440
     Static4D defRot = ShapeHexahedron.DEFAULT_ROT;
441
     Static1D halo = new Static1D(5);
442
     control.rotateNow(defRot);
443
     float scale = 1.15f;
444
     control.scaleNow(scale);
445
     Static4D color = new Static4D(0,0,0,1);
446
     PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color);
447
     border.setHaloDepth(false);
448
     effects.apply(border);
449

  
450
     final String name = object.getShortName()+".png";
451
     File file = new File(act.getFilesDir(), name);
452
     String filename = file.getAbsolutePath();
453

  
454
     mSaveIcon = 0;
455
     mPath = filename;
456
 */
437 457
     }
438
*/
458

  
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

  
461
    private void saveIcon()
462
      {
463
      int fW = mFramebuffer.getWidth();
464
      int fH = mFramebuffer.getHeight();
465
      ByteBuffer buf = ByteBuffer.allocateDirect(fW*fH*4);
466
      buf.order(ByteOrder.LITTLE_ENDIAN);
467

  
468
      int textureID = mFramebuffer.getTextureID();
469

  
470
      if( textureID>=0 )
471
        {
472
        GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, textureID);
473
        GLES31.glReadPixels( 0, 0, fW, fH, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, buf);
474
        BandagedCreatorWorkerThread.newBuffer(buf,fW,fH,6,mPath);
475
        }
476
      else
477
        {
478
        android.util.Log.e("Save", "Error trying to read from offscreen FBO, textureID="+textureID);
479
        }
480

  
481
      mSaveIcon = -1;
482
      }
483

  
439 484
///////////////////////////////////////////////////////////////////////////////////////////////////
440 485

  
441 486
   public void displaySavingDialog()

Also available in: Unified diff