Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
dd9148bd
Commit
dd9148bd
authored
Sep 17, 2009
by
schurade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] shader class to manage shader related tasks
parent
35bd188d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
235 additions
and
22 deletions
+235
-22
.hgignore
.hgignore
+3
-0
src/graphicsEngine/WShader.cpp
src/graphicsEngine/WShader.cpp
+122
-0
src/graphicsEngine/WShader.h
src/graphicsEngine/WShader.h
+96
-0
src/modules/navigationSlices/WNavigationSliceModule.cpp
src/modules/navigationSlices/WNavigationSliceModule.cpp
+4
-20
src/modules/navigationSlices/WNavigationSliceModule.h
src/modules/navigationSlices/WNavigationSliceModule.h
+10
-2
No files found.
.hgignore
View file @
dd9148bd
...
...
@@ -19,3 +19,6 @@ syntax: regexp
syntax: glob
.project
.cproject
syntax: regexp
^Debug$
\ No newline at end of file
src/graphicsEngine/WShader.cpp
0 → 100644
View file @
dd9148bd
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <string>
#include "../kernel/WKernel.h"
#include "WShader.h"
WShader
::
WShader
()
{
}
WShader
::
WShader
(
std
::
string
fileName
)
{
m_VertexObject
=
readShaderFromFile
(
fileName
+
".vs"
,
osg
::
Shader
::
VERTEX
);
m_FragmentObject
=
readShaderFromFile
(
fileName
+
".fs"
,
osg
::
Shader
::
FRAGMENT
);
m_ProgramObject
=
new
osg
::
Program
;
if
(
m_FragmentObject
)
{
m_ProgramObject
->
addShader
(
m_FragmentObject
);
}
if
(
m_VertexObject
)
{
m_ProgramObject
->
addShader
(
m_VertexObject
);
}
}
WShader
::~
WShader
()
{
}
osg
::
Shader
*
WShader
::
readShaderFromFile
(
std
::
string
fileName
,
osg
::
Shader
::
Type
type
)
{
std
::
string
fileText
=
readTextFile
(
fileName
);
std
::
cout
<<
fileText
<<
std
::
endl
;
osg
::
Shader
*
shader
=
new
osg
::
Shader
(
type
,
fileText
);
return
shader
;
}
std
::
string
WShader
::
readTextFile
(
std
::
string
fileName
)
{
std
::
string
fileText
;
std
::
ifstream
ifs
(
(
WKernel
::
getRunningKernel
()
->
getShaderPath
()
+
fileName
).
c_str
()
);
std
::
string
line
;
while
(
getline
(
ifs
,
line
)
)
{
if
(
isIncludeLine
(
line
)
)
{
fileText
+=
readTextFile
(
getIncludeFileName
(
line
)
);
}
else
{
fileText
+=
line
;
fileText
+=
'\n'
;
}
}
return
fileText
;
}
bool
WShader
::
isIncludeLine
(
std
::
string
line
)
{
if
(
line
.
substr
(
0
,
8
)
==
"#include"
)
{
return
true
;
}
return
false
;
}
std
::
string
WShader
::
getIncludeFileName
(
std
::
string
line
)
{
size_t
pos
=
0
;
std
::
string
fileName
;
while
(
line
[
pos
++
]
!=
'\"'
)
{
}
while
(
(
pos
<
line
.
length
()
)
&&
(
line
[
pos
]
!=
'\"'
)
)
{
fileName
+=
line
[
pos
];
++
pos
;
}
return
fileName
;
}
osg
::
Program
*
WShader
::
getProgramObject
()
{
return
m_ProgramObject
;
}
src/graphicsEngine/WShader.h
0 → 100644
View file @
dd9148bd
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WSHADER_H
#define WSHADER_H
#include <string>
#include <osg/Geometry>
#include <boost/shared_ptr.hpp>
class
WShader
{
public:
/**
* default constructor
*/
WShader
();
/**
*
*/
explicit
WShader
(
std
::
string
fileName
);
/**
* destructor
*/
virtual
~
WShader
();
/**
*
*/
osg
::
Program
*
getProgramObject
();
private:
/**
*
*/
osg
::
Shader
*
readShaderFromFile
(
std
::
string
fileName
,
osg
::
Shader
::
Type
type
);
/**
*
*/
std
::
string
readTextFile
(
std
::
string
fileName
);
/**
*
*/
bool
isIncludeLine
(
std
::
string
line
);
/**
*
*/
std
::
string
getIncludeFileName
(
std
::
string
line
);
/**
*
*/
osg
::
Shader
*
m_VertexObject
;
/**
*
*/
osg
::
Shader
*
m_FragmentObject
;
/**
*
*/
osg
::
Program
*
m_ProgramObject
;
};
#endif // WSHADER_H
src/modules/navigationSlices/WNavigationSliceModule.cpp
View file @
dd9148bd
...
...
@@ -25,7 +25,6 @@
#include <string>
#include <vector>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
...
...
@@ -33,10 +32,13 @@
#include "WNavigationSliceModule.h"
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WShader.h"
WNavigationSliceModule
::
WNavigationSliceModule
()
:
WModule
()
{
// initialize members
m_shader
=
boost
::
shared_ptr
<
WShader
>
(
new
WShader
(
"slice"
)
);
}
WNavigationSliceModule
::~
WNavigationSliceModule
()
...
...
@@ -141,25 +143,7 @@ void WNavigationSliceModule::createSlices()
WKernel
::
getRunningKernel
()
->
getGraphicsEngine
()
->
getScene
()
->
addChild
(
m_sliceNode
);
std
::
string
shaderPath
=
WKernel
::
getRunningKernel
()
->
getShaderPath
();
std
::
cout
<<
"Full path is: "
<<
shaderPath
<<
std
::
endl
;
osg
::
StateSet
*
sliceState
=
m_sliceNode
->
getOrCreateStateSet
();
osg
::
Program
*
sliceProgramObject
=
new
osg
::
Program
;
osg
::
Shader
*
sliceVertexObject
=
osg
::
Shader
::
readShaderFile
(
osg
::
Shader
::
VERTEX
,
shaderPath
+
"slice.vs"
);
osg
::
Shader
*
sliceFragmentObject
=
osg
::
Shader
::
readShaderFile
(
osg
::
Shader
::
FRAGMENT
,
shaderPath
+
"slice.fs"
);
if
(
sliceFragmentObject
)
{
sliceProgramObject
->
addShader
(
sliceFragmentObject
);
}
if
(
sliceVertexObject
)
{
sliceProgramObject
->
addShader
(
sliceVertexObject
);
}
sliceState
->
setAttributeAndModes
(
sliceProgramObject
,
osg
::
StateAttribute
::
ON
);
sliceState
->
setAttributeAndModes
(
m_shader
->
getProgramObject
(),
osg
::
StateAttribute
::
ON
);
}
src/modules/navigationSlices/WNavigationSliceModule.h
View file @
dd9148bd
...
...
@@ -26,9 +26,12 @@
#include <string>
#include "../../kernel/WModule.h"
#include <osg/Node>
#include "../../kernel/WModule.h"
#include "../../graphicsEngine/WShader.h"
/**
* \par Description:
* Simple module for testing some WKernel functionality.
...
...
@@ -79,6 +82,11 @@ protected:
virtual
void
threadMain
();
private:
/**
*
*/
void
createSlices
();
/**
*
*/
...
...
@@ -87,7 +95,7 @@ private:
/**
*
*/
void
createSlices
()
;
boost
::
shared_ptr
<
WShader
>
m_shader
;
};
#endif // WNAVIGATIONSLICEMODULE_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