<commit_before>#include <assert.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <wayland-server-protocol.h>
#include <wayland-util.h>
#include <wlr/backend.h>
#include <wlr/render/egl.h>
#include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>
#include "render/gles2.h"
#include "glapi.h"

static const struct wlr_renderer_impl renderer_impl;

static struct wlr_gles2_renderer *gles2_get_renderer(
		struct wlr_renderer *wlr_renderer) {
	assert(wlr_renderer->impl == &renderer_impl);
	struct wlr_gles2_renderer *renderer =
		(struct wlr_gles2_renderer *)wlr_renderer;
	assert(eglGetCurrentContext() == renderer->egl->context);
	return renderer;
}

static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
		uint32_t height) {
	gles2_get_renderer(wlr_renderer);

	GLES2_DEBUG_PUSH;

	glViewport(0, 0, width, height);

	// enable transparency
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// XXX: maybe we should save output projection and remove some of the need
	// for users to sling matricies themselves

	GLES2_DEBUG_POP;
}

static void gles2_end(struct wlr_renderer *wlr_renderer) {
	gles2_get_renderer(wlr_renderer);
	// no-op
}

static void gles2_clear(struct wlr_renderer *wlr_renderer,
		const float color[static 4]) {
	gles2_get_renderer(wlr_renderer);

	GLES2_DEBUG_PUSH;
	glClearColor(color[0], color[1], color[2], color[3]);
	glClear(GL_COLOR_BUFFER_BIT);
	GLES2_DEBUG_POP;
}

static void gles2_scissor(struct wlr_renderer *wlr_renderer,
		struct wlr_box *box) {
	gles2_get_renderer(wlr_renderer);

	GLES2_DEBUG_PUSH;
	if (box != NULL) {
		glScissor(box->x, box->y, box->width, box->height);
		glEnable(GL_SCISSOR_TEST);
	} else {
		glDisable(GL_SCISSOR_TEST);
	}
	GLES2_DEBUG_POP;
}

static struct wlr_texture *gles2_renderer_texture_create(
		struct wlr_renderer *wlr_renderer) {
	assert(wlr_renderer->impl == &renderer_impl);
	struct wlr_gles2_renderer *renderer =
		(struct wlr_gles2_renderer *)wlr_renderer;
	return gles2_texture_create(renderer->egl);
}

static void draw_quad() {
	GLfloat verts[] = {
		1, 0, // top right
		0, 0, // top left
		1, 1, // bottom right
		0, 1, // bottom left
	};
	GLfloat texcoord[] = {
		1, 0, // top right
		0, 0, // top left
		1, 1, // bottom right
		0, 1, // bottom left
	};

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texcoord);

	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
}

static bool gles2_render_texture_with_matrix(
		struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture,
		const float matrix[static 9], float alpha) {
	struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
	struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
	if (!wlr_texture->valid) {
		wlr_log(L_ERROR, "attempt to render invalid texture");
		return false;
	}

	GLuint prog = renderer->shaders.tex_rgba;
	if (texture->target == GL_TEXTURE_EXTERNAL_OES) {
		prog = renderer->shaders.tex_ext;
	} else if (texture->pixel_format->wl_format == WL_SHM_FORMAT_XRGB8888 ||
			texture->pixel_format->wl_format == WL_SHM_FORMAT_XBGR8888) {
		prog = renderer->shaders.tex_rgbx;
	}

	// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
	// to GL_FALSE<commit_msg>render/gles2: use gles2_pixel_format::has_alpha for shader selection<commit_after>#include <assert.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <wayland-server-protocol.h>
#include <wayland-util.h>
#include <wlr/backend.h>
#include <wlr/render/egl.h>
#include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>
#include "render/gles2.h"
#include "glapi.h"

static const struct wlr_renderer_impl renderer_impl;

static struct wlr_gles2_renderer *gles2_get_renderer(
		struct wlr_renderer *wlr_renderer) {
	assert(wlr_renderer->impl == &renderer_impl);
	struct wlr_gles2_renderer *renderer =
		(struct wlr_gles2_renderer *)wlr_renderer;
	assert(eglGetCurrentContext() == renderer->egl->context);
	return renderer;
}

static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
		uint32_t height) {
	gles2_get_renderer(wlr_renderer);

	GLES2_DEBUG_PUSH;

	glViewport(0, 0, width, height);

	// enable transparency
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// XXX: maybe we should save output projection and remove some of the need
	// for users to sling matricies themselves

	GLES2_DEBUG_POP;
}

static void gles2_end(struct wlr_renderer *wlr_renderer) {
	gles2_get_renderer(wlr_renderer);
	// no-op
}

static void gles2_clear(struct wlr_renderer *wlr_renderer,
		const float color[static 4]) {
	gles2_get_renderer(wlr_renderer);

	GLES2_DEBUG_PUSH;
	glClearColor(color[0], color[1], color[2], color[3]);
	glClear(GL_COLOR_BUFFER_BIT);
	GLES2_DEBUG_POP;
}

static void gles2_scissor(struct wlr_renderer *wlr_renderer,
		struct wlr_box *box) {
	gles2_get_renderer(wlr_renderer);

	GLES2_DEBUG_PUSH;
	if (box != NULL) {
		glScissor(box->x, box->y, box->width, box->height);
		glEnable(GL_SCISSOR_TEST);
	} else {
		glDisable(GL_SCISSOR_TEST);
	}
	GLES2_DEBUG_POP;
}

static struct wlr_texture *gles2_renderer_texture_create(
		struct wlr_renderer *wlr_renderer) {
	assert(wlr_renderer->impl == &renderer_impl);
	struct wlr_gles2_renderer *renderer =
		(struct wlr_gles2_renderer *)wlr_renderer;
	return gles2_texture_create(renderer->egl);
}

static void draw_quad() {
	GLfloat verts[] = {
		1, 0, // top right
		0, 0, // top left
		1, 1, // bottom right
		0, 1, // bottom left
	};
	GLfloat texcoord[] = {
		1, 0, // top right
		0, 0, // top left
		1, 1, // bottom right
		0, 1, // bottom left
	};

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texcoord);

	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
}

static bool gles2_render_texture_with_matrix(
		struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture,
		const float matrix[static 9], float alpha) {
	struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
	struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
	if (!wlr_texture->valid) {
		wlr_log(L_ERROR, "attempt to render invalid texture");
		return false;
	}

	GLuint prog = renderer->shaders.tex_rgba;
	if (texture->target == GL_TEXTURE_EXTERNAL_OES) {
		prog = renderer->shaders.tex_ext;
	} else if (!texture->pixel_format->has_alpha) {
		prog = renderer->shaders.tex_rgbx;
	}

	// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
	// to GL_FALSE
{'fraction_non_alphanumeric': 0.1170378777131508, 'fraction_numerical': 0.022414526883245852, 'mean_word_length': 5.515711645101663, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 65, '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': '7522314', 'n_tokens_mistral': 2858, 'n_tokens_neox': 2841, 'n_words': 557}