<commit_before>#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/CameraUi.h"
#include "cinder/Utilities.h"
#include "cinder/CinderAssert.h"
#include "cinder/Log.h"
#include "cinder/params/Params.h"

// Define this to blow up the selection area that is picked.
//#define DEBUG_PICKING 1

using namespace ci;
using namespace ci::app;

class PickingFBOApp : public App {
  public:
	void setup() override;
	void resize() override;
	void draw() override;
	void mouseDown( MouseEvent event ) override;
	void mouseDrag( MouseEvent event ) override;

	int pick( const ivec2 &mousePos );
	void setupParams();
	void setupShader();
	void setupGeometry();
	void setupGrid( int xSize, int zSize, int spacing );
	void setupGradient();
	void setupFbo();

	void renderScene();
	uint32_t colorToIndex( const ColorA8u &color );
	ColorA8u indexToColor( uint32_t index );
	vec4 colorToVec4( const ColorA8u &color );
	void setPickingColors( bool selectVertices, bool selectEdges );
	void restoreDefaultColors();
	void setSelectedColors( int selected );

	gl::VboMeshRef		mVerticesMesh;
	gl::VboMeshRef		mEdgesMesh;
	gl::VertBatchRef	mGridMesh;
	gl::BatchRef		mGradientMesh;
	gl::BatchRef		mVerticesBatch;
	gl::BatchRef		mEdgesBatch;

	gl::FboRef			mFbo;
	gl::GlslProgRef		mPickableProg;
	gl::GlslProgRef		mNotPickableProg;
	int					mPickPixelSize;
	ivec2				mPickPos;
	CameraPersp			mCamera;
	CameraUi			mCamUi;
	vec4				mDefaultVertexColor;
	vec4				mDefaultEdgeColor;
	vec4				mSelectedVertexColor;
	vec4				mSelectedEdgeColor;
	mat4				mBoxTransform;
	gl::TextureRef		mDebugTexture;
	float				mDebugDisplaySize;
	gl::Texture2dRef	mPickingTexture;
	bool				mNeedsRedraw;
	bool				mSelectVertices;
	bool				mSelectEdges;
	params::InterfaceGlRef		mParams;
};

void PickingFBOApp::setup()
{
	mDefaultVertexColor = vec4( 0.7f, 0.3f, 0.7f, 1.0f );
	mDefaultEdgeColor = vec4( 0.3f, 0.7f, 0.9f, 1.0f );
	mSelectedVertexColor = vec4( 0.7f, 0.7f, 0.3f, 1.0f );
	mSelectedEdgeColor = vec4( 0.9f, 0.7f, 0.3f, 1.0f );

	mPickPixelSize = 6;
	mSelectVertices = true;
	mSelectEdges = true;

	setupParams();
	setupShader();
	setupGradient();
	setupGrid( 200, 200, 10 );
	setupGeometry();
	setupFbo();

	mCamera.lookAt( vec3( 100, 100, 100 ), vec3( 0 ) );
	mCamUi = CameraUi( &mCamera );

	mBoxTransform = mat4( 1.0f );
	mBoxTransform = glm::scale( mBoxTransform, vec3( 30.0f ) );
	mBoxTransform = glm::translate( mBoxTransform, vec3( 0.0f, 0.5f, 0.0f ) );

	mNeedsRedraw = true;
	mDebugDisplaySize = 20.0f;

	gl::enableDepthWrite();
	gl::enableDepthRead();
}

void PickingFBOApp::resize()
{
	mCamUi.setWindowSize( getWindowSize() );
	mCamera.setPerspective( 60, getWindowAspectRatio(), 1, 1000 );

	setupFbo();
	mNeedsRedraw = true;
}

void PickingFBOApp::draw()
{
	if( mNeedsRedraw )
		renderScene();

	gl::clear();
	gl::disableDepthRead();
	gl::setMatricesWindow( toPixels( getWindowSize() ) );
	gl::draw( mFbo->getColorTexture(), toPixels( getWindowBounds() ) );
	if( mDebugTexture ) {
		gl::color( Color::white() );
		gl::draw( mDebugTexture, Rectf( mPickPos.x - mDebugDisplaySize, mPickPos.y - mDebugDisplaySize, mPickPos.x + mDebugDisplaySize, mPickPos.y + mDebugDisplaySize ) );
	}
#if ! defined( CINDER_GL_ES )
	mParams->draw();
#endif
	gl::enableDepthRead();
}

void PickingFBOApp::renderScene()
{
	gl::ScopedFramebuffer scopedFbo( mFbo );
	gl::clear( ci::ColorA( 0.0f, 0.0f, 0.0f, 0.0f ) );

	gl::ScopedGlslProg glslScope( mNotPickableProg );
	gl::setDefaultShaderVars();

	// Draw gradient.
	gl::disableDepthWrite();
	gl::pushMatrices();
	gl::setMatricesWindow( 1, 1 );
	mGradientMesh->draw();
	gl::popMatrices();<commit_msg>Fix for PickingFBO sample... ...as suggested by @gaborpapp, see #1049.<commit_after>#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/CameraUi.h"
#include "cinder/Utilities.h"
#include "cinder/CinderAssert.h"
#include "cinder/Log.h"
#include "cinder/params/Params.h"

// Define this to blow up the selection area that is picked.
//#define DEBUG_PICKING

using namespace ci;
using namespace ci::app;

class PickingFBOApp : public App {
  public:
	void setup() override;
	void resize() override;
	void draw() override;
	void mouseDown( MouseEvent event ) override;
	void mouseDrag( MouseEvent event ) override;

	int pick( const ivec2 &mousePos );
	void setupParams();
	void setupShader();
	void setupGeometry();
	void setupGrid( int xSize, int zSize, int spacing );
	void setupGradient();
	void setupFbo();

	void renderScene();
	uint32_t colorToIndex( const ColorA8u &color );
	ColorA8u indexToColor( uint32_t index );
	vec4 colorToVec4( const ColorA8u &color );
	void setPickingColors( bool selectVertices, bool selectEdges );
	void restoreDefaultColors();
	void setSelectedColors( int selected );

	gl::VboMeshRef		mVerticesMesh;
	gl::VboMeshRef		mEdgesMesh;
	gl::VertBatchRef	mGridMesh;
	gl::BatchRef		mGradientMesh;
	gl::BatchRef		mVerticesBatch;
	gl::BatchRef		mEdgesBatch;

	gl::FboRef			mFbo;
	gl::GlslProgRef		mPickableProg;
	gl::GlslProgRef		mNotPickableProg;
	int					mPickPixelSize;
	ivec2				mPickPos;
	CameraPersp			mCamera;
	CameraUi			mCamUi;
	vec4				mDefaultVertexColor;
	vec4				mDefaultEdgeColor;
	vec4				mSelectedVertexColor;
	vec4				mSelectedEdgeColor;
	mat4				mBoxTransform;
	gl::TextureRef		mDebugTexture;
	float				mDebugDisplaySize;
	gl::Texture2dRef	mPickingTexture;
	bool				mNeedsRedraw;
	bool				mSelectVertices;
	bool				mSelectEdges;
	params::InterfaceGlRef		mParams;
};

void PickingFBOApp::setup()
{
	mDefaultVertexColor = vec4( 0.7f, 0.3f, 0.7f, 1.0f );
	mDefaultEdgeColor = vec4( 0.3f, 0.7f, 0.9f, 1.0f );
	mSelectedVertexColor = vec4( 0.7f, 0.7f, 0.3f, 1.0f );
	mSelectedEdgeColor = vec4( 0.9f, 0.7f, 0.3f, 1.0f );

	mPickPixelSize = 6;
	mSelectVertices = true;
	mSelectEdges = true;

	setupParams();
	setupShader();
	setupGradient();
	setupGrid( 200, 200, 10 );
	setupGeometry();
	setupFbo();

	mCamera.lookAt( vec3( 100, 100, 100 ), vec3( 0 ) );
	mCamUi = CameraUi( &mCamera );

	mBoxTransform = mat4( 1.0f );
	mBoxTransform = glm::scale( mBoxTransform, vec3( 30.0f ) );
	mBoxTransform = glm::translate( mBoxTransform, vec3( 0.0f, 0.5f, 0.0f ) );

	mNeedsRedraw = true;
	mDebugDisplaySize = 20.0f;

	gl::enableDepthWrite();
	gl::enableDepthRead();
}

void PickingFBOApp::resize()
{
	mCamUi.setWindowSize( getWindowSize() );
	mCamera.setPerspective( 60, getWindowAspectRatio(), 1, 1000 );

	setupFbo();
	mNeedsRedraw = true;
}

void PickingFBOApp::draw()
{
	if( mNeedsRedraw )
		renderScene();

	gl::clear();
	gl::disableDepthRead();
	gl::setMatricesWindow( toPixels( getWindowSize() ) );
	gl::draw( mFbo->getColorTexture(), toPixels( getWindowBounds() ) );
	if( mDebugTexture ) {
		gl::color( Color::white() );
		gl::draw( mDebugTexture, Rectf( mPickPos.x - mDebugDisplaySize, mPickPos.y - mDebugDisplaySize, mPickPos.x + mDebugDisplaySize, mPickPos.y + mDebugDisplaySize ) );
	}
#if ! defined( CINDER_GL_ES )
	mParams->draw();
#endif
	gl::enableDepthRead();
}

void PickingFBOApp::renderScene()
{
	gl::ScopedFramebuffer scopedFbo( mFbo );
	gl::clear( ci::ColorA( 0.0f, 0.0f, 0.0f, 0.0f ) );

	gl::ScopedGlslProg glslScope( mNotPickableProg );
	gl::setDefaultShaderVars();

	gl::ScopedBlend blend( false );

	// Draw gradient.
	gl::disableDepthWrite();
	gl::pushMatrices();
	gl::setMatricesWindow( 1, 1 );
	mGradientMesh->draw();
	gl::popMatrices();
{'fraction_non_alphanumeric': 0.13494529244900716, 'fraction_numerical': 0.029852762393624208, 'mean_word_length': 4.970967741935484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '407854', 'n_tokens_mistral': 3111, 'n_tokens_neox': 2882, 'n_words': 618}