<commit_before>#include "ShaderNew.h"

#include "common/Vector.h"

#include <GL/GLee.h>
#include <stdio.h>
#include <wx/wx.h>

namespace d2d
{

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

static const int ATTRIB_VERTEX    = 0;
static const int ATTRIB_TEXTCOORD = 1;
static const int ATTRIB_COLOR     = 2;
static const int ATTRIB_ADDITIVE  = 3;

ShaderNew* ShaderNew::m_instance = NULL;

int ShaderNew::MAX_COMMBINE = 20000;
//int ShaderNew::MAX_COMMBINE = 4096;

ShaderNew* ShaderNew::Instance()
{
	if (!m_instance)
	{
		m_instance = new ShaderNew();
		m_instance->load();
	}
	return m_instance;
}

ShaderNew::ShaderNew()
{
	m_prog_curr = 0;
	m_prog_sprite = 0;
	m_prog_shape = 0;

	VertexBuffer = IndexBuffer = 0;
	m_sprite_count = 0;
	m_vb = NULL;
	m_tex = 0;
	m_fbo = 0;

	m_color = 0xffffffff;
	m_additive = 0;

	m_version = 0;

	m_open_buffer_data = true;
}

void ShaderNew::SetSpriteColor(const Colorf& multi, const Colorf& add)
{
	// ABGR
	m_color = ((int)(multi.a * 255 + 0.5f) << 24) | 
		((int)(multi.b * 255 + 0.5f) << 16) | 
		((int)(multi.g * 255 + 0.5f) << 8) | 
		((int)(multi.r * 255 + 0.5f));
	m_additive = ((int)(add.a * 255 + 0.5f) << 24) | 
		((int)(add.b * 255 + 0.5f) << 16) | 
		((int)(add.g * 255 + 0.5f) << 8) | 
		((int)(add.r * 255 + 0.5f));
}

void ShaderNew::SetShapeColor(const Colorf& col)
{
	if (m_prog_curr == m_prog_shape) {
		glUniform4fv(m_col_loc, 1, (GLfloat*)(&col.r));
	}
}

void ShaderNew::sprite()
{
	if (m_prog_curr != m_prog_sprite) {
		if (m_sprite_count != 0) {
			wxLogDebug(_T("Shader Commit change shader to sprite"));
		}

		Commit();

		glEnable(GL_BLEND);

		// todo Դejoy2dõGL_ONE
		//		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glUseProgram(m_prog_sprite);
		m_prog_curr = m_prog_sprite;
	}
}

void ShaderNew::shape()
{
	if (m_prog_curr != m_prog_shape) {
		if (m_sprite_count != 0) {
//			wxLogDebug(_T("Shader Commit change shader to shape"));
		}

		Commit();

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glUseProgram(m_prog_shape);
		m_prog_curr = m_prog_shape;

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	}
}

void ShaderNew::null()
{
	if (m_sprite_count != 0) {
		wxLogDebug(_T("Shader Commit change shader to null"));
	}

	Commit();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glUseProgram(0);
	m_prog_curr = 0;
}

void ShaderNew::release()<commit_msg>[FIXED] 画shape时tex设置不对<commit_after>#include "ShaderNew.h"

#include "common/Vector.h"

#include <GL/GLee.h>
#include <stdio.h>
#include <wx/wx.h>

namespace d2d
{

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

static const int ATTRIB_VERTEX    = 0;
static const int ATTRIB_TEXTCOORD = 1;
static const int ATTRIB_COLOR     = 2;
static const int ATTRIB_ADDITIVE  = 3;

ShaderNew* ShaderNew::m_instance = NULL;

int ShaderNew::MAX_COMMBINE = 20000;
//int ShaderNew::MAX_COMMBINE = 4096;

ShaderNew* ShaderNew::Instance()
{
	if (!m_instance)
	{
		m_instance = new ShaderNew();
		m_instance->load();
	}
	return m_instance;
}

ShaderNew::ShaderNew()
{
	m_prog_curr = 0;
	m_prog_sprite = 0;
	m_prog_shape = 0;

	VertexBuffer = IndexBuffer = 0;
	m_sprite_count = 0;
	m_vb = NULL;
	m_tex = 0;
	m_fbo = 0;

	m_color = 0xffffffff;
	m_additive = 0;

	m_version = 0;

	m_open_buffer_data = true;
}

void ShaderNew::SetSpriteColor(const Colorf& multi, const Colorf& add)
{
	// ABGR
	m_color = ((int)(multi.a * 255 + 0.5f) << 24) | 
		((int)(multi.b * 255 + 0.5f) << 16) | 
		((int)(multi.g * 255 + 0.5f) << 8) | 
		((int)(multi.r * 255 + 0.5f));
	m_additive = ((int)(add.a * 255 + 0.5f) << 24) | 
		((int)(add.b * 255 + 0.5f) << 16) | 
		((int)(add.g * 255 + 0.5f) << 8) | 
		((int)(add.r * 255 + 0.5f));
}

void ShaderNew::SetShapeColor(const Colorf& col)
{
	if (m_prog_curr == m_prog_shape) {
		glUniform4fv(m_col_loc, 1, (GLfloat*)(&col.r));
	}
}

void ShaderNew::sprite()
{
	if (m_prog_curr != m_prog_sprite) {
		if (m_sprite_count != 0) {
			wxLogDebug(_T("Shader Commit change shader to sprite"));
		}

		Commit();

		glEnable(GL_BLEND);

		// todo Դejoy2dõGL_ONE
		//		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glUseProgram(m_prog_sprite);
		m_prog_curr = m_prog_sprite;
	}
}

void ShaderNew::shape()
{
	if (m_prog_curr != m_prog_shape) {
		if (m_sprite_count != 0) {
//			wxLogDebug(_T("Shader Commit change shader to shape"));
		}

		Commit();

		SetTexture(0);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glUseProgram(m_prog_shape);
		m_prog_curr = m_prog_shape;

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	}
}

void ShaderNew::null()
{
	if (m_sprite_count != 0) {
		wxLogDebug(_T("Shader Commit change shader to null"));
	}

	Commit();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glUseProgram(0);
	m_prog_curr = 0;
}

void ShaderNew::release()
{'fraction_non_alphanumeric': 0.15667001003009026, 'fraction_numerical': 0.033901705115346036, 'mean_word_length': 4.281779661016949, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2541870', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2188, 'n_words': 405}