title: Apply Image Effects in GLSurfaceView while i scroll it in listview or RecyclerView [Android]
body: <p><strong>This is the class where I set bitmap to adapter</strong></p>
  <pre><code>  List&lt;ItemEffectObject&gt; bitmapList = new ArrayList&lt;&gt;();
          for(int i = 0 ; i &lt; 26 ; i++){
              ItemEffectObject itemObject = new ItemEffectObject();
              itemObject.setName(Effects.values()[i]);
              itemObject.setBitmap(bitmap);
              bitmapList.add(itemObject);
          }
          filterAlertAdapter = new FilterAlertAdapter(getContext(),bitmapList,mEffectContext);
          mRecyclerView.setAdapter(filterAlertAdapter);
          LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
          linearLayoutManager.scrollToPositionWithOffset(2,25);
          mRecyclerView.setLayoutManager(linearLayoutManager);
          filterAlertAdapter.setOnItemClickListener(new FilterAlertAdapter.OnItemClickListener() {
              @Override
              public void onItemClickListener(View view, int position) {
                  setCurrentEffect(Effects.values()[position]);
                  mEffectView.requestRender();
              }
          });
  </code></pre>
  <p><strong>This is ItemObject Dto</strong></p>
  <pre><code>public class ItemEffectObject {
  
          Effects name;
  
          Bitmap bitmap;
  
          public Effects getName() {
              return name;
          }
  
          public void setName(Effects name) {
              this.name = name;
          }
  
          public Bitmap getBitmap() {
              return bitmap;
          }
  
          public void setBitmap(Bitmap bitmap) {
              this.bitmap = bitmap;
          }
  }
  </code></pre>
  <p><strong>This is my RecyclerView Adapter</strong></p>
  <p>I need a list of effect applying image list. While I load this code it show an exception. Thanks in advance.</p>
  <blockquote>
  <p>RuntimeException: Apply Wrong GL context exception</p>
  </blockquote>
  <pre><code>public class FilterAlertAdapter extends RecyclerView.Adapter implements GLSurfaceView.Renderer{
  
      private List&lt;ItemEffectObject&gt; bitmapList;
      private int mSelectedPosition = 0;
      private Context mContext;
      private OnItemClickListener mItemClickListener;
      private int value = 10;
      private TextureRenderer mTexRenderer = new TextureRenderer();
      private EffectContext mEffectContext;
      private boolean mInitialized = false;
      private int[] mTextures = new int[2];
      ViewHolder holder = null;
      int position;
      private GLSurfaceView.Renderer renderer = this;
      private Effects mCurrentEffect;
      private Effect mEffect;
      int mImageWidth = 0;
      int mImageHeight = 0;
  
  
      public FilterAlertAdapter(Context context, List&lt;ItemEffectObject&gt; bitmapList,EffectContext mEffectContext) {
          this.mEffectContext = mEffectContext;
          this.bitmapList = bitmapList;
          mContext = context;
      }
  
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          return new ViewHolder(View.inflate(mContext, R.layout.inflater_image_filter, null));
      }
  
      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder baseHolder, final int position) {
         holder = (ViewHolder)baseHolder;
                  holder.mEffectView.setEGLContextClientVersion(2);
                  holder.mEffectView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
                  holder.mEffectView.setRenderer(renderer);
                  holder.mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
                  setCurrentEffect(bitmapList.get(position).getName());
                  holder.mEffectView.requestRender();
  
         /* ImageLoaders imageLoader = new ImageLoaders(bitmapList.get(position).getBitmap());
          imageLoader.applyFilter(String.valueOf(bitmapList.get(position).getName()), holder.mEffectView);*/
      }
  
      private void setCurrentEffect(Effects effects) {
          mCurrentEffect = effects;
      }
  
  
      @Override
      public void onSurfaceCreated(GL10 gl, EGLConfig config) {
          gl.glClearColor(0.8f, 0.8f, 0.8f, 1);
      }
  
      @Override
      public void onSurfaceChanged(GL10 gl, int width, int height) {
          if (mTexRenderer != null) {
              mTexRenderer.updateViewSize(width, height);
          }
      }
  
  
      @Override
      public void onDrawFrame(GL10 gl) {
          if (!mInitialized) {
              //Only need to do this once
              mTexRenderer.init();
              loadTextures();
              mInitialized = true;
          }
          if (mCurrentEffect != Effects.NONE) {
              //if an effect is chosen initialize it and apply it to the texture
              mEffectContext = EffectContext.createWithCurrentGlContext();
             /* mEffect = ApplyEffects.newInstance().applyEffectOnBitmap(mCurrentEffect,mEffect,mEffectContext,mTextures,
                      mImageHeight,mImageWidth);*/
  //            mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
              mTextures = ApplyEffects.newInstance().applyEffectOnBitmap(mCurrentEffect,mEffect,mEffectContext,mTextures,
                      mImageHeight,mImageWidth);
          }
          renderResult();
      }
  
      private void loadTextures() {
          GLES20.glGenTextures(2, mTextures, 0);
          // Load input bitmap
          Bitmap bitmap = bitmapList.get(position).getBitmap();
          mImageWidth = bitmap.getWidth();
          mImageHeight = bitmap.getHeight();
          mTexRenderer.updateTextureSize(holder.mEffectView.getWidth(), holder.mEffectView.getHeight());
  
          // Upload to texture
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
          GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
  
          // Set texture parameters
          GLToolbox.initTexParams();
      }
  
      private void renderResult() {
          if (mCurrentEffect != Effects.NONE) {
              // if no effect is chosen, just render the original bitmap
              mTexRenderer.renderTexture(mTextures[1]);
          } else {
              // render the result of applyEffect()
              mTexRenderer.renderTexture(mTextures[0]);
          }
      }
  
      @Override
      public int getItemCount() {
          return bitmapList.size();
      }
  
      class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener  {
  
          GLSurfaceView mEffectView;
  
          public ViewHolder(View view) {
              super(view);
              mEffectView = (GLSurfaceView) view.findViewById(R.id.inflater_image_filter_gl);
              view.setOnClickListener(this);
          }
  
          @Override
          public void onClick(View view) {
              if (mItemClickListener != null) {
                  mItemClickListener.onItemClickListener(view, getLayoutPosition());
                  mSelectedPosition = getLayoutPosition();
                  notifyItemChanged(mSelectedPosition);
              }
          }
      }
  
      public interface OnItemClickListener {
          void onItemClickListener(View view, int position);
      }
  
      public void setOnItemClickListener(final OnItemClickListener itemClickListener) {
          mItemClickListener = itemClickListener;
      }
  
  //    public class AsyncSurfaceView extends AsyncTask&lt;&gt;
  
  }
  </code></pre>
  <p><strong>This is the place to apply effects in images</strong></p>
  <pre><code>public class ApplyEffects {
  
      public static ApplyEffects newInstance(){
          return new ApplyEffects();
      }
  
      public int[] applyEffectOnBitmap(Effects mCurrentEffect, Effect mEffect, EffectContext mEffectContext, int[] mTextures,
                                       int mImageHeight, int mImageWidth){
          EffectFactory effectFactory = mEffectContext.getFactory();
          if (mEffect != null) {
              mEffect.release();
          }
          // Initialize the correct effect based on the selected menu/action item
          switch (mCurrentEffect) {
  
              case NONE:
                  break;
  
              case AUTOFIX:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX);
                  mEffect.setParameter(&quot;scale&quot;, 0.5f);
                  break;
  
              case MIN_MAX_COLOR_INTENSITY:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BLACKWHITE);
                  mEffect.setParameter(&quot;black&quot;, .1f);
                  mEffect.setParameter(&quot;white&quot;, .7f);
                  break;
  
              case BRIGHTNESS:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BRIGHTNESS);
                  mEffect.setParameter(&quot;brightness&quot;, 2.0f);
                  break;
  
              case CONTRAST:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CONTRAST);
                  mEffect.setParameter(&quot;contrast&quot;, 1.4f);
                  break;
  
              case CROSS_PROCESS:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CROSSPROCESS);
                  break;
  
              case DOCUMENTARY:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DOCUMENTARY);
                  break;
  
              case DUO_TONE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DUOTONE);
                  mEffect.setParameter(&quot;first_color&quot;, Color.YELLOW);
                  mEffect.setParameter(&quot;second_color&quot;, Color.DKGRAY);
                  break;
  
              case FILL_LIGHT:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FILLLIGHT);
                  mEffect.setParameter(&quot;strength&quot;, .8f);
                  break;
  
              case FISH_EYE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE);
                  mEffect.setParameter(&quot;scale&quot;, .5f);
                  break;
  
              case FLIP_VERTICAL:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
                  mEffect.setParameter(&quot;vertical&quot;, true);
                  break;
  
              case FLIP_HORIZONTAL:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
                  mEffect.setParameter(&quot;horizontal&quot;, true);
                  break;
  
              case GRAIN:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN);
                  mEffect.setParameter(&quot;strength&quot;, 1.0f);
                  break;
  
              case GRAYSCALE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAYSCALE);
                  break;
  
              case LOMOISH:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_LOMOISH);
                  break;
  
              case NEGATIVE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE);
                  break;
  
              case POSTERIZE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_POSTERIZE);
                  break;
  
              case ROTATE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_ROTATE);
                  mEffect.setParameter(&quot;angle&quot;, 180);
                  break;
  
              case SATURATE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SATURATE);
                  mEffect.setParameter(&quot;scale&quot;, .5f);
                  break;
  
              case SEPIA:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SEPIA);
                  break;
  
              case SHARPEN:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SHARPEN);
                  break;
  
              case TEMPERATURE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TEMPERATURE);
                  mEffect.setParameter(&quot;scale&quot;, .9f);
                  break;
  
              case TINT:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
                  mEffect.setParameter(&quot;tint&quot;, Color.MAGENTA);
                  break;
  
              case VIGNETTE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_VIGNETTE);
                  mEffect.setParameter(&quot;scale&quot;, .5f);
                  break;
  
              case TINT_BLUE:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
                  mEffect.setParameter(&quot;tint&quot;, Color.BLUE);
                  break;
  
              case TINT_RED:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
                  mEffect.setParameter(&quot;tint&quot;, Color.RED);
                  break;
  
              case TINT_GREEN:
                  mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
                  mEffect.setParameter(&quot;tint&quot;, Color.GREEN);
                  break;
  
              default:
                  break;
          }
          if (mCurrentEffect != Effects.NONE){
              mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
          }
          return mTextures;
      }
  }
  </code></pre>
  <p>I'm using GLSurfaceView OpenGL ES 2.0. I applying android default image effects to that bitmap list and get that bitmap list to show in sample of images like instagram sample images. below is original image what I want.</p>
  <p><a href="https://i.stack.imgur.com/yWZ41.jpg" rel="nofollow noreferrer">Image</a></p>