<commit_before>package org.anddev.andengine.opengl.buffer;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL11;

import org.anddev.andengine.opengl.util.GLHelper;

/**
 * @author <NAME>
 * @since 14:22:56 - 07.04.2010
 */
public abstract class BufferObject {
	// ===========================================================
	// Constants
	// ===========================================================

	public static final int BYTES_PER_FLOAT = 4;

	private static final int[] HARDWAREBUFFERID_FETCHER = new int[1];

	// ===========================================================
	// Fields
	// ===========================================================

	private final int mByteCount;
	private final int mDrawType;
	
	private final FloatBuffer mFloatBuffer;

	private int mHardwareBufferID = -1;
	private boolean mLoadedToHardware;
	private boolean mHardwareBufferNeedsUpdate = true;
	
	// ===========================================================
	// Constructors
	// ===========================================================

	public BufferObject(final int pByteCount, final int pDrawType) {
		this.mByteCount = pByteCount;
		this.mDrawType = pDrawType;
		
		this.mFloatBuffer = ByteBuffer.allocateDirect(pByteCount).order(ByteOrder.nativeOrder()).asFloatBuffer();
	}

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	public FloatBuffer getFloatBuffer() {
		return this.mFloatBuffer;
	}

	public int getByteCount() {
		return this.mByteCount;
	}

	public int getHardwareBufferID() {
		return this.mHardwareBufferID;
	}

	public boolean isLoadedToHardware() {
		return this.mLoadedToHardware;
	}

	void setLoadedToHardware(final boolean pLoadedToHardware) {
		this.mLoadedToHardware = pLoadedToHardware;
	}

	public void setHardwareBufferNeedsUpdate(final boolean pHardwareBufferNeedsUpdate) {
		this.mHardwareBufferNeedsUpdate = pHardwareBufferNeedsUpdate;
	}

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	public void update(){
		this.mHardwareBufferNeedsUpdate = true;
	}

	// ===========================================================
	// Methods
	// ===========================================================

	public void selectOnHardware(final GL11 pGL11) {
		if(this.mHardwareBufferNeedsUpdate && this.mHardwareBufferID != -1) {
//			Debug.d("BufferObject.updating: ID = "  + this.mHardwareBufferID);
			this.mHardwareBufferNeedsUpdate = false;

			GLHelper.bindBuffer(pGL11, this.mHardwareBufferID);
			GLHelper.bufferData(pGL11, this, this.mDrawType);
		} else {
			GLHelper.bindBuffer(pGL11, this.mHardwareBufferID); // TODO Does this always need to be binded, or are just for buffers of the same 'type'(texture/vertex)?
		}<commit_msg>Minor change to BufferObject.<commit_after>package org.anddev.andengine.opengl.buffer;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL11;

import org.anddev.andengine.opengl.util.GLHelper;

/**
 * @author <NAME>
 * @since 14:22:56 - 07.04.2010
 */
public abstract class BufferObject {
	// ===========================================================
	// Constants
	// ===========================================================

	public static final int BYTES_PER_FLOAT = 4;

	private static final int[] HARDWAREBUFFERID_FETCHER = new int[1];

	// ===========================================================
	// Fields
	// ===========================================================

	private final int mByteCount;
	private final int mDrawType;
	
	private final FloatBuffer mFloatBuffer;

	private int mHardwareBufferID = -1;
	private boolean mLoadedToHardware;
	private boolean mHardwareBufferNeedsUpdate = true;
	
	// ===========================================================
	// Constructors
	// ===========================================================

	public BufferObject(final int pByteCount, final int pDrawType) {
		this.mByteCount = pByteCount;
		this.mDrawType = pDrawType;
		
		this.mFloatBuffer = ByteBuffer.allocateDirect(pByteCount).order(ByteOrder.nativeOrder()).asFloatBuffer();
	}

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	public FloatBuffer getFloatBuffer() {
		return this.mFloatBuffer;
	}

	public int getByteCount() {
		return this.mByteCount;
	}

	public int getHardwareBufferID() {
		return this.mHardwareBufferID;
	}

	public boolean isLoadedToHardware() {
		return this.mLoadedToHardware;
	}

	void setLoadedToHardware(final boolean pLoadedToHardware) {
		this.mLoadedToHardware = pLoadedToHardware;
	}

	public void setHardwareBufferNeedsUpdate(final boolean pHardwareBufferNeedsUpdate) {
		this.mHardwareBufferNeedsUpdate = pHardwareBufferNeedsUpdate;
	}

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	public void update(){
		this.mHardwareBufferNeedsUpdate = true;
	}

	// ===========================================================
	// Methods
	// ===========================================================

	public void selectOnHardware(final GL11 pGL11) {
		final int hardwareBufferID = this.mHardwareBufferID;
		if(hardwareBufferID == -1) {
			return;
		}

		GLHelper.bindBuffer(pGL11, hardwareBufferID); // TODO Does this always need to be binded, or are just for buffers of the same 'type'(texture/vertex)?
		
		if(this.mHardwareBufferNeedsUpdate) {
//			Debug.d("BufferObject.updating: ID = "  + this.mHardwareBufferID);
			this.mHardwareBufferNeedsUpdate = false;

			GLHelper.bufferData(pGL11, this, this.mDrawType);
		} 
{'fraction_non_alphanumeric': 0.31540917492858345, 'fraction_numerical': 0.00974626113258276, 'mean_word_length': 5.672645739910314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5041292', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1585, 'n_words': 315}