[libcamera-devel,v3,3/6] pipeline: simple: Implements Texture Handling
diff mbox series

Message ID 20220814160747.52093-3-kunalagarwal1072002@gmail.com
State New
Headers show
Series
  • [libcamera-devel,v3,1/6] pipeline: simple: shader: Shaders for debayering
Related show

Commit Message

Kunal Agarwal Aug. 14, 2022, 4:07 p.m. UTC
Texture Class which includes functions for binding, unbinding,
deleting and rendering on textures

Signed-off-by: Kunal Agarwal <kunalagarwal1072002@gmail.com>
---
 src/libcamera/pipeline/simple/texture.cpp | 53 +++++++++++++++++++++++
 src/libcamera/pipeline/simple/texture.h   | 42 ++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 src/libcamera/pipeline/simple/texture.cpp
 create mode 100644 src/libcamera/pipeline/simple/texture.h

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/simple/texture.cpp b/src/libcamera/pipeline/simple/texture.cpp
new file mode 100644
index 00000000..3551ebc7
--- /dev/null
+++ b/src/libcamera/pipeline/simple/texture.cpp
@@ -0,0 +1,53 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Kunal Agarwal
+ *
+ * texture.cpp - Texture Handling
+ */
+
+#include "texture.h"
+
+#include <libcamera/framebuffer.h>
+
+#include <GLES3/gl3.h>
+
+namespace libcamera {
+void Texture::initTexture(GLenum slot)
+{
+	/* Generates an OpenGL texture object and assigns the texture to a Texture Unit  */
+	glGenTextures(1, &idTex_);
+	glActiveTexture(slot);
+	glBindTexture(type_, idTex_);
+
+	/* Configures the type of algorithm that is used to make the image smaller or bigger */
+	glTexParameteri(type_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(type_, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+	/* Prevents edge bleeding */
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+}
+
+void Texture::startTexture(MappedFrameBuffer *image, GLenum format, GLenum pixelType, Size pixelSize)
+{
+	/* Assigns the image to the OpenGL Texture object */
+	glTexImage2D(type_, 0, GL_LUMINANCE, pixelSize.width, pixelSize.height, 0, format, pixelType, image->planes()[0].data());
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, idTex_, 0);
+}
+
+void Texture::bind()
+{
+	glBindTexture(type_, idTex_);
+}
+
+void Texture::unbind()
+{
+	glBindTexture(type_, 0);
+}
+
+void Texture::deleteText()
+{
+	glDeleteTextures(1, &idTex_);
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/pipeline/simple/texture.h b/src/libcamera/pipeline/simple/texture.h
new file mode 100644
index 00000000..c4a41f6f
--- /dev/null
+++ b/src/libcamera/pipeline/simple/texture.h
@@ -0,0 +1,42 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Kunal Agarwal
+ *
+ * texture.h - Texture Handling
+ */
+
+#pragma once
+
+#include <libcamera/geometry.h>
+
+#include "libcamera/internal/mapped_framebuffer.h"
+
+#include "shader.h"
+
+namespace libcamera {
+
+class FrameBuffer;
+
+class Texture
+{
+public:
+	GLuint idTex_;
+	GLenum type_;
+
+	Texture(GLenum texType, GLuint rend_text)
+		: idTex_(rend_text), type_(texType){};
+
+	void initTexture(GLenum slot);
+
+	void startTexture(MappedFrameBuffer *image, GLenum format, GLenum pixelType, Size pixelSize);
+
+	void texUnit(ShaderProgram &shader, const char *uniform, GLuint unit);
+
+	void bind();
+
+	void unbind();
+
+	void deleteText();
+};
+
+} /* namespace libcamera */