From patchwork Sun Aug 14 16:07:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunal Agarwal X-Patchwork-Id: 17118 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BCA9BC3272 for ; Sun, 14 Aug 2022 16:08:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85CFE61FC0; Sun, 14 Aug 2022 18:08:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660493336; bh=r2idUaRfzEcTQdxg1Ff5xpPqVRdDMeYRlgk/SOSaxS0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=4SXdutv8JWfRiE7kfs7b2sCUx4EBi+Rjss/PLzOFYn+tS8Uao+2OCiAFEvGP9CdIb TGAZ0KhVOZXT71TEQr95Br54jwqpM/kWOilVgDwLNgnOrDpQLvO7kL0h2g64DnFogg qzSug1Vo445Ist2UxW5z5xzJHn1zOvrOO+4x9471RKBmjERmJlkLtwYC3bSpIf9kVt Ju/7QrLY/1ytXEJRp5EeIO2IpgOtXcDPHY3BvriKK9NESvIXrurzkK0RnuR8Syqyur odal2M3LZWFV8M4xeK/QwwifOv5fohG0a4yU18d5fWy8FIFSwjYprecWv2qVyD/hue t27DtmwFxJLug== Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C4C2961FBC for ; Sun, 14 Aug 2022 18:08:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Zn1LfA2u"; dkim-atps=neutral Received: by mail-pg1-x536.google.com with SMTP id bh13so4772867pgb.4 for ; Sun, 14 Aug 2022 09:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=83YbuU0kUdKgf06BbOz5ZPqh339HmPmLaxDcEZrp7Xk=; b=Zn1LfA2uvqlXVVW7t+lJlJ73Ui5utwjilauyPuCN/NoJccJiashRV2Fj3fyTFU5GeK 902w3OtiC33ZvMaNLwHeMLuJjD0atPT+XIdf0KQXNSpmZwOri3ImTWtNiP4ks78G4WIW pY4tM68TRAzGcOZqzbiUUo6w0DcVAtXdfPpQdWt76dT/cb4YdqHidPlcdvrGEO1xx/ue Lq8Ol8gazueGw64J7mhbb9Kgyi44XG+WXCzw7ym+WviC1tpZACVLpoiVA4390RbwMnhe /HAZ0ZHJwiPTJAxi634NHlNHqR4cOEOjLXOAPwzjK/IYxuh/7mY3nSaZrYAw3yKMVhPv 7abw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=83YbuU0kUdKgf06BbOz5ZPqh339HmPmLaxDcEZrp7Xk=; b=JNLn6tguLxkFy5QMX+wVqvyh9+JXbSZH9r+qihLvqNqAiK/URn04BeLG8j9PeICp8Z Nf8lB1p5OrBafLgm+pWmYTZXjNdlYIzNRtnQriy9znUXh67bJzlC5wA5dcF/46dsWeuv lr4rR46Rh1/ReBn0+ZxS9KJygF2H1SST7c+zljXL+S8tYT0plDCSfI76u0cgED1623Eo 6WNKt017SVKNnrb8PNiOtfZSgfsT0Vt9MYORmmu5F1ikjPUeCGhBchygLUm06u3c9TOZ RGfpFJVcHXf3cw66JtjmXUaIFGOXiXYMuVyL05DI473GBOITwGVvBC1xVAu/9Kp/hyTv vusw== X-Gm-Message-State: ACgBeo0Nblpy4zk20efduRJpfkGPRkihrA1ONwxyZTd52fTO36hKR+k+ DvGR9BXlQDAzgEWUAN8S5752ZDyEwwE= X-Google-Smtp-Source: AA6agR6I55IT9l4Kqv5PGT5U6zBabTPCohla9dPqoI+fmdRzz/2yvcy0+ZZs1htyhkZ7uApm4p5nRQ== X-Received: by 2002:a63:4547:0:b0:41d:ba0a:870a with SMTP id u7-20020a634547000000b0041dba0a870amr10828401pgk.216.1660493333080; Sun, 14 Aug 2022 09:08:53 -0700 (PDT) Received: from pop-os.localdomain ([115.96.217.20]) by smtp.googlemail.com with ESMTPSA id j6-20020a170902da8600b001709aea1516sm5576653plx.276.2022.08.14.09.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Aug 2022 09:08:52 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 14 Aug 2022 21:37:44 +0530 Message-Id: <20220814160747.52093-3-kunalagarwal1072002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220814160747.52093-1-kunalagarwal1072002@gmail.com> References: <20220814160747.52093-1-kunalagarwal1072002@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/6] pipeline: simple: Implements Texture Handling X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kunal Agarwal via libcamera-devel From: Kunal Agarwal Reply-To: Kunal Agarwal Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Texture Class which includes functions for binding, unbinding, deleting and rendering on textures Signed-off-by: Kunal Agarwal --- 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 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 + +#include + +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 + +#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 */