Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Diego Pérez Peña
/
PAG_p1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3973828b
authored
Sep 25, 2025
by
Diego Pérez Peña
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Clase ShaderException creada
parent
7f4579cb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
24 deletions
CMakeLists.txt
Renderer.cpp
ShaderException.cpp
ShaderException.h
CMakeLists.txt
View file @
3973828b
...
...
@@ -7,30 +7,32 @@ file( GLOB MY_FILES *.cpp )
file
(
GLOB GLAD_FILES glad/src/*.c
)
file
(
GLOB IMGUI_FILES imgui/src/*.cpp
)
add_executable
(
PAG_p1
${
MY_FILES
}
${
GLAD_FILES
}
${
IMGUI_FILES
}
)
add_executable
(
PAG_p1
${
MY_FILES
}
${
GLAD_FILES
}
${
IMGUI_FILES
}
ShaderException.cpp
ShaderException.h
)
target_include_directories
(
PAG_p1 PUBLIC glad/include imgui/include
)
# Uncomment the following when using Conan, comment (# at line start) otherwise
find_package
(
opengl_system
)
find_package
(
glfw3
)
find_package
(
glm
)
#
find_package(opengl_system)
#
find_package(glfw3)
#
find_package(glm)
# Then, link your executable or library with the corresponding package targets:
target_link_libraries
(
PAG_p1 opengl::opengl
)
target_link_libraries
(
PAG_p1 glfw
)
target_link_libraries
(
PAG_p1 glm::glm
)
#
target_link_libraries(PAG_p1 opengl::opengl)
#
target_link_libraries(PAG_p1 glfw)
#
target_link_libraries(PAG_p1 glm::glm)
#===========================================
# Uncomment the following when using Linux, comment (# at line start) otherwise
#
find_package(glfw3 3.3 REQUIRED)
#
find_package(OpenGL REQUIRED)
find_package
(
glfw3 3.3 REQUIRED
)
find_package
(
OpenGL REQUIRED
)
#
target_include_directories(PAG_p1 PUBLIC
#
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
#
$<INSTALL_INTERFACE:include>)
#
target_link_libraries(PAG_p1 PUBLIC glfw OpenGL::GL ${CMAKE_DL_LIBS})
target_include_directories
(
PAG_p1 PUBLIC
$<BUILD_INTERFACE:
${
CMAKE_CURRENT_LIST_DIR
}
/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries
(
PAG_p1 PUBLIC glfw OpenGL::GL
${
CMAKE_DL_LIBS
}
)
Renderer.cpp
View file @
3973828b
...
...
@@ -11,6 +11,8 @@
#include <cstdarg>
#include <iostream>
#include <string>
#include "ShaderException.h"
#include "glad/glad.h"
PAG
::
Renderer
*
PAG
::
Renderer
::
instancia
=
nullptr
;
...
...
@@ -115,8 +117,7 @@ void PAG::Renderer::creaShaderProgram() {
idVS
=
glCreateShader
(
GL_VERTEX_SHADER
);
if
(
idVS
==
0
)
{
std
::
cout
<<
"Cannot create vertex shader object."
<<
std
::
endl
;
return
;
throw
ShaderException
(
GL_VERTEX_SHADER
,
true
,
""
);
}
const
GLchar
*
fuenteVS
=
miVertexShader
.
c_str
();
glShaderSource
(
idVS
,
1
,
&
fuenteVS
,
nullptr
);
...
...
@@ -136,15 +137,13 @@ void PAG::Renderer::creaShaderProgram() {
mensaje
.
assign
(
mensajeFormatoC
);
delete
[]
mensajeFormatoC
;
mensajeFormatoC
=
nullptr
;
throw
std
::
runtime_error
(
mensaje
);
throw
ShaderException
(
GL_VERTEX_SHADER
,
false
,
mensaje
);
}
}
idFS
=
glCreateShader
(
GL_FRAGMENT_SHADER
);
if
(
idFS
==
0
)
{
std
::
cout
<<
"Cannot create fragment shader object."
<<
std
::
endl
;
// TODO: Cambiar por excepción
return
;
throw
ShaderException
(
GL_FRAGMENT_SHADER
,
true
,
""
);
}
const
GLchar
*
fuenteFS
=
miFragmentShader
.
c_str
();
glShaderSource
(
idFS
,
1
,
&
fuenteFS
,
nullptr
);
...
...
@@ -163,14 +162,13 @@ void PAG::Renderer::creaShaderProgram() {
mensaje
.
assign
(
mensajeFormatoC
);
delete
[]
mensajeFormatoC
;
mensajeFormatoC
=
nullptr
;
throw
std
::
runtime_error
(
mensaje
);
throw
ShaderException
(
GL_FRAGMENT_SHADER
,
false
,
mensaje
);
}
}
idSP
=
glCreateProgram
();
if
(
idSP
==
0
)
{
std
::
cout
<<
"Cannot create shader program"
<<
std
::
endl
;
return
;
throw
ShaderException
(
0
,
true
,
""
);
}
glAttachShader
(
idSP
,
idVS
);
glAttachShader
(
idSP
,
idFS
);
...
...
@@ -189,8 +187,7 @@ void PAG::Renderer::creaShaderProgram() {
mensaje
.
assign
(
mensajeFormatoC
);
delete
[]
mensajeFormatoC
;
mensajeFormatoC
=
nullptr
;
std
::
cout
<<
"Cannot link shader program"
<<
std
::
endl
;
std
::
cout
<<
mensaje
<<
std
::
endl
;
throw
ShaderException
(
0
,
false
,
mensaje
);
}
}
}
...
...
ShaderException.cpp
0 → 100644
View file @
3973828b
/**
* @file ShaderException.cpp
* @author dpp00022
*
* @date 2025/08/25
*
* @brief Implementación de la clase ShaderException
*/
#include "ShaderException.h"
#include "glad/glad.h"
#include <utility>
/**
* Constructor parametrizado de la clase
* @param type Tipo de shader que ha causado el error
* @param creating Si el error ha ocurrido durante la creación o no
* @param log Descripción del error
*/
ShaderException
::
ShaderException
(
int
type
,
bool
creating
,
std
::
string
log
)
:
type
(
type
),
creating
(
creating
),
log
(
std
::
move
(
log
))
{}
/**
* Constructor copia de la clase
* @param other Excepción que se desea copiar
*/
ShaderException
::
ShaderException
(
ShaderException
&
other
)
:
type
(
other
.
type
),
creating
(
other
.
creating
),
log
(
other
.
log
)
{}
/**
* Operador copia de la clase
* @param other Excepción que se desea copiar
*/
ShaderException
&
ShaderException
::
operator
=
(
ShaderException
const
&
other
)
{
this
->
type
=
other
.
type
;
this
->
creating
=
other
.
creating
;
this
->
log
=
other
.
log
;
return
*
this
;
}
/**
* Devuelve un string con el log completo
*/
std
::
string
ShaderException
::
getLog
()
{
std
::
string
aux
=
"Cannot "
;
if
(
creating
)
{
aux
.
append
(
"create "
);
}
else
{
if
(
type
==
GL_FRAGMENT_SHADER
||
type
==
GL_VERTEX_SHADER
)
{
aux
.
append
(
"compile "
);
}
else
{
aux
.
append
(
"link "
);
}
}
if
(
type
==
GL_FRAGMENT_SHADER
)
{
aux
.
append
(
"fragment shader"
);
}
else
if
(
type
==
GL_VERTEX_SHADER
)
{
aux
.
append
(
"vertex shader"
);
}
else
{
aux
.
append
(
"shader program"
);
}
aux
.
append
(
":
\n
"
).
append
(
log
).
append
(
"
\n
"
);
return
log
;
}
/**
* Mét0do what() de excepción. Solo devuelve la descripción, sin la cabecera.
*/
const
char
*
ShaderException
::
what
()
const
noexcept
{
return
log
.
c_str
();
}
ShaderException.h
0 → 100644
View file @
3973828b
/**
* @file ShaderException.h
* @author dpp00022
*
* @date 2025/09/25
*
* @brief Declaración de la clase ShaderException
*/
#ifndef SHADEREXCEPTION_H
#define SHADEREXCEPTION_H
#include <string>
/**
* Clase que representa una excepción personalizada para manejar
* los errores que puedan suceder con los Shaders.
*/
class
ShaderException
:
public
std
::
exception
{
int
type
=
0
;
///< Tipo de shader que ha causado el error
bool
creating
=
false
;
///< Si el error ha ocurrido durante la creación o no
std
::
string
log
;
///< Descripción del error
public:
ShaderException
()
=
default
;
ShaderException
(
int
type
,
bool
creating
,
std
::
string
log
);
ShaderException
(
ShaderException
&
other
);
virtual
~
ShaderException
()
=
default
;
ShaderException
&
operator
=
(
ShaderException
const
&
other
);
std
::
string
getLog
();
const
char
*
what
()
const
noexcept
override
;
};
#endif //SHADEREXCEPTION_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment