Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
27a6f8af
Commit
27a6f8af
authored
Jun 30, 2013
by
Maciej Sumiński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shaders are built-in instead of being loaded from external files.
parent
335bf720
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
171 additions
and
97 deletions
+171
-97
CMakeLists.txt
common/CMakeLists.txt
+15
-0
drawpanel_gal.cpp
common/drawpanel_gal.cpp
+0
-7
make_shader_src_h.sh
common/gal/opengl/make_shader_src_h.sh
+39
-0
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+2
-3
shader.cpp
common/gal/opengl/shader.cpp
+91
-74
class_drawpanel_gal.h
include/class_drawpanel_gal.h
+0
-2
opengl_gal.h
include/gal/opengl/opengl_gal.h
+0
-6
shader.h
include/gal/opengl/shader.h
+24
-5
No files found.
common/CMakeLists.txt
View file @
27a6f8af
...
...
@@ -12,6 +12,20 @@ include_directories(
)
if
(
KICAD_GAL
)
# Generate files containing shader programs
add_custom_command
(
OUTPUT gal/opengl/shader_src.h
DEPENDS gal/opengl/make_shader_src_h.sh
WORKING_DIRECTORY
${
PROJECT_SOURCE_DIR
}
/common/gal/opengl
COMMAND
${
SHELL
}
ARGS
${
PROJECT_SOURCE_DIR
}
/common/gal/opengl/make_shader_src_h.sh
)
add_custom_target
(
ShaderHeader ALL
DEPENDS gal/opengl/shader_src.h
)
set
(
GAL_SRCS
drawpanel_gal.cpp
painter.cpp
...
...
@@ -27,6 +41,7 @@ set(GAL_SRCS
)
add_library
(
gal STATIC
${
GAL_SRCS
}
)
add_dependencies
(
gal ShaderHeader
)
if
(
WIN32
)
add_definitions
(
-DGLEW_STATIC
)
...
...
common/drawpanel_gal.cpp
View file @
27a6f8af
...
...
@@ -27,7 +27,6 @@
#include <wx/window.h>
#include <wx/event.h>
#include <wx/colour.h>
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include <class_drawpanel_gal.h>
...
...
@@ -56,11 +55,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_view
=
NULL
;
m_painter
=
NULL
;
wxStandardPaths
paths
;
wxFileName
executableFile
(
paths
.
GetExecutablePath
()
);
m_galShaderPath
=
std
::
string
(
(
executableFile
.
GetPath
()
+
wxT
(
"/../../common/gal/opengl"
)
).
mb_str
()
);
SwitchBackend
(
aGalType
,
true
);
SetBackgroundStyle
(
wxBG_STYLE_CUSTOM
);
...
...
@@ -170,7 +164,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders )
{
case
GAL_TYPE_OPENGL
:
m_gal
=
new
KiGfx
::
OPENGL_GAL
(
this
,
this
,
this
,
aUseShaders
);
static_cast
<
KiGfx
::
OPENGL_GAL
*>
(
m_gal
)
->
SetShaderPath
(
m_galShaderPath
);
break
;
case
GAL_TYPE_CAIRO
:
...
...
common/gal/opengl/make_shader_src_h.sh
0 → 100755
View file @
27a6f8af
#!/bin/bash
# Make a header file containing GLSL source code
echo
"Generating headers containing GLSL source code.."
# Source files to be included
SHADER_SRC
=(
"shader.vert"
"shader.frag"
)
# Number of shaders
SHADERS_NUMBER
=
${#
SHADER_SRC
[@]
}
OUTPUT
=
"shader_src.h"
# Prepare GLSL source to be included in C array
function
processSrc
{
# 1st part: remove /* */ comments
# 2nd part: remove // comments
# 3rd part: remove blank lines (or containing only whitespaces)
# 4th & 5th part: wrap every line in quotation marks
sed
'/\/\*/,/\*\//d; s/[ \t]*\/\/.*$//; /^[ \t]*$/d; s/^[ \t]*/"/; s/[ \t]*$/\\n"/'
$1
>>
$OUTPUT
echo
","
>>
$OUTPUT
}
# Header
echo
"#ifndef SHADER_SRC_H
#define SHADER_SRC_H
const unsigned int shaders_number =
$SHADERS_NUMBER
;
const char *shaders_src[] = {"
>
$OUTPUT
# Main contents
for
filename
in
"
${
SHADER_SRC
[@]
}
"
do
processSrc
$filename
done
# Footer
echo
"};
#endif /* SHADER_SRC_H */"
>>
$OUTPUT
echo
"Done."
common/gal/opengl/opengl_gal.cpp
View file @
27a6f8af
...
...
@@ -74,7 +74,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
isUseShader
=
isUseShaders
;
isShaderInitialized
=
false
;
isGrouping
=
false
;
shaderPath
=
"../../common/gal/opengl"
;
wxSize
parentSize
=
aParent
->
GetSize
();
isVboInitialized
=
false
;
...
...
@@ -359,12 +358,12 @@ void OPENGL_GAL::BeginDrawing()
// Compile the shaders
if
(
!
isShaderInitialized
&&
isUseShader
)
{
if
(
!
shader
.
AddSource
(
shaderPath
+
std
::
string
(
"/shader.vert"
)
,
SHADER_TYPE_VERTEX
)
)
if
(
!
shader
.
LoadBuiltinShader
(
0
,
SHADER_TYPE_VERTEX
)
)
{
wxLogFatalError
(
wxT
(
"Cannot compile vertex shader!"
)
);
}
if
(
!
shader
.
AddSource
(
shaderPath
+
std
::
string
(
"/shader.frag"
)
,
SHADER_TYPE_FRAGMENT
)
)
if
(
!
shader
.
LoadBuiltinShader
(
1
,
SHADER_TYPE_FRAGMENT
)
)
{
wxLogFatalError
(
wxT
(
"Cannot compile fragment shader!"
)
);
}
...
...
common/gal/opengl/shader.cpp
View file @
27a6f8af
...
...
@@ -32,14 +32,15 @@
#include <wx/log.h>
#include <gal/opengl/shader.h>
#include "shader_src.h"
using
namespace
KiGfx
;
SHADER
::
SHADER
()
:
isProgramCreated
(
false
),
isShaderLinked
(
false
),
maximumVertices
(
4
),
active
(
false
),
maximumVertices
(
4
),
geomInputType
(
GL_LINES
),
geomOutputType
(
GL_LINES
)
{
...
...
@@ -62,7 +63,84 @@ SHADER::~SHADER()
}
void
SHADER
::
ProgramInfo
(
GLuint
aProgram
)
bool
SHADER
::
LoadBuiltinShader
(
unsigned
int
aShaderNumber
,
ShaderType
aShaderType
)
{
if
(
aShaderNumber
>=
shaders_number
)
return
false
;
return
addSource
(
std
::
string
(
shaders_src
[
aShaderNumber
]
),
aShaderType
);
}
bool
SHADER
::
LoadShaderFromFile
(
const
std
::
string
&
aShaderSourceName
,
ShaderType
aShaderType
)
{
// Load shader sources
const
std
::
string
shaderSource
=
readSource
(
aShaderSourceName
);
return
addSource
(
shaderSource
,
aShaderType
);
}
void
SHADER
::
ConfigureGeometryShader
(
GLuint
maxVertices
,
GLuint
geometryInputType
,
GLuint
geometryOutputType
)
{
maximumVertices
=
maxVertices
;
geomInputType
=
geometryInputType
;
geomOutputType
=
geometryOutputType
;
}
bool
SHADER
::
Link
()
{
// Shader linking
glLinkProgram
(
programNumber
);
programInfo
(
programNumber
);
// Check the Link state
glGetObjectParameterivARB
(
programNumber
,
GL_OBJECT_LINK_STATUS_ARB
,
(
GLint
*
)
&
isShaderLinked
);
#ifdef __WXDEBUG__
if
(
!
isShaderLinked
)
{
int
maxLength
;
glGetProgramiv
(
programNumber
,
GL_INFO_LOG_LENGTH
,
&
maxLength
);
maxLength
=
maxLength
+
1
;
char
*
linkInfoLog
=
new
char
[
maxLength
];
glGetProgramInfoLog
(
programNumber
,
maxLength
,
&
maxLength
,
linkInfoLog
);
std
::
cerr
<<
"Shader linking error:"
<<
std
::
endl
;
std
::
cerr
<<
linkInfoLog
;
delete
[]
linkInfoLog
;
}
#endif
/* __WXDEBUG__ */
return
isShaderLinked
;
}
void
SHADER
::
AddParameter
(
const
std
::
string
&
aParameterName
)
{
GLint
location
=
glGetUniformLocation
(
programNumber
,
aParameterName
.
c_str
()
);
if
(
location
!=
-
1
)
{
parameterLocation
.
push_back
(
location
);
}
}
void
SHADER
::
SetParameter
(
int
parameterNumber
,
float
value
)
{
glUniform1f
(
parameterLocation
[
parameterNumber
],
value
);
}
int
SHADER
::
GetAttribute
(
std
::
string
aAttributeName
)
const
{
return
glGetAttribLocation
(
programNumber
,
aAttributeName
.
c_str
()
);
}
void
SHADER
::
programInfo
(
GLuint
aProgram
)
{
GLint
glInfoLogLength
=
0
;
GLint
writtenChars
=
0
;
...
...
@@ -83,7 +161,7 @@ void SHADER::ProgramInfo( GLuint aProgram )
}
void
SHADER
::
S
haderInfo
(
GLuint
aShader
)
void
SHADER
::
s
haderInfo
(
GLuint
aShader
)
{
GLint
glInfoLogLength
=
0
;
GLint
writtenChars
=
0
;
...
...
@@ -104,7 +182,7 @@ void SHADER::ShaderInfo( GLuint aShader )
}
std
::
string
SHADER
::
R
eadSource
(
std
::
string
aShaderSourceName
)
std
::
string
SHADER
::
r
eadSource
(
std
::
string
aShaderSourceName
)
{
// Open the shader source for reading
std
::
ifstream
inputFile
(
aShaderSourceName
.
c_str
(),
std
::
ifstream
::
in
);
...
...
@@ -130,7 +208,7 @@ std::string SHADER::ReadSource( std::string aShaderSourceName )
}
bool
SHADER
::
AddSource
(
const
std
::
string
&
aShaderSourceNam
e
,
ShaderType
aShaderType
)
bool
SHADER
::
addSource
(
const
std
::
string
&
aShaderSourc
e
,
ShaderType
aShaderType
)
{
if
(
isShaderLinked
)
{
...
...
@@ -144,24 +222,21 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader
isProgramCreated
=
true
;
}
// Load shader sources
std
::
string
shaderSource
=
ReadSource
(
aShaderSourceName
);
// Create a shader
GLuint
shaderNumber
=
glCreateShader
(
aShaderType
);
shaderNumbers
.
push_back
(
shaderNumber
);
// Get the program info
P
rogramInfo
(
programNumber
);
p
rogramInfo
(
programNumber
);
// Copy to char array
char
*
source
=
new
char
[
s
haderSource
.
size
()
+
1
];
strcpy
(
source
,
s
haderSource
.
c_str
()
);
char
*
source
=
new
char
[
aS
haderSource
.
size
()
+
1
];
strcpy
(
source
,
aS
haderSource
.
c_str
()
);
const
char
**
source_
=
(
const
char
**
)
(
&
source
);
// Attach the source
glShaderSource
(
shaderNumber
,
1
,
source_
,
NULL
);
P
rogramInfo
(
programNumber
);
p
rogramInfo
(
programNumber
);
// Compile and attach shader to the program
glCompileShader
(
shaderNumber
);
...
...
@@ -169,15 +244,15 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader
glGetShaderiv
(
shaderNumber
,
GL_COMPILE_STATUS
,
&
status
);
if
(
status
!=
GL_TRUE
)
{
wxLogError
(
wxT
(
"Shader compilation error"
)
);
wxLogError
(
wxT
(
"Shader compilation error"
)
);
S
haderInfo
(
shaderNumber
);
s
haderInfo
(
shaderNumber
);
return
false
;
return
false
;
}
glAttachShader
(
programNumber
,
shaderNumber
);
P
rogramInfo
(
programNumber
);
p
rogramInfo
(
programNumber
);
// Special handling for the geometry shader
if
(
aShaderType
==
SHADER_TYPE_GEOMETRY
)
...
...
@@ -193,61 +268,3 @@ bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader
return
true
;
}
void
SHADER
::
ConfigureGeometryShader
(
GLuint
maxVertices
,
GLuint
geometryInputType
,
GLuint
geometryOutputType
)
{
maximumVertices
=
maxVertices
;
geomInputType
=
geometryInputType
;
geomOutputType
=
geometryOutputType
;
}
bool
SHADER
::
Link
()
{
// Shader linking
glLinkProgram
(
programNumber
);
ProgramInfo
(
programNumber
);
// Check the Link state
glGetObjectParameterivARB
(
programNumber
,
GL_OBJECT_LINK_STATUS_ARB
,
(
GLint
*
)
&
isShaderLinked
);
#ifdef __WXDEBUG__
if
(
!
isShaderLinked
)
{
int
maxLength
;
glGetProgramiv
(
programNumber
,
GL_INFO_LOG_LENGTH
,
&
maxLength
);
maxLength
=
maxLength
+
1
;
char
*
linkInfoLog
=
new
char
[
maxLength
];
glGetProgramInfoLog
(
programNumber
,
maxLength
,
&
maxLength
,
linkInfoLog
);
std
::
cerr
<<
"Shader linking error:"
<<
std
::
endl
;
std
::
cerr
<<
linkInfoLog
;
delete
[]
linkInfoLog
;
}
#endif
/* __WXDEBUG__ */
return
isShaderLinked
;
}
void
SHADER
::
AddParameter
(
const
std
::
string
&
aParameterName
)
{
GLint
location
=
glGetUniformLocation
(
programNumber
,
aParameterName
.
c_str
()
);
if
(
location
!=
-
1
)
{
parameterLocation
.
push_back
(
location
);
}
}
void
SHADER
::
SetParameter
(
int
parameterNumber
,
float
value
)
{
glUniform1f
(
parameterLocation
[
parameterNumber
],
value
);
}
int
SHADER
::
GetAttribute
(
std
::
string
aAttributeName
)
const
{
return
glGetAttribLocation
(
programNumber
,
aAttributeName
.
c_str
()
);
}
include/class_drawpanel_gal.h
View file @
27a6f8af
...
...
@@ -91,8 +91,6 @@ protected:
GalType
m_currentGal
;
///< Currently used GAL
bool
m_useShaders
;
///< Are shaders used? (only for OpenGL GAL)
wxLongLong
m_timeStamp
;
std
::
string
m_galShaderPath
;
///< Path to shader files, used in OpenGL mode
};
#endif
include/gal/opengl/opengl_gal.h
View file @
27a6f8af
...
...
@@ -320,11 +320,6 @@ public:
paintListener
=
aPaintListener
;
}
void
SetShaderPath
(
const
std
::
string
&
aPath
)
{
shaderPath
=
aPath
;
}
///< Parameters passed to the GLU tesselator
typedef
struct
{
...
...
@@ -389,7 +384,6 @@ private:
SHADER
shader
;
///< There is only one shader used for different objects
int
shaderAttrib
;
///< Location of shader attributes (for glVertexAttribPointer)
std
::
string
shaderPath
;
///< Location of shader files
// Cursor
int
cursorSize
;
///< Size of the cursor in pixels
...
...
include/gal/opengl/shader.h
View file @
27a6f8af
...
...
@@ -71,12 +71,22 @@ public:
virtual
~
SHADER
();
/**
* @brief Add a shader and compile the shader sources.
* @brief Loads one of the built-in shaders and compiles it.
*
* @param aShaderNumber is the shader number (indexing from 0).
* @param aShaderType is the type of the shader.
* @return True in case of success, false otherwise.
*/
bool
LoadBuiltinShader
(
unsigned
int
aShaderNumber
,
ShaderType
aShaderType
);
/**
* @brief Loads one of the built-in shaders and compiles it.
*
* @param aShaderSourceName is the shader source file name.
* @param aShaderType is the type of the shader.
* @return True in case of success, false otherwise.
*/
bool
AddSourc
e
(
const
std
::
string
&
aShaderSourceName
,
ShaderType
aShaderType
);
bool
LoadShaderFromFil
e
(
const
std
::
string
&
aShaderSourceName
,
ShaderType
aShaderType
);
/**
* @brief Link the shaders.
...
...
@@ -157,14 +167,14 @@ private:
*
* @param aProgram is the program number.
*/
void
P
rogramInfo
(
GLuint
aProgram
);
void
p
rogramInfo
(
GLuint
aProgram
);
/**
* @brief Get the shader information.
*
* @param aShader is the shader number.
*/
void
S
haderInfo
(
GLuint
aShader
);
void
s
haderInfo
(
GLuint
aShader
);
/**
* @brief Read the shader source file
...
...
@@ -172,7 +182,16 @@ private:
* @param aShaderSourceName is the shader source file name.
* @return the source as string
*/
std
::
string
ReadSource
(
std
::
string
aShaderSourceName
);
std
::
string
readSource
(
std
::
string
aShaderSourceName
);
/**
* @brief Add a shader and compile the shader sources.
*
* @param aShaderSource is the shader source content.
* @param aShaderType is the type of the shader.
* @return True in case of success, false otherwise.
*/
bool
addSource
(
const
std
::
string
&
aShaderSource
,
ShaderType
aShaderType
);
std
::
deque
<
GLuint
>
shaderNumbers
;
///< Shader number list
GLuint
programNumber
;
///< Shader program number
...
...
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