Skip to content
Browse files

ozFactory, DDS fixed, File::directory()

- ozCore
  * String::fileDirectory(), File::directory()
- ozEngine
  * Shader class (not woking yet)
  * GL, AL loaders for InputStream
- ozFactory: builder library
  * DDS builder moved ozFactory and fixed
  • Loading branch information...
1 parent e3c6bac commit 113b6d466e1fa97e07293516dd092950779375f1 @ducakar committed May 7, 2013
View
6 CMakeLists.txt
@@ -11,12 +11,12 @@ set( OZ_VERSION 0.3.81 )
option( OZ_TRACK_ALLOCS "Track memory allocations to detect new/delete mismatches and memory leaks." OFF )
option( OZ_SIMD_MATH "Use SIMD implementation of linear algebra classes." OFF )
option( OZ_DYNAMICS "Build complete ozDynamics library with ODE support." OFF )
+option( OZ_SDL2 "Use SDL 2.0 instead of SDL 1.2." OFF )
option( OZ_GL_ES "Use OpenGL ES 2.0 instead of OpenGL 2.1." OFF )
+option( OZ_NONFREE "Enable support for building S3TC textures." OFF )
option( OZ_LUAJIT "Use use LuaJIT 2.0 instead of official Lua." OFF )
-option( OZ_SDL2 "Use SDL 2.0 instead of SDL 1.2." OFF )
option( OZ_NET "Enable networking support." OFF )
-option( OZ_NONFREE "Enable support for building S3TC textures." OFF )
option( OZ_STANDALONE "Install layout appropriate for launching from its own folder." OFF )
option( OZ_TESTS "Build test programs (that should only be used by me)." OFF )
@@ -136,7 +136,7 @@ endif()
if( NOT PLATFORM_EMBEDDED )
find_library( FREEIMAGE_LIBRARY freeimage )
- find_library( FREEIMAGEPLUS_LIBRARY freeimageplus)
+ find_library( FREEIMAGEPLUS_LIBRARY freeimageplus )
mark_as_advanced( FREEIMAGE_LIBRARY )
mark_as_advanced( FREEIMAGEPLUS_LIBRARY )
View
1 README.md
@@ -267,7 +267,6 @@ The following alternative launches are available:
NaCl port. If `strip` is passed as the second option, binaries are stripped too.
Documentation
-
-------------
To generate documentation from source code with Doxygen, run
View
4 autogen.sh
@@ -10,7 +10,9 @@
#
version=0.3.81
-components=( ozCore ozDynamics ozEngine common matrix nirvana modules client builder unittest )
+components=( ozCore ozDynamics ozEngine ozFactory
+ common matrix nirvana modules client builder
+ unittest )
# Generate CMakeLists.txt files.
for component in ${components[@]}; do
View
6 etc/PKGBUILD
@@ -31,9 +31,9 @@ function build()
function package_liboz()
{
- pkgdesc='OpenZone Core, Dynamics and Engine Libraries'
+ pkgdesc='OpenZone ozCore, ozDynamics, ozEngine and ozFactory libraries'
license=('ZLIB')
- depends=('libpulse' 'physfs')
+ depends=('libpulse' 'physfs' 'sdl_ttf' 'libgl' 'openal' 'freeimage')
cd "${srcdir}/${pkgbase}-${pkgver}"
@@ -47,7 +47,7 @@ function package_liboz()
function package_openzone()
{
pkgdesc='Simple cross-platform FPS/RTS game engine'
- depends=('freeimage' 'libgl' 'liboz' 'luajit' 'openal' 'openzone-data' 'sdl_ttf')
+ depends=('liboz' 'luajit' 'openzone-data')
optdepends=('espeak: speech synthesis'
'libmad: MP3 streaming'
'faad2: AAC streaming'
View
27 etc/openzone.spec
@@ -31,30 +31,28 @@ and front-end that renders it and enables the player to manipulate with the
simulated world.
%package -n liboz
-Summary: OpenZone Core, Dynamics and Engine Libraries
+Summary: OpenZone ozCore, ozDynamics, ozEngine and ozFactory libraries
Group: System Environment/Libraries
License: zlib
%description -n liboz
-OpenZone Core Library provides facilities like container templates, array
-utilities, string class, memory manager with memory leak tracing, crash
-handlers, I/O buffers and classes for filesystem access with PhysicsFS support,
-log writer, JSON file manipulation class, math functions and linear algebra
-classes.
-OpenZone Dynamics Library is a rigid body physics engine used in OpenZone
-engine.
-OpenZone Engine Library contains basic engine building blocks for OpenZone
-game.
+ozCore library provides facilities like container templates, array utilities,
+string class, memory manager with memory leak tracing, crash handlers,
+I/O buffers and classes for filesystem access with PhysicsFS support,
+log writer, JSON file manipulation class, math functions and math classes.
+ozDynamics library is a rigid body physics engine used in OpenZone engine.
+ozEngine library contains basic engine building blocks for OpenZone game.
+ozFactory library contains functions for building OpenZone assets.
%package -n liboz-devel
-Summary: Headers for OpenZone Core, Dynamics and Engine Libraries
+Summary: Headers for liboz
Group: Development/Libraries
License: zlib
Requires: liboz = %{version}
%description -n liboz-devel
-This package contains header files for OpenZone Core, Dynamics and Engine
-Libraries.
+This package contains header files for OpenZone ozCore, ozDynamics, ozEngine and
+ozFactory libraries.
%package data
Summary: OpenZone game data
@@ -106,16 +104,19 @@ install -m644 share/openzone/*.zip "$RPM_BUILD_ROOT"%{_datadir}/openzone
%{_libdir}/libozCore.so*
%{_libdir}/libozDynamics.so*
%{_libdir}/libozEngine.so*
+%{_libdir}/libozFactory.so*
%doc src/ozCore/COPYING
%files -n liboz-devel
%defattr(-, root, root, -)
%{_libdir}/pkgconfig/ozCore.pc
%{_libdir}/pkgconfig/ozDynamics.pc
%{_libdir}/pkgconfig/ozEngine.pc
+%{_libdir}/pkgconfig/ozFactory.pc
%{_includedir}/ozCore
%{_includedir}/ozDynamics
%{_includedir}/ozEngine
+%{_includedir}/ozFactory
%doc src/ozCore/COPYING
%files data
View
1 src/CMakeLists.txt
@@ -4,6 +4,7 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
add_subdirectory( ozCore )
add_subdirectory( ozDynamics )
add_subdirectory( ozEngine )
+add_subdirectory( ozFactory )
add_subdirectory( unittest )
add_pch( pch stable.hh stable.cc )
View
2 src/builder/MD3.cc
@@ -36,7 +36,7 @@ void MD3::readAnimData()
{
File animFile( sPath + "/animation.cfg" );
- String realPath = animFile.realDir() + "/" + animFile.path();
+ String realPath = animFile.realDirectory() + "/" + animFile.path();
FILE* fs = fopen( realPath, "r" );
if( fs == nullptr ) {
View
2 src/builder/OBJ.cc
@@ -288,7 +288,7 @@ void OBJ::load()
config.clear( true );
- String realPath = modelFile.realDir() + "/" + &path[1];
+ String realPath = modelFile.realDirectory() + "/" + &path[1];
loadMaterials( realPath + "/data.mtl" );
View
1 src/builder/common.hh
@@ -24,6 +24,7 @@
#pragma once
#include <client/common.hh>
+#include <ozFactory/ozFactory.hh>
#include <builder/config.hh>
namespace oz
View
15 src/ozCore/CMakeLists.txt
@@ -76,16 +76,21 @@ add_library( ozCore
)
if( ANDROID )
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} ${ZLIB_LIBRARY} -ldl -lOpenSLES -llog ${PLATFORM_STL_LIBRARY} )
+ target_link_libraries( ozCore ${PLATFORM_STL_LIBRARY} -llog -lOpenSLES -ldl )
elseif( NACL )
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} ${ZLIB_LIBRARY} -lppapi_cpp -lppapi -lpthread )
+ target_link_libraries( ozCore -lpthread -lppapi -lppapi_cpp )
elseif( WIN32 )
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} -lwinmm )
+ target_link_libraries( ozCore -lwinmm )
elseif( NOT CMAKE_SYSTEM_NAME STREQUAL Linux )
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} -ldl -lpulse-simple -lrt -lpthread )
+ target_link_libraries( ozCore -lpthread -lrt -lpulse-simple -ldl )
else()
# TODO: Remove -lrt once glibc 2.17 becomes minimum.
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} -ldl -lpulse-simple -lasound -lrt -lpthread )
+ target_link_libraries( ozCore -lpthread -lrt -lasound -lpulse-simple -ldl )
+endif()
+
+target_link_libraries( ozCore ${PHYSFS_LIBRARY} )
+if( PLATFORM_EMBEDDED )
+ target_link_libraries( ozCore ${ZLIB_LIBRARY} )
endif()
set_target_properties( ozCore PROPERTIES VERSION ${OZ_VERSION} SOVERSION 0 )
View
2 src/ozCore/File.cc
@@ -332,7 +332,7 @@ bool File::stat()
return fileType != MISSING;
}
-String File::realDir() const
+String File::realDirectory() const
{
if( filePath.fileIsVirtual() ) {
const char* realDir = PHYSFS_getRealDir( &filePath[1] );
View
22 src/ozCore/File.hh
@@ -180,33 +180,43 @@ class File
}
/**
- * %File name.
+ * Extract directory from the path (substring before the last `/`).
+ */
+ String directory() const
+ {
+ return filePath.fileDirectory();
+ }
+
+ /**
+ * Extract file name from the path (substring after the last `/`).
*/
String name() const
{
return filePath.fileName();
}
/**
- * Name without the extension (and the dot).
+ * Extract base file name from the path (substring after the last `/` till the last dot
+ * following it).
*/
String baseName() const
{
return filePath.fileBaseName();
}
/**
- * Extension (part of base name after the last dot) or "" if no dot in base name.
+ * Extract file extension from the path (substring after the last dot in file name or "" if no
+ * extension).
*/
String extension() const
{
return filePath.fileExtension();
}
/**
- * True iff the extension (without dot) is equal to the given string.
+ * True iff file name has the given extension.
*
- * Empty string matches both no extension and files ending with dot.
+ * Empty string matches both no extension and files names ending with dot.
*/
bool hasExtension( const char* ext ) const
{
@@ -216,7 +226,7 @@ class File
/**
* %Path to the archive or mount-point of a VFS, "" for native files.
*/
- String realDir() const;
+ String realDirectory() const;
/**
* %Path to file in native file system.
View
2 src/ozCore/Math.hh
@@ -465,7 +465,7 @@ class Math
}
/**
- * Index (counting from the least significant side) of the first 1 bit or -1 if `v` is 0.
+ * Index of the first 1 bit (counting from the least significant bit) or -1 if `v` is 0.
*/
template <typename Value = int>
OZ_ALWAYS_INLINE
View
17 src/ozCore/String.cc
@@ -51,7 +51,7 @@ String::String( int count_, int ) :
}
OZ_HIDDEN
-inline void String::ensureCapacity( int newCount )
+void String::ensureCapacity( int newCount )
{
hard_assert( buffer != nullptr && count >= 0 && newCount >= 0 );
@@ -164,6 +164,13 @@ DArray<String> String::split( const char* s, char delimiter )
return array;
}
+String String::fileDirectory( const char* s )
+{
+ int slash = lastIndex( s, '/' );
+
+ return slash >= 0 ? substring( s, 0, slash ) : String( s );
+}
+
String String::fileName( const char* s )
{
int begin = s[0] == '@';
@@ -678,6 +685,7 @@ String String::create( int length, char** buffer_ )
{
String r( length, 0 );
+ r.buffer[length] = '\0';
*buffer_ = r.buffer;
return r;
}
@@ -854,6 +862,13 @@ DArray<String> String::split( char delimiter ) const
return array;
}
+String String::fileDirectory() const
+{
+ int slash = lastIndex( '/' );
+
+ return slash >= 0 ? substring( 0, slash ) : String( buffer );
+}
+
String String::fileName() const
{
int begin = buffer[0] == '@';
View
60 src/ozCore/String.hh
@@ -132,7 +132,7 @@ class String
}
/**
- * Index of the first occurrence of the character from the given index (inclusive).
+ * Index of the first occurrence of a character from the given index (inclusive).
*/
static int index( const char* s, char ch, int start = 0 )
{
@@ -145,7 +145,7 @@ class String
}
/**
- * Index of the last occurrence of the character before the given index (not inclusive).
+ * Index of the last occurrence of a character before the given index (not inclusive).
*/
static int lastIndex( const char* s, char ch, int end )
{
@@ -158,7 +158,7 @@ class String
}
/**
- * Index of the last occurrence of the character.
+ * Index of the last occurrence of a character.
*/
static int lastIndex( const char* s, char ch )
{
@@ -173,7 +173,7 @@ class String
}
/**
- * Pointer to the first occurrence of the character from the given index (inclusive).
+ * Pointer to the first occurrence of a character from the given index (inclusive).
*/
static const char* find( const char* s, char ch, int start = 0 )
{
@@ -186,7 +186,7 @@ class String
}
/**
- * Pointer to the last occurrence of the character before the given index (not inclusive).
+ * Pointer to the last occurrence of a character before the given index (not inclusive).
*/
static const char* findLast( const char* s, char ch, int end )
{
@@ -199,7 +199,7 @@ class String
}
/**
- * Pointer to the last occurrence of the character.
+ * Pointer to the last occurrence of a character.
*/
static const char* findLast( const char* s, char ch )
{
@@ -277,24 +277,31 @@ class String
}
/**
+ * Extract directory from a path (substring before the last `/`).
+ */
+ static String fileDirectory( const char* s );
+
+ /**
* Extract file name from a path (substring after the last `/`).
*/
static String fileName( const char* s );
/**
- * Extract base file name from a path (substring after the last `/` till the last following
- * dot).
+ * Extract base file name from a path (substring after the last `/` till the last dot following
+ * it).
*/
static String fileBaseName( const char* s );
/**
- * Extract file extension from a path (substring after the last dot in file name extracted form
- * the path).
+ * Extract file extension from the path (substring after the last dot in file name or "" if no
+ * extension).
*/
static String fileExtension( const char* s );
/**
- * True iff file name extracted from a path has the given extension.
+ * True iff file name has the given extension.
+ *
+ * Empty string matches both no extension and files names ending with dot.
*/
static bool fileHasExtension( const char* s, const char* ext );
@@ -503,7 +510,7 @@ class String
* Create uninitialised string.
*
* Terminating null character is written, so it represents a valid string even if not
- * initialised manually by the caller.
+ * initialised by the caller.
*
* @param length length of string (without the terminating null character).
* @param buffer where to pass non-constant pointer to the internal buffer.
@@ -752,47 +759,47 @@ class String
}
/**
- * Index of the first occurrence of the character from the given index (inclusive).
+ * Index of the first occurrence of a character from the given index (inclusive).
*/
int index( char ch, int start = 0 ) const
{
return index( buffer, ch, start );
}
/**
- * Index of the last occurrence of the character before the given index (not inclusive).
+ * Index of the last occurrence of a character before the given index (not inclusive).
*/
int lastIndex( char ch, int end ) const
{
return lastIndex( buffer, ch, end );
}
/**
- * Index of the last occurrence of the character.
+ * Index of the last occurrence of a character.
*/
int lastIndex( char ch ) const
{
return lastIndex( buffer, ch, count );
}
/**
- * Pointer to the first occurrence of the character from the given index (inclusive).
+ * Pointer to the first occurrence of a character from the given index (inclusive).
*/
const char* find( char ch, int start = 0 ) const
{
return find( buffer, ch, start );
}
/**
- * Pointer to the last occurrence of the character before the given index (not inclusive).
+ * Pointer to the last occurrence of a character before the given index (not inclusive).
*/
const char* findLast( char ch, int end ) const
{
return findLast( buffer, ch, end );
}
/**
- * Pointer to the last occurrence of the character.
+ * Pointer to the last occurrence of a character.
*/
const char* findLast( char ch ) const
{
@@ -911,24 +918,31 @@ class String
}
/**
+ * Extract directory from a path (substring before the last `/`).
+ */
+ String fileDirectory() const;
+
+ /**
* Extract file name from a path (substring after the last `/`).
*/
String fileName() const;
/**
- * Extract base file name from a path (substring after the last `/` till the last following
- * dot).
+ * Extract base file name from a path (substring after the last `/` till the last dot following
+ * it).
*/
String fileBaseName() const;
/**
- * Extract file extension from a path (substring after the last dot in file name extracted form
- * the path).
+ * Extract file extension from the path (substring after the last dot in file name or "" if no
+ * extension).
*/
String fileExtension() const;
/**
- * True iff file name extracted from a path has the given extension.
+ * True iff file name has the given extension.
+ *
+ * Empty string matches both no extension and files names ending with dot.
*/
bool fileHasExtension( const char* ext ) const;
View
6 src/ozDynamics/CMakeLists.txt
@@ -33,11 +33,11 @@ add_library( ozDynamics
#END SOURCES
)
+target_link_libraries( ozDynamics ozCore )
+
# HACK
if( OZ_DYNAMICS )
- target_link_libraries( ozDynamics ${ODE_LIBRARIES} ozCore )
-else()
- target_link_libraries( ozDynamics ozCore )
+ target_link_libraries( ozDynamics ${ODE_LIBRARIES} )
endif()
set_target_properties( ozDynamics PROPERTIES VERSION ${OZ_VERSION} SOVERSION 0 )
View
4 src/ozEngine/AL.hh
@@ -154,9 +154,7 @@ class AL
static void checkError( const char* function, const char* file, int line );
/**
- * Load OpenAL buffer with a sound sample from a file.
- *
- * WAVE and Ogg Vorbis files are supported.
+ * Load OpenAL buffer from a WAVE of Ogg Vorbis file.
*/
static bool bufferDataFromFile( ALuint buffer, const File& file );
View
19 src/ozEngine/CMakeLists.txt
@@ -8,20 +8,19 @@ add_library( ozEngine
AL.hh
ALSource.hh
ALStreamingBuffer.hh
- Builder.hh
common.hh
Cursor.hh
GL.hh
GLTexture.hh
ozEngine.hh
pch.hh
Pepper.hh
+ Shader.hh
Window.hh
ALBuffer.cc
AL.cc
ALSource.cc
ALStreamingBuffer.cc
- Builder.cc
common.cc
Cursor.cc
GL.cc
@@ -31,6 +30,8 @@ add_library( ozEngine
#END SOURCES
)
+target_link_libraries( ozEngine ozCore )
+
# OpenGL.
if( OZ_GL_ES )
target_link_libraries( ozEngine ${GLES2_LIBRARIES} )
@@ -43,27 +44,19 @@ target_link_libraries( ozEngine ${OPENAL_LIBRARY} )
# SDL.
if( OZ_SDL2 )
+ target_link_libraries( ozEngine ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARIES} )
if( OZ_NET )
target_link_libraries( ozEngine ${SDL2_NET_LIBRARIES} )
endif()
- target_link_libraries( ozEngine ${SDL2_TTF_LIBRARIES} ${SDL2_LIBRARIES} )
else()
+ target_link_libraries( ozEngine ${SDL_LIBRARIES} ${SDL_TTF_LIBRARIES} )
if( OZ_NET )
target_link_libraries( ozEngine ${SDL_NET_LIBRARIES} )
endif()
- target_link_libraries( ozEngine ${SDL_TTF_LIBRARIES} ${SDL_LIBRARIES} )
endif()
# libvorbisfile.
-target_link_libraries( ozEngine ozDynamics ${VORBISFILE_LIBRARIES} )
-
-# FreeImage.
-target_link_libraries( ozEngine ${FREEIMAGEPLUS_LIBRARY} )
-
-# squish.
-if( OZ_NONFREE )
- target_link_libraries( ozEngine ${SQUISH_LIBRARY} )
-endif()
+target_link_libraries( ozEngine ${VORBISFILE_LIBRARIES} )
# Dependencies.
if( PLATFORM_EMBEDDED )
View
511 src/ozEngine/Shader.cc
@@ -0,0 +1,511 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/Shader.cc
+ */
+
+#include "Shader.hh"
+
+#include "GL.hh"
+
+#define OZ_REGISTER_UNIFORM( uniformVar, uniformName ) \
+ programs[id].uniform.uniformVar = glGetUniformLocation( programs[id].program, uniformName )
+
+#define OZ_REGISTER_ATTRIBUTE( location, name ) \
+ glBindAttribLocation( programs[id].program, location, name )
+
+namespace oz
+{
+
+struct Program
+{
+ GLuint vertShader;
+ GLuint fragShader;
+ GLuint program;
+ Uniform uniform;
+};
+
+static Map<String, uint> vertShaders;
+static Map<String, uint> fragShaders;
+static List<Program> programs;
+#if 0
+void Transform::ortho( int width, int height )
+{
+ float cx = float( 2.0 / double( width ) );
+ float cy = float( 2.0 / double( height ) );
+
+ proj = Mat44( cx, 0.0f, 0.0f, 0.0f,
+ 0.0f, cy, 0.0f, 0.0f,
+ 0.0f, 0.0f, -0.001f, 0.0f,
+ -1.0f, -1.0f, 0.0f, 1.0f );
+}
+
+void Transform::projection()
+{
+ double lr = double( client::camera.vertPlane );
+ double tb = double( client::camera.horizPlane );
+ double near = double( client::Camera::MIN_DISTANCE );
+ double far = double( client::camera.maxDist );
+
+ float cx = float( near / lr );
+ float cy = float( near / tb );
+ float cz = float( -( far + near ) / ( far - near ) );
+ float tz = float( -( 2.0 * far * near ) / ( far - near ) );
+
+ proj = Mat44( cx, 0.0f, 0.0f, 0.0f,
+ 0.0f, cy, 0.0f, 0.0f,
+ 0.0f, 0.0f, cz, -1.0f,
+ 0.0f, 0.0f, tz, 0.0f );
+}
+
+void Transform::applyCamera()
+{
+ projCamera = proj * camera;
+
+ glUniform3fv( uniform.cameraPosition, 1, client::camera.p );
+}
+
+void Transform::applyModel() const
+{
+ glUniformMatrix4fv( uniform.modelTransform, 1, GL_FALSE, model );
+}
+
+void Transform::apply() const
+{
+ glUniformMatrix4fv( uniform.projModelTransform, 1, GL_FALSE, projCamera * model );
+ glUniformMatrix4fv( uniform.modelTransform, 1, GL_FALSE, model );
+}
+
+void Transform::applyColour() const
+{
+ setColour( colour );
+}
+
+void Transform::setColour( const Mat44& colour_ ) const
+{
+ glUniformMatrix4fv( uniform.colourTransform, 1, GL_FALSE, colour_ );
+}
+
+void Transform::setColour( const Vec4& colour_ ) const
+{
+ setColour( Mat44::scaling( colour_ ) );
+}
+
+void Transform::setColour( float r, float g, float b, float a ) const
+{
+ setColour( Mat44::scaling( Vec4( r, g, b, a ) ) );
+}
+
+Transform tf;
+#endif
+const int Shader::SAMPLER_MAP[] = { 0, 1, 2, 3, 4, 5 };
+char Shader::logBuffer[LOG_BUFFER_SIZE];
+String Shader::defines;
+#if 0
+Shader::Light::Light( const Point& pos_, const Vec4& diffuse_ ) :
+ pos( pos_ ), diffuse( diffuse_ )
+{}
+#endif
+
+static Buffer shaderPrologue;
+
+bool Shader::readFile( const File& file, OutputStream* ostream, List<String>* fileNames,
+ List<int>* fileLengths )
+{
+ Buffer buffer = file.read();
+ if( buffer.isEmpty() ) {
+ return false;
+ }
+
+ InputStream is = buffer.inputStream();
+ int begin = ostream->tell();
+
+ while( is.isAvailable() ) {
+ String line = is.readLine();
+
+ if( line.beginsWith( "#include" ) ) {
+ int startQuote = line.index( '"' );
+ int endQuote = line.lastIndex( '"' );
+
+ if( startQuote > 0 && startQuote < endQuote ) {
+ File includeFile = file.directory() + "/" + line.substring( startQuote + 1, endQuote );
+
+ if( !readFile( includeFile, ostream, fileNames, fileLengths ) ) {
+ return false;
+ }
+ }
+ }
+ else {
+ ostream->writeLine( line );
+ }
+ }
+
+ if( !fileNames->contains( file.path() ) ) {
+ fileNames->add( file.path() );
+ fileLengths->add( ostream->tell() - begin );
+ }
+ return true;
+}
+
+bool Shader::loadShader( const File& file, GLenum type )
+{
+ List<String> fileNames;
+ List<int> fileOffsets;
+ OutputStream ostream( 0 );
+
+ fileNames.add();
+ ostream.writeChars( shaderPrologue.begin(), shaderPrologue.length() );
+
+ if( !readFile( file, &ostream, &fileNames, &fileOffsets ) ) {
+ return false;
+ }
+
+ const char** fileContents = new const char*[ fileNames.length() ];
+ int fileLengths = new int[ fileNames.length() ];
+ int prevOffset = 0;
+
+ for( int i = 0; i < fileOffsets.length(); ++i ) {
+ fileContents[i] = ostream.begin() + fileOffsets[i];
+ fileLengths[i] = i == fileOffsets.length() - 1 ? :
+ fileOffsets[i + 1] - fileOffsets[i];
+ }
+
+ hard_assert( fileNames.length() == fileContents.length() &&
+ fileNames.length() == fileLengths.length() );
+
+ GLuint id = glCreateShader( type );
+ glShaderSource( id, fileNames.length(), fileContents.fi, fileLengths.begin() );
+ glCompileShader( id );
+
+ int result, length;
+
+ glGetShaderiv( id, GL_COMPILE_STATUS, &result );
+ glGetShaderInfoLog( id, LOG_BUFFER_SIZE - 1, &length, logBuffer );
+ logBuffer[LOG_BUFFER_SIZE - 1] = '\0';
+
+ if( length != 0 ) {
+ Log::printRaw( "\n%s:\n%s", file.path().cstr(), logBuffer );
+ }
+
+ OZ_GL_CHECK_ERROR();
+
+ return result == GL_TRUE;
+}
+
+void Shader::loadProgram( const char* name )
+{
+ File configFile( String( "@glsl/%s.json", name ) );
+ JSON programConfig;
+
+ if( !programConfig.load( configFile ) ) {
+ OZ_ERROR( "Failed to read shader program configuration '%s'", configFile.path().cstr() );
+ }
+
+ const char* vertName = programConfig[0].asString();
+ const char* fragName = programConfig[1].asString();
+
+ const uint* vertId = vertShaders.find( vertName );
+ const uint* fragId = fragShaders.find( fragName );
+
+ if( vertId == nullptr ) {
+ OZ_ERROR( "Invalid vertex shader '%s' requested for shader program '%s'", vertName, name );
+ }
+ if( fragId == nullptr ) {
+ OZ_ERROR( "Invalid fragment shader '%s' requested for shader program '%s'", fragName, name );
+ }
+
+ int id = programs.length();
+
+ programs.add();
+ programs[id].vertShader = *vertId;
+ programs[id].fragShader = *fragId;
+ programs[id].program = glCreateProgram();
+
+ glAttachShader( programs[id].program, programs[id].vertShader );
+ glAttachShader( programs[id].program, programs[id].fragShader );
+
+ OZ_REGISTER_ATTRIBUTE( POSITION, "inPosition" );
+ OZ_REGISTER_ATTRIBUTE( TEXCOORD, "inTexCoord" );
+ OZ_REGISTER_ATTRIBUTE( NORMAL, "inNormal" );
+
+ glLinkProgram( programs[id].program );
+
+ int result;
+ glGetProgramiv( programs[id].program, GL_LINK_STATUS, &result );
+
+ int length;
+ glGetProgramInfoLog( programs[id].program, LOG_BUFFER_SIZE, &length, logBuffer );
+ logBuffer[LOG_BUFFER_SIZE - 1] = '\0';
+
+ if( length != 0 ) {
+ if( result == GL_TRUE ) {
+ Log::verboseMode = true;
+ }
+
+ Log::printRaw( "\n%s:\n%s", name, logBuffer );
+ Log::verboseMode = false;
+ }
+
+ if( result != GL_TRUE ) {
+ OZ_ERROR( "Shader program '%s' linking failed", name );
+ }
+
+ glUseProgram( programs[id].program );
+
+ OZ_REGISTER_UNIFORM( projModelTransform, "oz_ProjModelTransform" );
+ OZ_REGISTER_UNIFORM( modelTransform, "oz_ModelTransform" );
+ OZ_REGISTER_UNIFORM( boneTransforms, "oz_BoneTransforms" );
+ OZ_REGISTER_UNIFORM( meshAnimation, "oz_MeshAnimation" );
+
+ OZ_REGISTER_UNIFORM( colourTransform, "oz_ColourTransform" );
+ OZ_REGISTER_UNIFORM( textures, "oz_Textures" );
+
+ OZ_REGISTER_UNIFORM( caelumLight_dir, "oz_CaelumLight.dir" );
+ OZ_REGISTER_UNIFORM( caelumLight_diffuse, "oz_CaelumLight.diffuse" );
+ OZ_REGISTER_UNIFORM( caelumLight_ambient, "oz_CaelumLight.ambient" );
+ OZ_REGISTER_UNIFORM( cameraPosition, "oz_CameraPosition" );
+
+ OZ_REGISTER_UNIFORM( fog_dist, "oz_Fog.dist" );
+ OZ_REGISTER_UNIFORM( fog_colour, "oz_Fog.colour" );
+
+ OZ_REGISTER_UNIFORM( starsColour, "oz_StarsColour" );
+ OZ_REGISTER_UNIFORM( waveBias, "oz_WaveBias" );
+ OZ_REGISTER_UNIFORM( wind, "oz_Wind" );
+
+// uniform = programs[id].uniform;
+
+ if( setSamplerMap ) {
+// glUniform1iv( uniform.textures, aLength( SAMPLER_MAP ), SAMPLER_MAP );
+ }
+
+ Mat44 bones[] = {
+ Mat44::ID, Mat44::ID, Mat44::ID, Mat44::ID,
+ Mat44::ID, Mat44::ID, Mat44::ID, Mat44::ID,
+ Mat44::ID, Mat44::ID, Mat44::ID, Mat44::ID,
+ Mat44::ID, Mat44::ID, Mat44::ID, Mat44::ID
+ };
+
+// glUniformMatrix4fv( uniform.boneTransforms, 16, GL_FALSE, bones[0] );
+
+ OZ_GL_CHECK_ERROR();
+}
+
+Shader::Shader() :
+ mode( UI ), plain( -1 ), defaultMasks( 0 )
+{}
+#if 0
+void Shader::program( int id )
+{
+ if( id == activeProgram ) {
+ return;
+ }
+
+ activeProgram = id;
+
+ glUseProgram( programs[id].program );
+ uniform = programs[id].uniform;
+
+ OZ_GL_CHECK_ERROR();
+}
+
+void Shader::setLightingDistance( float distance )
+{
+ lightingDistance = distance;
+}
+
+void Shader::setAmbientLight( const Vec4& colour )
+{
+ caelumLight.ambient = colour;
+}
+
+void Shader::setCaelumLight( const Vec3& dir, const Vec4& colour )
+{
+ caelumLight.dir = dir;
+ caelumLight.diffuse = colour;
+}
+
+void Shader::updateLights()
+{
+ glUniform3fv( uniform.caelumLight_dir, 1, caelumLight.dir );
+ glUniform4fv( uniform.caelumLight_diffuse, 1, caelumLight.diffuse );
+ glUniform4fv( uniform.caelumLight_ambient, 1, caelumLight.ambient );
+}
+
+void Shader::init()
+{
+ Log::print( "Initialising Shader ..." );
+
+ hasVertexTexture = config.include( "shader.vertexTexture", true ).asBool();
+ setSamplerMap = config.include( "shader.setSamplerMap", true ).asBool();
+ doPostprocess = config["render.postprocess"].asBool();
+ isLowDetail = config["render.lowDetail"].asBool();
+
+ medium = 0;
+
+ // bind white texture to id 0 to emulate fixed functionality (in fixed functionality sampler
+ // always returns white colour when texture 0 is bound)
+ ubyte whitePixel[] = { 0xff, 0xff, 0xff, 0xff };
+
+ glGenTextures( 1, &defaultTexture );
+ glBindTexture( GL_TEXTURE_2D, defaultTexture );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, whitePixel );
+
+ // default masks (specular 0.0, emission 0.0)
+ ubyte masksPixel[] = { 0x00, 0x00, 0x00, 0xff };
+
+ glGenTextures( 1, &defaultMasks );
+ glBindTexture( GL_TEXTURE_2D, defaultMasks );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, masksPixel );
+
+ // default normals for bumpmap [0, 0, 1]
+ ubyte normalsPixel[] = { 0x80, 0x80, 0xff, 0xff };
+
+ glGenTextures( 1, &defaultNormals );
+ glBindTexture( GL_TEXTURE_2D, defaultNormals );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, normalsPixel );
+
+ glBindTexture( GL_TEXTURE_2D, shader.defaultTexture );
+
+ for( int i = 2; i >= 0; --i ) {
+ glActiveTexture( GL_TEXTURE0 + uint( i ) );
+ glBindTexture( GL_TEXTURE_2D, shader.defaultTexture );
+ }
+
+ if( liber.shaders.length() == 0 ) {
+ OZ_ERROR( "Shaders missing" );
+ }
+
+ plain = liber.shaderIndex( "plain" );
+ mesh = liber.shaderIndex( "mesh" );
+ postprocess = liber.shaderIndex( "postprocess" );
+
+ programs.resize( liber.shaders.length() );
+
+ const char* sources[3];
+ int lengths[3];
+
+#ifdef GL_ES_VERSION_2_0
+ defines = "#version 100\n";
+#else
+ defines = "#version 120\n";
+#endif
+ defines = defines + ( hasVertexTexture ? "#define OZ_VERTEX_TEXTURE\n" : "\n" );
+ defines = defines + ( doPostprocess ? "#define OZ_POSTPROCESS\n" : "\n" );
+ defines = defines + ( isLowDetail ? "#define OZ_LOW_DETAIL\n" : "\n" );
+
+ for( int i = 4; i < 10; ++i ) {
+ defines = defines + "\n";
+ }
+
+ sources[0] = defines;
+ lengths[0] = defines.length();
+
+ File file( "@glsl/header.glsl" );
+ Buffer buffer = file.read();
+
+ if( buffer.isEmpty() ) {
+ OZ_ERROR( "'%s' read failed", file.path().cstr() );
+ }
+
+ sources[1] = buffer.begin();
+ lengths[1] = buffer.length();
+
+ File dir( "@glsl" );
+ DArray<File> shaderFiles = dir.ls();
+
+ foreach( file, shaderFiles.citer() ) {
+ if( file->hasExtension( "vert" ) ) {
+ uint id = glCreateShader( GL_VERTEX_SHADER );
+
+ vertShaders.add( file->baseName(), id );
+ compileShader( id, file->path(), sources, lengths );
+ }
+ else if( file->hasExtension( "frag" ) ) {
+ uint id = glCreateShader( GL_FRAGMENT_SHADER );
+
+ fragShaders.add( file->baseName(), id );
+ compileShader( id, file->path(), sources, lengths );
+ }
+ }
+
+ for( int i = 0; i < liber.shaders.length(); ++i ) {
+ loadProgram( i );
+ }
+
+ Log::printEnd( " OK" );
+}
+#endif
+#if 0
+void Shader::destroy()
+{
+ Log::print( "Destroying Shader ..." );
+
+ for( int i = 0; i < liber.shaders.length(); ++i ) {
+ if( programs[i].program != 0 ) {
+ glDetachShader( programs[i].program, programs[i].vertShader );
+ glDetachShader( programs[i].program, programs[i].fragShader );
+ glDeleteProgram( programs[i].program );
+ programs[i].program = 0;
+ }
+ }
+ foreach( vertShader, vertShaders.citer() ) {
+ glDeleteShader( vertShader->value );
+ }
+ foreach( fragShader, fragShaders.citer() ) {
+ glDeleteShader( fragShader->value );
+ }
+
+ fragShaders.clear();
+ fragShaders.deallocate();
+ vertShaders.clear();
+ vertShaders.deallocate();
+ programs.clear();
+
+ if( defaultNormals != 0 ) {
+ glDeleteTextures( 1, &defaultNormals );
+ defaultNormals = 0;
+ }
+ if( defaultMasks != 0 ) {
+ glDeleteTextures( 1, &defaultMasks );
+ defaultMasks = 0;
+ }
+ if( defaultTexture != 0 ) {
+ glDeleteTextures( 1, &defaultTexture );
+ defaultTexture = 0;
+ }
+
+ plain = -1;
+ defines = "";
+
+ OZ_GL_CHECK_ERROR();
+
+ Log::printEnd( " OK" );
+}
+#endif
+}
View
198 src/ozEngine/Shader.hh
@@ -0,0 +1,198 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/Shader.hh
+ *
+ * `Shader` class.
+ */
+
+#pragma once
+
+#include "GL.hh"
+
+namespace oz
+{
+
+struct Uniform
+{
+ int projModelTransform;
+ int modelTransform;
+ int boneTransforms;
+ int meshAnimation;
+
+ int colourTransform;
+ int textures;
+
+ int caelumLight_dir;
+ int caelumLight_diffuse;
+ int caelumLight_ambient;
+ int cameraPosition;
+
+ int fog_dist;
+ int fog_colour;
+
+ int starsColour;
+ int waveBias;
+ int wind;
+};
+
+class Transform
+{
+ friend class Shader;
+
+ private:
+
+ SList<Mat44, 8> stack;
+
+ public:
+
+ Mat44 proj;
+ Mat44 camera;
+ Mat44 model;
+
+ Mat44 projCamera;
+
+ Mat44 colour;
+
+ OZ_ALWAYS_INLINE
+ void push()
+ {
+ stack.pushLast( model );
+ }
+
+ OZ_ALWAYS_INLINE
+ void pop()
+ {
+ model = stack.popLast();
+ }
+
+ void ortho( int width, int height );
+ void projection();
+
+ void applyCamera();
+ void applyModel() const;
+ void apply() const;
+
+ void applyColour() const;
+
+ void setColour( const Mat44& colour ) const;
+ void setColour( const Vec4& colour ) const;
+ void setColour( float r, float g, float b, float a = 1.0f ) const;
+
+};
+
+class Shader
+{
+ public:
+
+ enum Mode
+ {
+ UI,
+ SCENE
+ };
+
+ enum Type
+ {
+ POSITION,
+ TEXCOORD,
+ NORMAL,
+ TANGENT,
+ BINORMAL,
+ COLOUR
+ };
+
+ public:
+
+ struct CaelumLight
+ {
+ Vec3 dir;
+ Vec4 diffuse;
+ Vec4 ambient;
+ };
+
+ struct Light
+ {
+ Point pos;
+ Vec4 diffuse;
+
+ explicit Light() = default;
+ explicit Light( const Point& pos, const Vec4& diffuse );
+ };
+
+ static const int LOG_BUFFER_SIZE = 8192;
+ static const int SAMPLER_MAP[];
+
+ static char logBuffer[LOG_BUFFER_SIZE];
+
+ static String defines;
+
+ SList<int, 8> programStack;
+
+ float lightingDistance;
+ CaelumLight caelumLight;
+
+ static bool readFile( const File& file, OutputStream* ostream, List<String>* fileNames,
+ List<int>* fileLengths );
+ static bool loadShader( const File& file, GLenum type );
+ void compileShader( uint id, const char* path, const char** sources, int* lengths ) const;
+ void loadProgram( const char* name );
+
+ public:
+
+ Mode mode;
+
+ int plain;
+ int mesh;
+ int postprocess;
+
+ int activeProgram;
+
+ Vec4 fogColour;
+
+ uint defaultTexture;
+ uint defaultMasks;
+ uint defaultNormals;
+
+ int medium;
+ bool hasS3TC;
+ bool hasVertexTexture;
+ bool setSamplerMap;
+ bool doPostprocess;
+ bool isLowDetail;
+
+ explicit Shader();
+
+ void program( int id );
+
+ void setLightingDistance( float distance );
+ void setAmbientLight( const Vec4& colour );
+ void setCaelumLight( const Vec3& dir, const Vec4& colour );
+
+ void updateLights();
+
+ void init();
+ void destroy();
+
+};
+
+}
View
3 src/ozEngine/config.hh.in
@@ -28,6 +28,3 @@
// Use OpenGL ES 2.0 instead of OpenGL 2.1.
#cmakedefine OZ_GL_ES
-
-// Enable squish S3TC library.
-#cmakedefine OZ_NONFREE
View
3 src/ozEngine/ozEngine.hh
@@ -39,7 +39,6 @@
#include "ALStreamingBuffer.hh"
#include "ALSource.hh"
+#include "Shader.hh"
#include "Cursor.hh"
#include "Window.hh"
-
-#include "Builder.hh"
View
2 src/ozEngine/ozEngine.pc.in
@@ -7,5 +7,5 @@ Name: ozEngine
Description: OpenZone Engine Library
Version: @OZ_VERSION@
Requires: ozCore ozDynamics
-Libs: -L${libdir} -lozDynamics
+Libs: -L${libdir} -lozEngine
Cflags: -std=c++11 -I${includedir}
View
47 src/ozEngine/Builder.cc → src/ozFactory/Builder.cc
@@ -1,5 +1,5 @@
/*
- * ozEngine - OpenZone Engine Library.
+ * ozFactory - OpenZone Assets Builder Library.
*
* Copyright © 2002-2013 Davorin Učakar
*
@@ -21,7 +21,7 @@
*/
/**
- * @file ozEngine/Builder.cc
+ * @file ozFactory/Builder.cc
*/
#include "Builder.hh"
@@ -88,7 +88,8 @@ bool Builder::buildDDS( const File& file, int options, OutputStream* ostream )
return false;
}
- int nMipmaps = options & MIPMAPS_BIT ? Math::index1( max( width, height ) ) + 1 : 1;
+ int pitchOrLinSize = pitch;
+ int nMipmaps = options & MIPMAPS_BIT ? Math::index1( max( width, height ) ) + 1 : 1;
int flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
flags |= options & MIPMAPS_BIT ? DDSD_MIPMAPCOUNT : 0;
@@ -98,17 +99,31 @@ bool Builder::buildDDS( const File& file, int options, OutputStream* ostream )
caps |= options & MIPMAPS_BIT ? DDSDCAPS_COMPLEX | DDSDCAPS_MIPMAP : 0;
int pixelFlags = 0;
- pixelFlags |= bpp == 32 ? DDPF_ALPHAPIXELS : 0;
+ pixelFlags |= image.isTransparent() ? DDPF_ALPHAPIXELS : 0;
pixelFlags |= options & COMPRESSION_BIT ? DDPF_FOURCC :
bpp == 8 ? DDPF_LUMINANCE : DDPF_RGB;
+ const char* compression = "\0\0\0\0";
+
+#ifdef OZ_NONFREE
+ int squishFlags = image.isTransparent() ? squish::kDxt5 : squish::kDxt1;
+ squishFlags |= options & QUALITY_BIT ?
+ squish::kColourIterativeClusterFit | squish::kWeightColourByAlpha :
+ squish::kColourRangeFit;
+
+ if( options & COMPRESSION_BIT ) {
+ pitchOrLinSize = squish::GetStorageRequirements( width, height, squishFlags );
+ compression = image.isTransparent() ? "DXT5" : "DXT1";
+ }
+#endif
+
// Header beginning.
ostream->writeChars( "DDS ", 4 );
ostream->writeInt( 124 );
ostream->writeInt( flags );
ostream->writeInt( height );
ostream->writeInt( width );
- ostream->writeInt( pitch ); // Will be overwritten later if compressed.
+ ostream->writeInt( pitchOrLinSize );
ostream->writeInt( 0 );
ostream->writeInt( nMipmaps );
@@ -128,7 +143,7 @@ bool Builder::buildDDS( const File& file, int options, OutputStream* ostream )
// Pixel format.
ostream->writeInt( 32 );
ostream->writeInt( pixelFlags );
- ostream->writeChars( bpp == 32 ? "DXT5" : "DXT1", 4 );
+ ostream->writeChars( compression, 4 );
ostream->writeInt( bpp );
ostream->writeUInt( 0x00ff0000 );
ostream->writeUInt( 0x0000ff00 );
@@ -150,19 +165,12 @@ bool Builder::buildDDS( const File& file, int options, OutputStream* ostream )
pitch = int( level.getScanWidth() );
}
-#ifdef OZ_NONFREE
- int squishFlags = bpp == 32 ? squish::kDxt5 : squish::kDxt5;
- squishFlags |= options & QUALITY_BIT ?
- squish::kColourIterativeClusterFit | squish::kWeightColourByAlpha :
- squish::kColourRangeFit;
-#endif
-
if( options & COMPRESSION_BIT ) {
#ifdef OZ_NONFREE
level.convertTo32Bits();
- int size = squish::GetStorageRequirements( width, height, squishFlags );
- char* pixels = reinterpret_cast<char*>( level.accessPixels() );
+ int size = squish::GetStorageRequirements( width, height, squishFlags );
+ ubyte* pixels = level.accessPixels();
// Swap red and blue channels.
for( int y = 0; y < height; ++y ) {
@@ -174,15 +182,6 @@ bool Builder::buildDDS( const File& file, int options, OutputStream* ostream )
squish::CompressImage( level.accessPixels(), width, height, ostream->forward( size ),
squishFlags );
-
- // Replace pitch with "linear size".
- if( i == 0 ) {
- int pos = ostream->tell();
-
- ostream->seek( 20 );
- ostream->writeInt( size );
- ostream->seek( pos );
- }
#endif
}
else {
View
4 src/ozEngine/Builder.hh → src/ozFactory/Builder.hh
@@ -1,5 +1,5 @@
/*
- * ozEngine - OpenZone Engine Library.
+ * ozFactory - OpenZone Assets Builder Library.
*
* Copyright © 2002-2013 Davorin Učakar
*
@@ -21,7 +21,7 @@
*/
/**
- * @file ozEngine/Builder.hh
+ * @file ozFactory/Builder.hh
*
* `Builder` class.
*/
View
35 src/ozFactory/CMakeLists.txt
@@ -0,0 +1,35 @@
+if( PLATFORM_EMBEDDED )
+ return()
+endif()
+
+configure_file( config.hh.in config.hh @ONLY )
+configure_file( ozFactory.pc.in ozFactory.pc @ONLY )
+
+add_library( ozFactory
+ ${CMAKE_CURRENT_BINARY_DIR}/config.hh
+#BEGIN SOURCES
+ Builder.hh
+ common.hh
+ ozFactory.hh
+ pch.hh
+ Builder.cc
+#END SOURCES
+)
+
+target_link_libraries( ozFactory ozCore ${FREEIMAGEPLUS_LIBRARY} )
+if( OZ_NONFREE )
+ target_link_libraries( ozFactory ${SQUISH_LIBRARY} )
+endif()
+
+set_target_properties( ozFactory PROPERTIES VERSION ${OZ_VERSION} SOVERSION 0 )
+
+add_pch( ozFactory_pch pch.hh pch.cc )
+use_pch( ozFactory ozFactory_pch )
+
+install( TARGETS ozFactory
+ RUNTIME DESTINATION bin${OZ_BINARY_SUBDIR}
+ LIBRARY DESTINATION lib${OZ_BINARY_SUBDIR}
+ ARCHIVE DESTINATION lib${OZ_BINARY_SUBDIR} )
+install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN *.hh )
+install( FILES ${CMAKE_CURRENT_BINARY_DIR}/config.hh DESTINATION include/ozFactory )
+install( FILES ${CMAKE_CURRENT_BINARY_DIR}/ozFactory.pc DESTINATION lib${OZ_BINARY_SUBDIR}/pkgconfig )
View
17 src/ozFactory/COPYING
@@ -0,0 +1,17 @@
+Copyright © 2002-2013 Davorin Učakar
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from
+the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software in
+ a product, an acknowledgement in the product documentation would be
+ appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
View
32 src/ozFactory/common.hh
@@ -0,0 +1,32 @@
+/*
+ * ozFactory - OpenZone Assets Builder Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozFactory/common.hh
+ *
+ * Common include file for ozFactory.
+ */
+
+#pragma once
+
+#include "pch.hh"
+#include <ozFactory/config.hh>
View
30 src/ozFactory/config.hh.in
@@ -0,0 +1,30 @@
+/*
+ * ozFactory - OpenZone Assets Builder Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+#pragma once
+
+/*
+ * Configuration variables
+ */
+
+// Enable squish S3TC library.
+#cmakedefine OZ_NONFREE
View
33 src/ozFactory/ozFactory.hh
@@ -0,0 +1,33 @@
+/*
+ * ozFactory - OpenZone Assets Builder Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/ozFactory.hh
+ *
+ * Main public header for OpenZone Assets Builder Library.
+ */
+
+#pragma once
+
+#include "common.hh"
+
+#include "Builder.hh"
View
11 src/ozFactory/ozFactory.pc.in
@@ -0,0 +1,11 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib@OZ_BINARY_SUBDIR@
+includedir=${prefix}/include
+
+Name: ozFactory
+Description: OpenZone Assets Builder Library
+Version: @OZ_VERSION@
+Requires: ozCore
+Libs: -L${libdir} -lozFactory
+Cflags: -std=c++11 -I${includedir}
View
29 src/ozFactory/pch.cc
@@ -0,0 +1,29 @@
+/*
+ * ozFactory - OpenZone Assets Builder Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozFactory/pch.cc
+ *
+ * Trigger for precompiled header.
+ */
+
+#include "pch.hh"
View
29 src/ozFactory/pch.hh
@@ -0,0 +1,29 @@
+/*
+ * ozFactory - OpenZone Assets Builder Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozFactory/pch.hh
+ *
+ * Precompiled header.
+ */
+
+#include <ozCore/ozCore.hh>
View
2 src/tests/CMakeLists.txt
@@ -3,7 +3,7 @@ if( NOT OZ_TESTS )
endif()
add_executable( engine engine.cc )
-target_link_libraries( engine ozEngine )
+target_link_libraries( engine ozEngine ozFactory )
add_executable( foreach foreach.cc )
target_link_libraries( foreach ozCore )
View
11 src/tests/engine.cc
@@ -23,6 +23,7 @@
#include <ozCore/ozCore.hh>
#include <ozEngine/ozEngine.hh>
+#include <ozFactory/ozFactory.hh>
#include <SDL.h>
#include <AL/alc.h>
@@ -101,5 +102,15 @@ int main( int argc, char** argv )
alcCloseDevice( device );
Window::destroy();
SDL_Quit();
+
+ List<String> fileNames;
+ List<Buffer> fileContents;
+
+// Shader::readFile( "data/oz_base/glsl/mesh.vert", &fileNames, &fileContents );
+
+ for( const Buffer& b : fileContents ) {
+ Log() << "---------------\n";
+ Log() << b.toString();
+ }
return 0;
}
View
7 src/tools/CMakeLists.txt
@@ -25,11 +25,16 @@ else()
install( TARGETS openzone RUNTIME DESTINATION bin${OZ_BINARY_SUBDIR} )
add_executable( ozBuild ozBuild.cc )
- target_link_libraries( ozBuild builder client modules nirvana matrix common ozEngine )
+ target_link_libraries( ozBuild builder client modules nirvana matrix common ozFactory ozEngine )
use_pch( ozBuild pch )
install( TARGETS ozBuild RUNTIME DESTINATION bin${OZ_BINARY_SUBDIR} )
+ add_executable( ozDDS ozDDS.cc )
+ target_link_libraries( ozDDS ozFactory )
+
+ install( TARGETS ozDDS RUNTIME DESTINATION bin${OZ_BINARY_SUBDIR} )
+
add_executable( ozGettext ozGettext.cc )
target_link_libraries( ozGettext ozCore )
View
1 src/tools/openzone.cc
@@ -24,7 +24,6 @@
#include <stable.hh>
#include <client/openzone.hh>
-#include <ozEngine/Pepper.hh>
#include <client/Client.hh>
#include <SDL.h>
View
84 src/tools/ozDDS.cc
@@ -0,0 +1,84 @@
+/*
+ * img2dds - DDS image builder.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+#include <ozFactory/ozFactory.hh>
+
+#include <cstdio>
+#include <cstdlib>
+#include <getopt.h>
+
+using namespace oz;
+
+static void usage()
+{
+ Log::printRaw(
+ "Usage: img2dds [-c] [-m] [-q] <inputImage> <outputDDS>\n"
+ "\t-c\tUse S3 texture compression\n"
+ "\t-m\tGenerate mipmaps\n"
+ "\t-q\tUse top quality for texture compression and mipmap scaling.\n"
+ );
+}
+
+int main( int argc, char** argv )
+{
+ System::init();
+
+ int ddsOptions = 0;
+
+ int opt;
+ while( ( opt = getopt( argc, argv, "cmq" ) ) >= 0 ) {
+ switch( opt ) {
+ case 'c': {
+ ddsOptions |= Builder::COMPRESSION_BIT;
+ break;
+ }
+ case 'm': {
+ ddsOptions |= Builder::MIPMAPS_BIT;
+ break;
+ }
+ case 'q': {
+ ddsOptions |= Builder::QUALITY_BIT;
+ break;
+ }
+ default: {
+ usage();
+ return EXIT_FAILURE;
+ }
+ }
+ }
+
+ if( argc - optind != 2 ) {
+ usage();
+ return EXIT_FAILURE;
+ }
+
+ OutputStream ostream( 0 );
+ if( !Builder::buildDDS( argv[optind], ddsOptions, &ostream ) ) {
+ return EXIT_FAILURE;
+ }
+
+ if( !File( argv[optind + 1] ).write( ostream.begin(), ostream.tell() ) ) {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}

0 comments on commit 113b6d4

Please sign in to comment.
Something went wrong with that request. Please try again.