{"id":17117,"url":"https://patchwork.libcamera.org/api/1.1/patches/17117/?format=json","web_url":"https://patchwork.libcamera.org/patch/17117/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220814160747.52093-2-kunalagarwal1072002@gmail.com>","date":"2022-08-14T16:07:43","name":"[libcamera-devel,v3,2/6] pipeline: simple: Implements Shader Handling","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e85323ca12eeedecde7c8d16f071ca4c75d37d4c","submitter":{"id":116,"url":"https://patchwork.libcamera.org/api/1.1/people/116/?format=json","name":"Kunal Agarwal","email":"kunalagarwal1072002@gmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17117/mbox/","series":[{"id":3414,"url":"https://patchwork.libcamera.org/api/1.1/series/3414/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3414","date":"2022-08-14T16:07:42","name":"[libcamera-devel,v3,1/6] pipeline: simple: shader: Shaders for debayering","version":3,"mbox":"https://patchwork.libcamera.org/series/3414/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17117/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17117/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 39AE4C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 14 Aug 2022 16:08:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 050F161FBA;\n\tSun, 14 Aug 2022 18:08:52 +0200 (CEST)","from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com\n\t[IPv6:2607:f8b0:4864:20::62d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BA28761FBA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Aug 2022 18:08:50 +0200 (CEST)","by mail-pl1-x62d.google.com with SMTP id p18so4583541plr.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Aug 2022 09:08:50 -0700 (PDT)","from pop-os.localdomain ([115.96.217.20])\n\tby smtp.googlemail.com with ESMTPSA id\n\tj6-20020a170902da8600b001709aea1516sm5576653plx.276.2022.08.14.09.08.47\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 14 Aug 2022 09:08:48 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660493332;\n\tbh=cn5cxbSO9TKRTz95mqMJUItKo7xk7Pgzu8KIow2cAJU=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=FSOZVADeoMrCTz1uaKOg0VCZJ16UEueZ/WTjT4Z2git4PH2wLFStb8LidGYnct48n\n\tAhuKzNLG1H2d9hS0ViV2WTgzCQtY95SHCaPz976y6nmXtmykd+IN1iBaO9FODoq+0U\n\tvt3hQomMQhNLEGQvbJffMB1kVHx7xkYAn6Sv6oGtQ/FHjgYxJ5PZ3liGKDo/2ubB5U\n\tHy/rxYPZtWIR3K07PwjWVxkM/jBdd4+upbmg4neOAGotogMir9c38D0pd5ta0soGVg\n\t3oU13K/M5HM99Map3QNohHkHLdSqVlKhinNhY+WuOncn4tP55dWYX9neM/JdNrb5W6\n\tNOSd8f9xROuMw==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc;\n\tbh=vK8jRGiVpF4kQwMqlfQbjrWhJfA8FqWvwjpfSDafvp4=;\n\tb=R1BMq26okBNtAWsSyv04RqlGeD5hCdhgZ6YAe/gHuEHPDPQRpejWQQUqhp0tqbq53M\n\tRpZKJpr+yOMaYYmSD2FLoCnVy9rPy/nwkK5QT8Ca2n3w8B9DQZc23iR0HAJ+Zsof6aP1\n\t6345GjXsNpUipU7lcUPopeJdzhvKutUx1rslHe1jS19cr7d1KNYQnfHriVOVQnGcKNeg\n\ts2IYIF5B26NPmg3J5Sgt+tKgJ90TMRjq3mNSB/9MXsl5uYIR+0KhclUCoKR8r8SMaiCB\n\ttgKofmb3cav58I70yuNMkf1sf3LHcpa4V9yojqFgpA903XXboTntwrONNcuts5qJNjKI\n\tqbBg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"R1BMq26o\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc;\n\tbh=vK8jRGiVpF4kQwMqlfQbjrWhJfA8FqWvwjpfSDafvp4=;\n\tb=XOrxL/YRnIhBQtcDtDKshMSqOY15uJ+wDB4ddhQSpjgQVgot4qu0VJQMf/65MbB3hl\n\trEkicJrrvdzwbRxEOJrxVPAYSTJLhaNDSMSqHD3t8vt83fSsniE4mVlc+56SfuNDbzdS\n\tXhaWN+tYFxFSDu1KyIK8Ua1MYEG+lFUqFg02oxwNbmPy57UGmRE+vXVvB5GMBlfNMARh\n\t5ABMln47Ri30c9rNpkog4RpSzv6qGMsmdWVYN/9DTjN70FIhlr8MObm+9mnD7+1geoLo\n\tNsdabqhO4dSihUSF1SIMo8+b9Tj7dA4NO7u5pjGRwxFAOzogstS/2lGxmWavGIcP0e9w\n\ttaNg==","X-Gm-Message-State":"ACgBeo3i8h6S/EITWnYm7bMnkE66bvR6o6GLhy9kAqVR3LjjxEeQVMUF\n\tBb5lNM2muqtARfj3W1rkB93G4LM68A8=","X-Google-Smtp-Source":"AA6agR7mIHt8BYXc+FBs7NETfUeH9thK3i3dIcfoVXpGFnho0ganRfwcM8bFnYi6GVNuiATR83Jdkg==","X-Received":"by 2002:a17:90a:e2cc:b0:1f3:1151:e0ff with SMTP id\n\tfr12-20020a17090ae2cc00b001f31151e0ffmr14582275pjb.50.1660493329069; \n\tSun, 14 Aug 2022 09:08:49 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 14 Aug 2022 21:37:43 +0530","Message-Id":"<20220814160747.52093-2-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 2/6] pipeline: simple: Implements\n\tShader Handling","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Kunal Agarwal via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Kunal Agarwal <kunalagarwal1072002@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Shader Class which includes functions for building,\nactivating, deleting and compiling shaders\n\nSigned-off-by: Kunal Agarwal <kunalagarwal1072002@gmail.com>\n---\n src/libcamera/pipeline/simple/shader.cpp | 110 +++++++++++++++++++++++\n src/libcamera/pipeline/simple/shader.h   |  34 +++++++\n 2 files changed, 144 insertions(+)\n create mode 100644 src/libcamera/pipeline/simple/shader.cpp\n create mode 100644 src/libcamera/pipeline/simple/shader.h","diff":"diff --git a/src/libcamera/pipeline/simple/shader.cpp b/src/libcamera/pipeline/simple/shader.cpp\nnew file mode 100644\nindex 00000000..f0079618\n--- /dev/null\n+++ b/src/libcamera/pipeline/simple/shader.cpp\n@@ -0,0 +1,110 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Kunal Agarwal\n+ *\n+ * shader.cpp - Shader Handling\n+ */\n+\n+#include \"shader.h\"\n+\n+#include <libcamera/base/file.h>\n+#include <libcamera/base/log.h>\n+\n+#include <GLES3/gl3.h>\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(SimplePipeline)\n+\n+/* Reads a text file and outputs a string with everything in the text file */\n+static std::string get_file_contents(const char *filename)\n+{\n+\tstd::string fullname = std::string(\"/home/pi/Desktop/compile/libcamera/src/libcamera/pipeline/simple/shader/\") + filename;\n+\n+\tFile file(fullname);\n+\tif (!file.open(File::OpenModeFlag::ReadOnly))\n+\t\treturn \"\";\n+\n+\tSpan<uint8_t> data = file.map();\n+\treturn std::string(reinterpret_cast<char *>(data.data()), data.size());\n+}\n+\n+/* Constructor that build the Shader Program from 2 different shaders */\n+void ShaderProgram::callShader(const char *vertexFile, const char *fragmentFile)\n+{\n+\t/* Read vertexFile and fragmentFile and store the strings */\n+\tstd::string vertexCode = get_file_contents(vertexFile);\n+\tstd::string fragmentCode = get_file_contents(fragmentFile);\n+\tconst char *vertexSource = vertexCode.c_str();\n+\tconst char *fragmentSource = fragmentCode.c_str();\n+\n+\t/* Create the vertex shader, set its source code and compile it. */\n+\tGLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);\n+\tglShaderSource(vertexShader, 1, &vertexSource, NULL);\n+\tglCompileShader(vertexShader);\n+\tcompileErrors(vertexShader, \"VERTEX\");\n+\n+\t/* Create the fragment shader, set its source code and compile it. */\n+\tGLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);\n+\tglShaderSource(fragmentShader, 1, &fragmentSource, NULL);\n+\tglCompileShader(fragmentShader);\n+\tcompileErrors(fragmentShader, \"FRAGMENT\");\n+\n+\t/* Create Shader Program Object and get its reference */\n+\tid_ = glCreateProgram();\n+\n+\t/* Attach and wrap-up/link the Vertex and Fragment Shaders to the Shader Program */\n+\tglAttachShader(id_, vertexShader);\n+\tglAttachShader(id_, fragmentShader);\n+\tglLinkProgram(id_);\n+\n+\t/* Checks if Shaders linked succesfully */\n+\tcompileErrors(id_, \"PROGRAM\");\n+\n+\t/* Delete the Vertex and Fragment Shader objects. Here, they are flagged for deletion\n+\t   and will not be deleted until they are detached from the program object. This frees\n+\t   up the memory used to store the shader source. */\n+\tglDeleteShader(vertexShader);\n+\tglDeleteShader(fragmentShader);\n+}\n+\n+/* Activates the Shader Program */\n+void ShaderProgram::activate()\n+{\n+\tglUseProgram(id_);\n+}\n+\n+/* Deletes the Shader Program */\n+void ShaderProgram::deleteProgram()\n+{\n+\tglDeleteProgram(id_);\n+}\n+\n+/* Checks if the different Shaders have compiled properly */\n+void ShaderProgram::compileErrors(unsigned int shader, const char *type)\n+{\n+\t/* Stores status of compilation */\n+\tGLint hasCompiled;\n+\tGLint logLength;\n+\t/* Character array to store error message in */\n+\tglGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);\n+\tchar *infoLog = new char[logLength];\n+\tif (strcmp(type, \"PROGRAM\") != 0) {\n+\t\tglGetShaderiv(shader, GL_COMPILE_STATUS, &hasCompiled);\n+\t\tif (hasCompiled == GL_FALSE) {\n+\t\t\tglGetShaderInfoLog(shader, logLength, NULL, infoLog);\n+\t\t\tLOG(SimplePipeline, Error) << \"SHADER_COMPILATION_ERROR for:\"\n+\t\t\t\t\t\t   << type << \"\\t\"\n+\t\t\t\t\t\t   << infoLog;\n+\t\t}\n+\t} else {\n+\t\tglGetProgramiv(shader, GL_LINK_STATUS, &hasCompiled);\n+\t\tif (hasCompiled == GL_FALSE) {\n+\t\t\tglGetProgramInfoLog(shader, logLength, NULL, infoLog);\n+\t\t\tLOG(SimplePipeline, Error) << \"SHADER_LINKING_ERROR for:\"\n+\t\t\t\t\t\t   << type << \"\\t\"\n+\t\t\t\t\t\t   << infoLog;\n+\t\t}\n+\t}\n+}\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/simple/shader.h b/src/libcamera/pipeline/simple/shader.h\nnew file mode 100644\nindex 00000000..921e4040\n--- /dev/null\n+++ b/src/libcamera/pipeline/simple/shader.h\n@@ -0,0 +1,34 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Kunal Agarwal\n+ *\n+ * shader.h - Shader Handling\n+ */\n+\n+#pragma once\n+\n+#include <iostream>\n+#include <string.h>\n+\n+#include <GL/gl.h>\n+\n+namespace libcamera {\n+\n+class ShaderProgram\n+{\n+public:\n+\tvoid callShader(const char *vertexFile, const char *fragmentFile);\n+\n+\tvoid activate();\n+\n+\tvoid deleteProgram();\n+\n+\tint id() const { return id_; };\n+\n+private:\n+\t/* Reference ID of the Shader Program */\n+\tGLuint id_;\n+\tvoid compileErrors(unsigned int shader, const char *type);\n+};\n+\n+} /* namespace libcamera */\n","prefixes":["libcamera-devel","v3","2/6"]}