mirror of
https://github.com/glest/glest-source.git
synced 2025-08-24 17:02:49 +02:00
initial version ( megaglest 3.2.3-beta3 )
This commit is contained in:
61
source/shared_lib/include/graphics/buffer.h
Normal file
61
source/shared_lib/include/graphics/buffer.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef _SHARED_GRAPHICS_BUFFER_H_
|
||||
#define _SHARED_GRAPHICS_BUFFER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class VertexBuffer
|
||||
// =====================================================
|
||||
|
||||
class VertexBuffer{
|
||||
private:
|
||||
static const int texCoordCount = 8;
|
||||
static const int attribCount = 8;
|
||||
|
||||
private:
|
||||
void *positionPointer;
|
||||
void *normalPointer;
|
||||
|
||||
void *texCoordPointers[texCoordCount];
|
||||
int texCoordCoordCounts[texCoordCount];
|
||||
|
||||
void *attribPointers[attribCount];
|
||||
int attribCoordCounts[attribCount];
|
||||
string attribNames[attribCount];
|
||||
|
||||
public:
|
||||
VertexBuffer();
|
||||
virtual ~VertexBuffer(){};
|
||||
|
||||
virtual void init(int size)= 0;
|
||||
|
||||
void setPositionPointer(void *pointer);
|
||||
void setNormalPointer(void *pointer);
|
||||
void setTexCoordPointer(void *pointer, int texCoordIndex, int coordCount);
|
||||
void setAttribPointer(void *pointer, int attribIndex, int coordCount, const string &name);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class IndexBuffer
|
||||
// =====================================================
|
||||
|
||||
class IndexBuffer{
|
||||
private:
|
||||
void *indexPointer;
|
||||
|
||||
public:
|
||||
IndexBuffer();
|
||||
virtual ~IndexBuffer(){}
|
||||
|
||||
virtual void init(int size)= 0;
|
||||
|
||||
void setIndexPointer(void *pointer);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
48
source/shared_lib/include/graphics/camera.h
Normal file
48
source/shared_lib/include/graphics/camera.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_CAMERA_H_
|
||||
#define _SHARED_GRAPHICS_CAMERA_H_
|
||||
|
||||
#include "vec.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class Camera
|
||||
// =====================================================
|
||||
|
||||
class Camera{
|
||||
private:
|
||||
Quaternion orientation;
|
||||
Vec3f position;
|
||||
public:
|
||||
Camera();
|
||||
|
||||
Vec3f getPosition() const {return position;}
|
||||
Quaternion getOrientation() const {return orientation;}
|
||||
|
||||
void setPosition(const Vec3f &position) {this->position= position;}
|
||||
void setOrientation(const Quaternion &orientation) {this->orientation= orientation;}
|
||||
|
||||
void moveLocalX(float amount);
|
||||
void moveLocalY(float amount);
|
||||
void moveLocalZ(float amount);
|
||||
|
||||
void addYaw(float amount);
|
||||
void addPitch(float amount);
|
||||
void addRoll(float amount);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
53
source/shared_lib/include/graphics/context.h
Normal file
53
source/shared_lib/include/graphics/context.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_CONTEXT_H_
|
||||
#define _SHARED_GRAPHICS_CONTEXT_H_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
using Platform::uint32;
|
||||
|
||||
// =====================================================
|
||||
// class Context
|
||||
// =====================================================
|
||||
|
||||
class Context{
|
||||
protected:
|
||||
uint32 colorBits;
|
||||
uint32 depthBits;
|
||||
uint32 stencilBits;
|
||||
|
||||
public:
|
||||
Context();
|
||||
virtual ~Context(){}
|
||||
|
||||
uint32 getColorBits() const {return colorBits;}
|
||||
uint32 getDepthBits() const {return depthBits;}
|
||||
uint32 getStencilBits() const {return stencilBits;}
|
||||
|
||||
void setColorBits(uint32 colorBits) {this->colorBits= colorBits;}
|
||||
void setDepthBits(uint32 depthBits) {this->depthBits= depthBits;}
|
||||
void setStencilBits(uint32 stencilBits) {this->stencilBits= stencilBits;}
|
||||
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
virtual void reset()= 0;
|
||||
|
||||
virtual void makeCurrent()= 0;
|
||||
virtual void swapBuffers()= 0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
48
source/shared_lib/include/graphics/d3d9/context_d3d9.h
Normal file
48
source/shared_lib/include/graphics/d3d9/context_d3d9.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef _SHARED_D3D9_DEVICECONTEXTD3D9_H_
|
||||
#define _SHARED_D3D9_DEVICECONTEXTD3D9_H_
|
||||
|
||||
#include "context.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class ContextD3d9
|
||||
// ===============================
|
||||
|
||||
class ContextD3d9: public Context{
|
||||
private:
|
||||
bool windowed;
|
||||
bool hardware;
|
||||
|
||||
IDirect3D9 *d3dObject;
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
D3DCAPS9 caps;
|
||||
D3DPRESENT_PARAMETERS d3dPresentParameters;
|
||||
|
||||
public:
|
||||
bool getWindowed() const {return windowed;}
|
||||
bool getHardware() const {return hardware;}
|
||||
|
||||
void setWindowed(bool windowed) {this->windowed= windowed;}
|
||||
void setHardware(bool hardware) {this->hardware= hardware;}
|
||||
|
||||
ContextD3d9();
|
||||
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
virtual void reset();
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
const D3DCAPS9 *getCaps() const {return ∩︀};
|
||||
|
||||
|
||||
IDirect3DDevice9 *getD3dDevice() {return d3dDevice;}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
26
source/shared_lib/include/graphics/d3d9/d3d9_util.h
Normal file
26
source/shared_lib/include/graphics/d3d9/d3d9_util.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _SHARED_D3D9_D3D9UTIL_H_
|
||||
#define _SHARED_D3D9_D3D9UTIL_H_
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#define D3DCALL(X) checkResult(X, #X);
|
||||
|
||||
using std::string;
|
||||
using std::runtime_error;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
string d3dErrorToStr(HRESULT result);
|
||||
|
||||
inline void checkResult(HRESULT result, const string &functionCall){
|
||||
if(result!=D3D_OK){
|
||||
throw runtime_error("Direct3D Error\nCode: " + d3dErrorToStr(result) + "\nFunction: " + functionCall);
|
||||
}
|
||||
}
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
26
source/shared_lib/include/graphics/d3d9/font_d3d9.h
Normal file
26
source/shared_lib/include/graphics/d3d9/font_d3d9.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _SHARED_D3D9_FONTD3D9_H_
|
||||
#define _SHARED_D3D9_FONTD3D9_H_
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#include <d3dx9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class FontD3d9
|
||||
// ===============================
|
||||
|
||||
class Font2DD3d9: public Font2D{
|
||||
private:
|
||||
LPD3DXFONT d3dFont;
|
||||
|
||||
public:
|
||||
LPD3DXFONT getD3dFont() const {return d3dFont;}
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,33 @@
|
||||
#ifndef _SHARED_D3D9_GRAPHICSFACTORYD3D9_H_
|
||||
#define _SHARED_D3D9_GRAPHICSFACTORYD3D9_H_
|
||||
|
||||
#include "context_d3d9.h"
|
||||
#include "model_renderer_d3d9.h"
|
||||
#include "texture_d3d9.h"
|
||||
#include "font_d3d9.h"
|
||||
#include "text_renderer_d3d9.h"
|
||||
#include "shader_d3d9.h"
|
||||
#include "graphics_factory.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class GraphicsFactoryD3d9
|
||||
// ===============================
|
||||
|
||||
class GraphicsFactoryD3d9: public GraphicsFactory{
|
||||
public:
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DD3d9();}
|
||||
virtual ModelRenderer *newModelRenderer() {return NULL;}
|
||||
virtual Context *newContext() {return new ContextD3d9();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DD3d9();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeD3d9();}
|
||||
virtual Font2D *newFont2D() {return new Font2DD3d9();}
|
||||
virtual ShaderProgram *newShaderProgram() {return new ShaderProgramD3d9();}
|
||||
virtual VertexShader *newVertexShader() {return new VertexShaderD3d9();}
|
||||
virtual FragmentShader *newFragmentShader() {return new PixelShaderD3d9();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,53 @@
|
||||
#ifndef _SHARED_D3D9_MODELRENDERERD3D9_H_
|
||||
#define _SHARED_D3D9_MODELRENDERERD3D9_H_
|
||||
|
||||
#include "model_renderer.h"
|
||||
#include "model.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class ModelRendererD3d9
|
||||
// ===============================
|
||||
|
||||
class ModelRendererD3d9: public ModelRenderer{
|
||||
private:
|
||||
static const int defBufferPointCount= 100; //buffer size in vertices
|
||||
static const int defBufferIndexCount= 100; //buffer size in vertices
|
||||
|
||||
struct CustomVertexPNTT{
|
||||
Vec3f vertex;
|
||||
Vec3f normal;
|
||||
Vec2f texCoord;
|
||||
Vec3f tangent;
|
||||
};
|
||||
|
||||
private:
|
||||
bool rendering;
|
||||
int bufferPointCount;
|
||||
int bufferIndexCount;
|
||||
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
IDirect3DVertexBuffer9 *d3dVertexBuffer;
|
||||
IDirect3DIndexBuffer9 *d3dIndexBuffer;
|
||||
IDirect3DVertexDeclaration9 *d3dVertexDeclarationPNT;
|
||||
IDirect3DVertexDeclaration9 *d3dVertexDeclarationPNTT;
|
||||
|
||||
public:
|
||||
ModelRendererD3d9();
|
||||
~ModelRendererD3d9();
|
||||
virtual void begin(bool renderNormals= true, bool renderTextures= true, bool renderColors= true);
|
||||
virtual void end();
|
||||
virtual void render(const Model *model);
|
||||
virtual void renderNormalsOnly(const Model *model);
|
||||
|
||||
private:
|
||||
void renderMesh(const Mesh *mesh);
|
||||
void readyBuffers(int newPointCount, int newIndexCount);
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
109
source/shared_lib/include/graphics/d3d9/shader_d3d9.h
Normal file
109
source/shared_lib/include/graphics/d3d9/shader_d3d9.h
Normal file
@@ -0,0 +1,109 @@
|
||||
#ifndef _SHARED_D3D9_SHADERD3D9_H_
|
||||
#define _SHARED_D3D9_SHADERD3D9_H_
|
||||
|
||||
#include "shader.h"
|
||||
#include "vec.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9shader.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class ShaderProgramD3d9
|
||||
// ===============================
|
||||
|
||||
class VertexShaderD3d9;
|
||||
class PixelShaderD3d9;
|
||||
|
||||
class ShaderProgramD3d9: public virtual ShaderProgram{
|
||||
protected:
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
ID3DXConstantTable *d3dVsConstantTable;
|
||||
ID3DXConstantTable *d3dPsConstantTable;
|
||||
|
||||
VertexShaderD3d9 *vertexShader;
|
||||
PixelShaderD3d9 *pixelShader;
|
||||
|
||||
public:
|
||||
ShaderProgramD3d9();
|
||||
|
||||
virtual void init(){};
|
||||
virtual void end(){};
|
||||
|
||||
virtual void attach(VertexShader *vs, FragmentShader *fs);
|
||||
virtual void activate();
|
||||
|
||||
virtual bool link(string &messages);
|
||||
|
||||
virtual void setUniform(const string &name, int value);
|
||||
virtual void setUniform(const string &name, float value);
|
||||
virtual void setUniform(const string &name, const Vec2f &value);
|
||||
virtual void setUniform(const string &name, const Vec3f &value);
|
||||
virtual void setUniform(const string &name, const Vec4f &value);
|
||||
virtual void setUniform(const string &name, const Matrix3f &value);
|
||||
virtual void setUniform(const string &name, const Matrix4f &value);
|
||||
//virtual void setUniform(const string &name, const Texture *value);
|
||||
};
|
||||
|
||||
|
||||
// ===============================
|
||||
// class ShaderD3d9
|
||||
// ===============================
|
||||
|
||||
class ShaderD3d9: virtual public Shader{
|
||||
protected:
|
||||
ShaderSource source;
|
||||
string target;
|
||||
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
ID3DXConstantTable *d3dConstantTable;
|
||||
|
||||
public:
|
||||
ShaderD3d9();
|
||||
virtual void init(){};
|
||||
virtual void end();
|
||||
virtual void load(const string &path);
|
||||
|
||||
ID3DXConstantTable *getD3dConstantTable() const {return d3dConstantTable;}
|
||||
|
||||
void setTarget(const string &target) {this->target= target;}
|
||||
};
|
||||
|
||||
// ===============================
|
||||
// class VertexShaderD3d9
|
||||
// ===============================
|
||||
|
||||
class VertexShaderD3d9: public ShaderD3d9, public VertexShader{
|
||||
private:
|
||||
IDirect3DVertexShader9 *d3dVertexShader;
|
||||
|
||||
public:
|
||||
VertexShaderD3d9();
|
||||
virtual void end();
|
||||
|
||||
virtual bool compile(string &messages);
|
||||
|
||||
IDirect3DVertexShader9 *getD3dVertexShader() const {return d3dVertexShader;}
|
||||
};
|
||||
|
||||
// ===============================
|
||||
// class PixelShaderD3d9
|
||||
// ===============================
|
||||
|
||||
class PixelShaderD3d9: public ShaderD3d9, public FragmentShader{
|
||||
private:
|
||||
IDirect3DPixelShader9 *d3dPixelShader;
|
||||
|
||||
public:
|
||||
PixelShaderD3d9();
|
||||
virtual void end();
|
||||
|
||||
virtual bool compile(string &messages);
|
||||
|
||||
IDirect3DPixelShader9 *getD3dPixelShader() const {return d3dPixelShader;}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
25
source/shared_lib/include/graphics/d3d9/text_renderer_d3d9.h
Normal file
25
source/shared_lib/include/graphics/d3d9/text_renderer_d3d9.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef _SHARED_D3D9_TEXTRENDERERD3D9_H_
|
||||
#define _SHARED_D3D9_TEXTRENDERERD3D9_H_
|
||||
|
||||
#include "text_renderer.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class TextRenderer2DD3d9
|
||||
// ===============================
|
||||
|
||||
class TextRenderer2DD3d9: public TextRenderer2D{
|
||||
private:
|
||||
const Font *font;
|
||||
Vec4f color;
|
||||
|
||||
public:
|
||||
virtual void begin(const Font2D *font);
|
||||
virtual void render(const string &text, int x, int y, bool centered= false);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
41
source/shared_lib/include/graphics/d3d9/texture_d3d9.h
Normal file
41
source/shared_lib/include/graphics/d3d9/texture_d3d9.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _SHARED_D3D9_TEXTURED3D9_H_
|
||||
#define _SHARED_D3D9_TEXTURED3D9_H_
|
||||
|
||||
#include "texture.h"
|
||||
#include <d3d9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class Texture2DD3d9
|
||||
// ===============================
|
||||
|
||||
class Texture2DD3d9: public Texture2D{
|
||||
private:
|
||||
IDirect3DTexture9 *d3dTexture;
|
||||
|
||||
public:
|
||||
IDirect3DTexture9 *getD3dTexture() const {return d3dTexture;}
|
||||
|
||||
virtual void init(Filter textureFilter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// ===============================
|
||||
// class TextureCubeD3d9
|
||||
// ===============================
|
||||
|
||||
class TextureCubeD3d9: public TextureCube{
|
||||
private:
|
||||
IDirect3DCubeTexture9 *d3dCubeTexture;
|
||||
|
||||
public:
|
||||
IDirect3DCubeTexture9 *getD3dCubeTexture() const {return d3dCubeTexture;}
|
||||
|
||||
virtual void init(Filter textureFilter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
110
source/shared_lib/include/graphics/font.h
Normal file
110
source/shared_lib/include/graphics/font.h
Normal file
@@ -0,0 +1,110 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_FONT_H_
|
||||
#define _SHARED_GRAPHICS_FONT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class FontMetrics
|
||||
// =====================================================
|
||||
|
||||
class FontMetrics{
|
||||
private:
|
||||
float *widths;
|
||||
float height;
|
||||
|
||||
public:
|
||||
FontMetrics();
|
||||
~FontMetrics();
|
||||
|
||||
void setWidth(int i, float width) {widths[i]= width;}
|
||||
void setHeight(float height) {this->height= height;}
|
||||
|
||||
float getTextWidth(const string &str) const;
|
||||
float getHeight() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font
|
||||
// =====================================================
|
||||
|
||||
class Font{
|
||||
public:
|
||||
static const int charCount;
|
||||
|
||||
public:
|
||||
enum Width{
|
||||
wNormal= 400,
|
||||
wBold= 700
|
||||
};
|
||||
|
||||
protected:
|
||||
string type;
|
||||
int width;
|
||||
bool inited;
|
||||
FontMetrics metrics;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Font();
|
||||
virtual ~Font(){};
|
||||
virtual void init()=0;
|
||||
virtual void end()=0;
|
||||
|
||||
//get
|
||||
string getType() const {return type;}
|
||||
int getWidth() const {return width;}
|
||||
const FontMetrics *getMetrics() const {return &metrics;}
|
||||
|
||||
//set
|
||||
void setType(string type) {this->type= type;}
|
||||
void setWidth(int width) {this->width= width;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font2D
|
||||
// =====================================================
|
||||
|
||||
class Font2D: public Font{
|
||||
protected:
|
||||
int size;
|
||||
|
||||
public:
|
||||
Font2D();
|
||||
|
||||
int getSize() const {return size;}
|
||||
void setSize(int size) {this->size= size;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font3D
|
||||
// =====================================================
|
||||
|
||||
class Font3D: public Font{
|
||||
protected:
|
||||
float depth;
|
||||
|
||||
public:
|
||||
Font3D();
|
||||
|
||||
float getDepth() const {return depth;}
|
||||
void setDepth(float depth) {this->depth= depth;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
48
source/shared_lib/include/graphics/font_manager.h
Normal file
48
source/shared_lib/include/graphics/font_manager.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_FONTMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_FONTMANAGER_H_
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class FontManager
|
||||
//
|
||||
/// Creates, Intializes, Finalizes, and Deletes fonts
|
||||
// =====================================================
|
||||
|
||||
class FontManager{
|
||||
protected:
|
||||
typedef vector<Font*> FontContainer;
|
||||
|
||||
protected:
|
||||
FontContainer fonts;
|
||||
|
||||
public:
|
||||
virtual ~FontManager();
|
||||
|
||||
Font2D *newFont2D();
|
||||
Font3D *newFont3D();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
43
source/shared_lib/include/graphics/gl/context_gl.h
Normal file
43
source/shared_lib/include/graphics/gl/context_gl.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_CONTEXTGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_CONTEXTGL_H_
|
||||
|
||||
#include "context.h"
|
||||
#include "gl_wrap.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
using Platform::PlatformContextGl;
|
||||
|
||||
// =====================================================
|
||||
// class ContextGl
|
||||
// =====================================================
|
||||
|
||||
class ContextGl: public Context{
|
||||
protected:
|
||||
PlatformContextGl pcgl;
|
||||
|
||||
public:
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
virtual void reset(){};
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
const PlatformContextGl *getPlatformContextGl() const {return &pcgl;}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
58
source/shared_lib/include/graphics/gl/font_gl.h
Normal file
58
source/shared_lib/include/graphics/gl/font_gl.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_FONTGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_FONTGL_H_
|
||||
|
||||
#include "font.h"
|
||||
#include "opengl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class FontGl
|
||||
// =====================================================
|
||||
|
||||
class FontGl{
|
||||
protected:
|
||||
GLuint handle;
|
||||
|
||||
public:
|
||||
GLuint getHandle() const {return handle;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font2DGl
|
||||
//
|
||||
/// OpenGL bitmap font
|
||||
// =====================================================
|
||||
|
||||
class Font2DGl: public Font2D, public FontGl{
|
||||
public:
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font3DGl
|
||||
//
|
||||
/// OpenGL outline font
|
||||
// =====================================================
|
||||
|
||||
class Font3DGl: public Font3D, public FontGl{
|
||||
public:
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,43 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYBASICGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYBASICGL_H_
|
||||
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryBasicGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryBasicGl: public GraphicsFactory{
|
||||
public:
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
65
source/shared_lib/include/graphics/gl/graphics_factory_gl.h
Normal file
65
source/shared_lib/include/graphics/gl/graphics_factory_gl.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL_H_
|
||||
|
||||
#include "texture_manager.h"
|
||||
#include "model_manager.h"
|
||||
#include "particle.h"
|
||||
#include "font_manager.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "particle_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryGl: public GraphicsFactory{
|
||||
public:
|
||||
//context
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return new TextureManager();}
|
||||
virtual Texture1D *newTexture1D() {return new Texture1DGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Texture3D *newTexture3D() {return new Texture3DGl();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeGl();}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return new ModelManager();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return new FontManager();}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return new ParticleManager();}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return new ParticleRendererGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
62
source/shared_lib/include/graphics/gl/graphics_factory_gl2.h
Normal file
62
source/shared_lib/include/graphics/gl/graphics_factory_gl2.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
|
||||
#include "texture_manager.h"
|
||||
#include "model_manager.h"
|
||||
#include "font_manager.h"
|
||||
#include "particle.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "particle_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
#include "shader_gl.h"
|
||||
#include "shader_manager.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryGl2: public GraphicsFactory{
|
||||
public:
|
||||
//context
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return new TextureManager();}
|
||||
virtual Texture1D *newTexture1D() {return new Texture1DGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Texture3D *newTexture3D() {return new Texture3DGl();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeGl();}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return new ModelManager();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return new FontManager();}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return new ParticleManager();}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return new ParticleRendererGl();}
|
||||
|
||||
//shaders
|
||||
virtual ShaderManager *newShaderManager() {return new ShaderManager();}
|
||||
virtual ShaderProgram *newShaderProgram() {return new ShaderProgramGl();}
|
||||
virtual VertexShader *newVertexShader() {return new VertexShaderGl();}
|
||||
virtual FragmentShader *newFragmentShader() {return new FragmentShaderGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
31
source/shared_lib/include/graphics/gl/model_gl.h
Normal file
31
source/shared_lib/include/graphics/gl/model_gl.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_MODELGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_MODELGL_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ModelGl
|
||||
// =====================================================
|
||||
|
||||
class ModelGl: public Model{
|
||||
public:
|
||||
virtual void init(){}
|
||||
virtual void end(){}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
50
source/shared_lib/include/graphics/gl/model_renderer_gl.h
Normal file
50
source/shared_lib/include/graphics/gl/model_renderer_gl.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_MODELRENDERERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_MODELRENDERERGL_H_
|
||||
|
||||
#include "model_renderer.h"
|
||||
#include "model.h"
|
||||
#include "opengl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ModelRendererGl
|
||||
// =====================================================
|
||||
|
||||
class ModelRendererGl: public ModelRenderer{
|
||||
private:
|
||||
bool rendering;
|
||||
bool duplicateTexCoords;
|
||||
int secondaryTexCoordUnit;
|
||||
GLuint lastTexture;
|
||||
|
||||
public:
|
||||
ModelRendererGl();
|
||||
virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback);
|
||||
virtual void end();
|
||||
virtual void render(const Model *model);
|
||||
virtual void renderNormalsOnly(const Model *model);
|
||||
|
||||
void setDuplicateTexCoords(bool duplicateTexCoords) {this->duplicateTexCoords= duplicateTexCoords;}
|
||||
void setSecondaryTexCoordUnit(int secondaryTexCoordUnit) {this->secondaryTexCoordUnit= secondaryTexCoordUnit;}
|
||||
|
||||
private:
|
||||
|
||||
void renderMesh(const Mesh *mesh);
|
||||
void renderMeshNormals(const Mesh *mesh);
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
69
source/shared_lib/include/graphics/gl/opengl.h
Normal file
69
source/shared_lib/include/graphics/gl/opengl.h
Normal file
@@ -0,0 +1,69 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_OPENGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_OPENGL_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "conversion.h"
|
||||
#include "gl_wrap.h"
|
||||
|
||||
using std::runtime_error;
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
using Util::intToStr;
|
||||
|
||||
// =====================================================
|
||||
// Globals
|
||||
// =====================================================
|
||||
|
||||
bool isGlExtensionSupported(const char *extensionName);
|
||||
bool isGlVersionSupported(int major, int minor, int release);
|
||||
const char *getGlVersion();
|
||||
const char *getGlRenderer();
|
||||
const char *getGlVendor();
|
||||
const char *getGlExtensions();
|
||||
const char *getGlPlatformExtensions();
|
||||
int getGlMaxLights();
|
||||
int getGlMaxTextureSize();
|
||||
int getGlMaxTextureUnits();
|
||||
int getGlModelviewMatrixStackDepth();
|
||||
int getGlProjectionMatrixStackDepth();
|
||||
void checkGlExtension(const char *extensionName);
|
||||
|
||||
void inline _assertGl(const char *file, int line){
|
||||
|
||||
GLenum error= glGetError();
|
||||
|
||||
if(error != GL_NO_ERROR){
|
||||
const char *errorString= reinterpret_cast<const char*>(gluErrorString(error));
|
||||
throw runtime_error("OpenGL error: "+string(errorString)+" at file: "+string(file)+", line "+intToStr(line));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assertGl() ((void) 0);
|
||||
|
||||
#else
|
||||
|
||||
#define assertGl() _assertGl(__FILE__, __LINE__);
|
||||
|
||||
#endif
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
50
source/shared_lib/include/graphics/gl/particle_renderer_gl.h
Normal file
50
source/shared_lib/include/graphics/gl/particle_renderer_gl.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_PARTICLERENDERERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_PARTICLERENDERERGL_H_
|
||||
|
||||
#include "particle_renderer.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ParticleRendererGl
|
||||
// =====================================================
|
||||
|
||||
class ParticleRendererGl: public ParticleRenderer{
|
||||
public:
|
||||
static const int bufferSize = 1024;
|
||||
|
||||
private:
|
||||
bool rendering;
|
||||
Vec3f vertexBuffer[bufferSize];
|
||||
Vec2f texCoordBuffer[bufferSize];
|
||||
Vec4f colorBuffer[bufferSize];
|
||||
|
||||
public:
|
||||
//particles
|
||||
ParticleRendererGl();
|
||||
virtual void renderManager(ParticleManager *pm, ModelRenderer *mr);
|
||||
virtual void renderSystem(ParticleSystem *ps);
|
||||
virtual void renderSystemLine(ParticleSystem *ps);
|
||||
virtual void renderSystemLineAlpha(ParticleSystem *ps);
|
||||
virtual void renderSingleModel(AttackParticleSystem *ps, ModelRenderer *mr);
|
||||
|
||||
protected:
|
||||
void renderBufferQuads(int quadCount);
|
||||
void renderBufferLines(int lineCount);
|
||||
void setBlendMode(ParticleSystem::BlendMode blendMode);
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
111
source/shared_lib/include/graphics/gl/shader_gl.h
Normal file
111
source/shared_lib/include/graphics/gl/shader_gl.h
Normal file
@@ -0,0 +1,111 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "shader.h"
|
||||
#include "opengl.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderProgramGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderProgramGl: public ShaderProgram{
|
||||
private:
|
||||
typedef pair<string, int> AttributePair;
|
||||
typedef vector<AttributePair> Attributes;
|
||||
|
||||
private:
|
||||
Attributes attributes;
|
||||
GLhandleARB handle;
|
||||
VertexShader *vertexShader;
|
||||
FragmentShader *fragmentShader;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderProgramGl();
|
||||
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
|
||||
virtual void attach(VertexShader *vertexShader, FragmentShader *fragmentShader);
|
||||
virtual bool link(string &messages);
|
||||
virtual void activate();
|
||||
virtual void deactivate();
|
||||
|
||||
virtual void setUniform(const string &name, int value);
|
||||
virtual void setUniform(const string &name, float value);
|
||||
virtual void setUniform(const string &name, const Vec2f &value);
|
||||
virtual void setUniform(const string &name, const Vec3f &value);
|
||||
virtual void setUniform(const string &name, const Vec4f &value);
|
||||
virtual void setUniform(const string &name, const Matrix3f &value);
|
||||
virtual void setUniform(const string &name, const Matrix4f &value);
|
||||
|
||||
void bindAttribute(const string &name, int index);
|
||||
|
||||
private:
|
||||
GLint getLocation(const string &name);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ShaderGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderGl: virtual public Shader{
|
||||
protected:
|
||||
GLhandleARB handle;
|
||||
ShaderSource source;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderGl();
|
||||
|
||||
const ShaderSource *getSource() const {return &source;}
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void load(const string &path);
|
||||
virtual bool compile(string &messages);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class VertexShaderGl
|
||||
// =====================================================
|
||||
|
||||
class VertexShaderGl: public VertexShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FragmentShaderGl
|
||||
// =====================================================
|
||||
|
||||
class FragmentShaderGl: public FragmentShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
58
source/shared_lib/include/graphics/gl/text_renderer_gl.h
Normal file
58
source/shared_lib/include/graphics/gl/text_renderer_gl.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_TEXTRENDERERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_TEXTRENDERERGL_H_
|
||||
|
||||
#include "text_renderer.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
class Font2DGl;
|
||||
class Font3DGl;
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer2DGl
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer2DGl: public TextRenderer2D{
|
||||
private:
|
||||
const Font2DGl *font;
|
||||
bool rendering;
|
||||
|
||||
public:
|
||||
TextRenderer2DGl();
|
||||
|
||||
virtual void begin(const Font2D *font);
|
||||
virtual void render(const string &text, int x, int y, bool centered);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer3DGl
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer3DGl: public TextRenderer3D{
|
||||
private:
|
||||
const Font3DGl *font;
|
||||
bool rendering;
|
||||
|
||||
public:
|
||||
TextRenderer3DGl();
|
||||
|
||||
virtual void begin(const Font3D *font);
|
||||
virtual void render(const string &text, float x, float y, float size, bool centered);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
74
source/shared_lib/include/graphics/gl/texture_gl.h
Normal file
74
source/shared_lib/include/graphics/gl/texture_gl.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_TEXTUREGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_TEXTUREGL_H_
|
||||
|
||||
#include "texture.h"
|
||||
#include "opengl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class TextureGl
|
||||
// =====================================================
|
||||
|
||||
class TextureGl{
|
||||
protected:
|
||||
GLuint handle;
|
||||
|
||||
public:
|
||||
GLuint getHandle() const {return handle;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture1DGl
|
||||
// =====================================================
|
||||
|
||||
class Texture1DGl: public Texture1D, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture2DGl
|
||||
// =====================================================
|
||||
|
||||
class Texture2DGl: public Texture2D, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture3DGl
|
||||
// =====================================================
|
||||
|
||||
class Texture3DGl: public Texture3D, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextureCubeGl
|
||||
// =====================================================
|
||||
|
||||
class TextureCubeGl: public TextureCube, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,61 @@
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
|
||||
#include "texture_manager.h"
|
||||
#include "model_manager.h"
|
||||
#include "particle_manager.h"
|
||||
#include "font_manager.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "particle_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
#include "shader_gl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryGl: public GraphicsFactory{
|
||||
public:
|
||||
//context
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return new TextureManager();}
|
||||
virtual Texture1D *newTexture1D() {return new Texture1DGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Texture3D *newTexture3D() {return new Texture3DGl();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeGl();}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return new ModelManager();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return new FontManager();}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return new ParticleManager();}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return new ParticleRendererGl();}
|
||||
|
||||
//shaders
|
||||
virtual Shadermanager *newShadermanager() {return new ShaderManager();}
|
||||
virtual ShaderProgram *newShaderProgram() {return new ShaderProgramGl();}
|
||||
virtual VertexShader *newVertexShader() {return new VertexShaderGl();}
|
||||
virtual FragmentShader *newFragmentShader() {return new FragmentShaderGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
110
source/shared_lib/include/graphics/gl2/shader_gl.h
Normal file
110
source/shared_lib/include/graphics/gl2/shader_gl.h
Normal file
@@ -0,0 +1,110 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "shader.h"
|
||||
#include "opengl.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderProgramGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderProgramGl: public ShaderProgram{
|
||||
private:
|
||||
typedef pair<string, int> AttributePair;
|
||||
typedef vector<AttributePair> Attributes;
|
||||
|
||||
private:
|
||||
Attributes attributes;
|
||||
GLhandleARB handle;
|
||||
VertexShader *vertexShader;
|
||||
FragmentShader *fragmentShader;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderProgramGl();
|
||||
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
|
||||
virtual void attach(VertexShader *vertexShader, FragmentShader *fragmentShader);
|
||||
virtual bool link(string &messages);
|
||||
virtual void activate();
|
||||
|
||||
virtual void setUniform(const string &name, int value);
|
||||
virtual void setUniform(const string &name, float value);
|
||||
virtual void setUniform(const string &name, const Vec2f &value);
|
||||
virtual void setUniform(const string &name, const Vec3f &value);
|
||||
virtual void setUniform(const string &name, const Vec4f &value);
|
||||
virtual void setUniform(const string &name, const Matrix3f &value);
|
||||
virtual void setUniform(const string &name, const Matrix4f &value);
|
||||
|
||||
void bindAttribute(const string &name, int index);
|
||||
|
||||
private:
|
||||
GLint getLocation(const string &name);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ShaderGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderGl: virtual public Shader{
|
||||
protected:
|
||||
GLhandleARB handle;
|
||||
ShaderSource source;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderGl();
|
||||
|
||||
const ShaderSource *getSource() const {return &source;}
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void load(const string &path);
|
||||
virtual bool compile(string &messages);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class VertexShaderGl
|
||||
// =====================================================
|
||||
|
||||
class VertexShaderGl: public VertexShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FragmentShaderGl
|
||||
// =====================================================
|
||||
|
||||
class FragmentShaderGl: public FragmentShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
88
source/shared_lib/include/graphics/graphics_factory.h
Normal file
88
source/shared_lib/include/graphics/graphics_factory.h
Normal file
@@ -0,0 +1,88 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GRAPHICSFACTORY_H_
|
||||
#define _SHARED_GRAPHICS_GRAPHICSFACTORY_H_
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class Context;
|
||||
|
||||
class TextureManager;
|
||||
class Texture1D;
|
||||
class Texture2D;
|
||||
class Texture3D;
|
||||
class TextureCube;
|
||||
|
||||
class ModelManager;
|
||||
class ModelRenderer;
|
||||
class Model;
|
||||
|
||||
class FontManager;
|
||||
class TextRenderer2D;
|
||||
class TextRenderer3D;
|
||||
class Font2D;
|
||||
class Font3D;
|
||||
|
||||
class ParticleManager;
|
||||
class ParticleRenderer;
|
||||
|
||||
class ShaderManager;
|
||||
class ShaderProgram;
|
||||
class VertexShader;
|
||||
class FragmentShader;
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactory
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactory{
|
||||
public:
|
||||
virtual ~GraphicsFactory(){}
|
||||
|
||||
//context
|
||||
virtual Context *newContext() {return NULL;}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return NULL;}
|
||||
virtual Texture1D *newTexture1D() {return NULL;}
|
||||
virtual Texture2D *newTexture2D() {return NULL;}
|
||||
virtual Texture3D *newTexture3D() {return NULL;}
|
||||
virtual TextureCube *newTextureCube() {return NULL;}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return NULL;}
|
||||
virtual ModelRenderer *newModelRenderer() {return NULL;}
|
||||
virtual Model *newModel() {return NULL;}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return NULL;}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return NULL;}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return NULL;}
|
||||
virtual Font2D *newFont2D() {return NULL;}
|
||||
virtual Font3D *newFont3D() {return NULL;}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return NULL;}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return NULL;}
|
||||
|
||||
//shaders
|
||||
virtual ShaderManager *newShaderManager() {return NULL;}
|
||||
virtual ShaderProgram *newShaderProgram() {return NULL;}
|
||||
virtual VertexShader *newVertexShader() {return NULL;}
|
||||
virtual FragmentShader *newFragmentShader() {return NULL;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
52
source/shared_lib/include/graphics/graphics_interface.h
Normal file
52
source/shared_lib/include/graphics/graphics_interface.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
|
||||
#define _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class GraphicsFactory;
|
||||
class Context;
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsInterface
|
||||
//
|
||||
/// Interface for the graphic engine
|
||||
// =====================================================
|
||||
|
||||
class GraphicsInterface{
|
||||
private:
|
||||
GraphicsFactory *graphicsFactory;
|
||||
Context *currentContext;
|
||||
|
||||
private:
|
||||
friend class TextureManager;
|
||||
friend class FontManager;
|
||||
|
||||
private:
|
||||
GraphicsInterface();
|
||||
GraphicsInterface(GraphicsInterface &);
|
||||
void operator=(GraphicsInterface &);
|
||||
|
||||
public:
|
||||
static GraphicsInterface &getInstance();
|
||||
|
||||
void setFactory(GraphicsFactory *graphicsFactory);
|
||||
void setCurrentContext(Context *context);
|
||||
|
||||
Context *getCurrentContext() const {return currentContext;}
|
||||
GraphicsFactory *getFactory() const {return graphicsFactory;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
45
source/shared_lib/include/graphics/interpolation.h
Normal file
45
source/shared_lib/include/graphics/interpolation.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_INTERPOLATION_H_
|
||||
#define _SHARED_GRAPHICS_INTERPOLATION_H_
|
||||
|
||||
#include "vec.h"
|
||||
#include "model.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class InterpolationData
|
||||
// =====================================================
|
||||
|
||||
class InterpolationData{
|
||||
private:
|
||||
const Mesh *mesh;
|
||||
|
||||
Vec3f *vertices;
|
||||
Vec3f *normals;
|
||||
|
||||
public:
|
||||
InterpolationData(const Mesh *mesh);
|
||||
~InterpolationData();
|
||||
|
||||
const Vec3f *getVertices() const {return vertices==NULL? mesh->getVertices(): vertices;}
|
||||
const Vec3f *getNormals() const {return normals==NULL? mesh->getNormals(): normals;}
|
||||
|
||||
void update(float t, bool cycle);
|
||||
void updateVertices(float t, bool cycle);
|
||||
void updateNormals(float t, bool cycle);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
218
source/shared_lib/include/graphics/math_util.h
Normal file
218
source/shared_lib/include/graphics/math_util.h
Normal file
@@ -0,0 +1,218 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MATHUTIL_H_
|
||||
#define _SHARED_GRAPHICS_MATHUTIL_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "vec.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
const float pi= 3.1415926f;
|
||||
const float sqrt2= 1.41421356f;
|
||||
const float zero= 1e-6f;
|
||||
const float infinity= 1e6f;
|
||||
|
||||
// =====================================================
|
||||
// class Rect
|
||||
// =====================================================
|
||||
|
||||
// 0 +-+
|
||||
// | |
|
||||
// +-+ 1
|
||||
|
||||
template<typename T>
|
||||
class Rect2{
|
||||
public:
|
||||
Vec2<T> p[2];
|
||||
public:
|
||||
Rect2(){
|
||||
};
|
||||
|
||||
Rect2(const Vec2<T> &p0, const Vec2<T> &p1){
|
||||
this->p[0]= p0;
|
||||
this->p[1]= p1;
|
||||
}
|
||||
|
||||
Rect2(T p0x, T p0y, T p1x, T p1y){
|
||||
p[0].x= p0x;
|
||||
p[0].y= p0y;
|
||||
p[1].x= p1x;
|
||||
p[1].y= p1y;
|
||||
}
|
||||
|
||||
Rect2<T> operator*(T scalar){
|
||||
return Rect2<T>(
|
||||
p[0]*scalar,
|
||||
p[1]*scalar);
|
||||
}
|
||||
|
||||
Rect2<T> operator/(T scalar){
|
||||
return Rect2<T>(
|
||||
p[0]/scalar,
|
||||
p[1]/scalar);
|
||||
}
|
||||
|
||||
bool isInside(const Vec2<T> &p) const{
|
||||
return
|
||||
p.x>=this->p[0].x &&
|
||||
p.y>=this->p[0].y &&
|
||||
p.x<this->p[1].x &&
|
||||
p.y<this->p[1].y;
|
||||
}
|
||||
|
||||
void clamp(T minX, T minY,T maxX, T maxY){
|
||||
for(int i=0; i<2; ++i){
|
||||
if(p[i].x<minX){
|
||||
p[i].x= minX;
|
||||
}
|
||||
if(p[i].y<minY){
|
||||
p[i].y= minY;
|
||||
}
|
||||
if(p[i].x>maxX){
|
||||
p[i].x= maxX;
|
||||
}
|
||||
if(p[i].y>maxY){
|
||||
p[i].y= maxY;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef Rect2<int> Rect2i;
|
||||
typedef Rect2<char> Rect2c;
|
||||
typedef Rect2<float> Rect2f;
|
||||
typedef Rect2<double> Rect2d;
|
||||
|
||||
// =====================================================
|
||||
// class Quad
|
||||
// =====================================================
|
||||
|
||||
// 0 +-+ 2
|
||||
// | |
|
||||
// 1 +-+ 3
|
||||
|
||||
template<typename T>
|
||||
class Quad2{
|
||||
public:
|
||||
Vec2<T> p[4];
|
||||
public:
|
||||
Quad2(){
|
||||
};
|
||||
|
||||
Quad2(const Vec2<T> &p0, const Vec2<T> &p1, const Vec2<T> &p2, const Vec2<T> &p3){
|
||||
this->p[0]= p0;
|
||||
this->p[1]= p1;
|
||||
this->p[2]= p2;
|
||||
this->p[3]= p3;
|
||||
}
|
||||
|
||||
explicit Quad2(const Rect2<T> &rect){
|
||||
this->p[0]= rect.p[0];
|
||||
this->p[1]= Vec2<T>(rect.p[0].x, rect.p[1].y);
|
||||
this->p[2]= rect.p[1];
|
||||
this->p[3]= Vec2<T>(rect.p[1].x, rect.p[0].y);
|
||||
}
|
||||
|
||||
Quad2<T> operator*(T scalar){
|
||||
return Quad2<T>(
|
||||
p[0]*scalar,
|
||||
p[1]*scalar,
|
||||
p[2]*scalar,
|
||||
p[3]*scalar);
|
||||
}
|
||||
|
||||
Quad2<T> operator/(T scalar){
|
||||
return Quad2<T>(
|
||||
p[0]/scalar,
|
||||
p[1]/scalar,
|
||||
p[2]/scalar,
|
||||
p[3]/scalar);
|
||||
}
|
||||
|
||||
Rect2<T> computeBoundingRect() const{
|
||||
return Rect2i(
|
||||
min(p[0].x, p[1].x),
|
||||
min(p[0].y, p[2].y),
|
||||
max(p[2].x, p[3].x),
|
||||
max(p[1].y, p[3].y));
|
||||
}
|
||||
|
||||
bool isInside(const Vec2<T> &pt) const{
|
||||
|
||||
if(!computeBoundingRect().isInside(pt))
|
||||
return false;
|
||||
|
||||
bool left[4];
|
||||
|
||||
left[0]= (pt.y - p[0].y)*(p[1].x - p[0].x) - (pt.x - p[0].x)*(p[1].y - p[0].y) < 0;
|
||||
left[1]= (pt.y - p[1].y)*(p[3].x - p[1].x) - (pt.x - p[1].x)*(p[3].y - p[1].y) < 0;
|
||||
left[2]= (pt.y - p[3].y)*(p[2].x - p[3].x) - (pt.x - p[3].x)*(p[2].y - p[3].y) < 0;
|
||||
left[3]= (pt.y - p[2].y)*(p[0].x - p[2].x) - (pt.x - p[2].x)*(p[0].y - p[2].y) < 0;
|
||||
|
||||
return left[0] && left[1] && left[2] && left[3];
|
||||
}
|
||||
|
||||
void clamp(T minX, T minY, T maxX, T maxY){
|
||||
for(int i=0; i<4; ++i){
|
||||
if(p[i].x<minX){
|
||||
p[i].x= minX;
|
||||
}
|
||||
if(p[i].y<minY){
|
||||
p[i].y= minY;
|
||||
}
|
||||
if(p[i].x>maxX){
|
||||
p[i].x= maxX;
|
||||
}
|
||||
if(p[i].y>maxY){
|
||||
p[i].y= maxY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float area(){
|
||||
Vec2i v0= p[3]-p[0];
|
||||
Vec2i v1= p[1]-p[2];
|
||||
|
||||
return 0.5f * ((v0.x * v1.y) - (v0.y * v1.x));
|
||||
}
|
||||
};
|
||||
|
||||
typedef Quad2<int> Quad2i;
|
||||
typedef Quad2<char> Quad2c;
|
||||
typedef Quad2<float> Quad2f;
|
||||
typedef Quad2<double> Quad2d;
|
||||
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
|
||||
inline int next2Power(int n){
|
||||
int i;
|
||||
for (i=1; i<n; i*=2);
|
||||
return i;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T degToRad(T deg){
|
||||
return (deg*2*pi)/360;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T radToDeg(T rad){
|
||||
return (rad*360)/(2*pi);
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
162
source/shared_lib/include/graphics/matrix.h
Normal file
162
source/shared_lib/include/graphics/matrix.h
Normal file
@@ -0,0 +1,162 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MATRIX_H_
|
||||
#define _SHARED_GRAPHICS_MATRIX_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "vec.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class Matrix3
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Matrix3{
|
||||
private:
|
||||
T data[9];
|
||||
public:
|
||||
Matrix3(){};
|
||||
|
||||
Matrix3(T *p){
|
||||
for(int i=0; i<9; ++i){
|
||||
data[i]= p[i];
|
||||
}
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return data;
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return data;
|
||||
}
|
||||
|
||||
T &operator[](int i){
|
||||
return data[i];
|
||||
}
|
||||
|
||||
T &operator()(int i, int j){
|
||||
return data[i*3+j];
|
||||
}
|
||||
|
||||
Vec3<T> operator * (const Vec3<T> &v) const{
|
||||
Vec3<T> rv;
|
||||
|
||||
return Vec3f(
|
||||
data[0]*v.x + data[1]*v.y + data[2]*v.z,
|
||||
data[3]*v.x + data[4]*v.y + data[5]*v.z,
|
||||
data[6]*v.x + data[7]*v.y + data[8]*v.z);
|
||||
}
|
||||
|
||||
Matrix3<T> operator * (const Matrix3<T> &m) const{
|
||||
Matrix3<T> rm;
|
||||
|
||||
for(int i=0; i<3; ++i){
|
||||
for(int j=0; j<3; ++j){
|
||||
T acum= 0.0f;
|
||||
for(int k=0; k<3; ++k){
|
||||
acum+= data[i*3+k]*m[k*3+j];
|
||||
}
|
||||
rm[i*3+j]= acum;
|
||||
}
|
||||
}
|
||||
return rm;
|
||||
}
|
||||
|
||||
void traspose(){
|
||||
for(int i=0; i<3; ++i){
|
||||
for(int j=0; j<3; ++j){
|
||||
T tmp= data[j*3+i];
|
||||
data[j*3+i]= data[i*3+j];
|
||||
data[i*3+j]= tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef Matrix3<float> Matrix3f;
|
||||
typedef Matrix3<double> Matrix3d;
|
||||
|
||||
// =====================================================
|
||||
// class Matrix4
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Matrix4{
|
||||
private:
|
||||
T data[16];
|
||||
public:
|
||||
Matrix4(){};
|
||||
|
||||
Matrix4(T *p){
|
||||
for(int i=0; i<16; ++i){
|
||||
data[i]= p[i];
|
||||
}
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return data;
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return data;
|
||||
}
|
||||
|
||||
T &operator[](int i){
|
||||
return data[i];
|
||||
}
|
||||
|
||||
const T &operator[](int i) const{
|
||||
return data[i];
|
||||
}
|
||||
|
||||
T &operator()(int i, int j){
|
||||
return data[i*4+j];
|
||||
}
|
||||
|
||||
Vec4<T> operator * (const Vec4<T> &v) const{
|
||||
Vec4<T> rv;
|
||||
|
||||
return Vec4f(
|
||||
data[0]*v.x + data[1]*v.y + data[2]*v.z + data[3]*v.w,
|
||||
data[4]*v.x + data[5]*v.y + data[6]*v.z + data[7]*v.w,
|
||||
data[8]*v.x + data[9]*v.y + data[10]*v.z + data[11]*v.w,
|
||||
data[12]*v.x + data[13]*v.y + data[14]*v.z + data[15]*v.w);
|
||||
}
|
||||
|
||||
Matrix4<T> operator * (const Matrix4<T> &m) const{
|
||||
Matrix4<T> rm;
|
||||
|
||||
for(int i=0; i<4; ++i){
|
||||
for(int j=0; j<4; ++j){
|
||||
T acum= 0.0f;
|
||||
for(int k=0; k<4; ++k){
|
||||
acum+= data[i*4+k]*m[k*4+j];
|
||||
}
|
||||
rm[i*4+j]= acum;
|
||||
}
|
||||
}
|
||||
return rm;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Matrix4<float> Matrix4f;
|
||||
typedef Matrix4<double> Matrix4d;
|
||||
|
||||
|
||||
}} //enmd namespace
|
||||
|
||||
#endif
|
172
source/shared_lib/include/graphics/model.h
Normal file
172
source/shared_lib/include/graphics/model.h
Normal file
@@ -0,0 +1,172 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MODEL_H_
|
||||
#define _SHARED_GRAPHICS_MODEL_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "types.h"
|
||||
#include "pixmap.h"
|
||||
#include "texture_manager.h"
|
||||
#include "texture.h"
|
||||
#include "model_header.h"
|
||||
|
||||
using std::string;
|
||||
using std::map;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class Model;
|
||||
class Mesh;
|
||||
class ShadowVolumeData;
|
||||
class InterpolationData;
|
||||
class TextureManager;
|
||||
|
||||
// =====================================================
|
||||
// class Mesh
|
||||
//
|
||||
// Part of a 3D model
|
||||
// =====================================================
|
||||
|
||||
class Mesh{
|
||||
private:
|
||||
//mesh data
|
||||
Texture2D *textures[meshTextureCount];
|
||||
string texturePaths[meshTextureCount];
|
||||
|
||||
//vertex data counts
|
||||
uint32 frameCount;
|
||||
uint32 vertexCount;
|
||||
uint32 indexCount;
|
||||
|
||||
//vertex data
|
||||
Vec3f *vertices;
|
||||
Vec3f *normals;
|
||||
Vec2f *texCoords;
|
||||
Vec3f *tangents;
|
||||
uint32 *indices;
|
||||
|
||||
//material data
|
||||
Vec3f diffuseColor;
|
||||
Vec3f specularColor;
|
||||
float specularPower;
|
||||
float opacity;
|
||||
|
||||
//properties
|
||||
bool twoSided;
|
||||
bool customColor;
|
||||
|
||||
InterpolationData *interpolationData;
|
||||
|
||||
public:
|
||||
//init & end
|
||||
Mesh();
|
||||
~Mesh();
|
||||
void init();
|
||||
void end();
|
||||
|
||||
//maps
|
||||
const Texture2D *getTexture(int i) const {return textures[i];}
|
||||
|
||||
//counts
|
||||
uint32 getFrameCount() const {return frameCount;}
|
||||
uint32 getVertexCount() const {return vertexCount;}
|
||||
uint32 getIndexCount() const {return indexCount;}
|
||||
uint32 getTriangleCount() const;
|
||||
|
||||
//data
|
||||
const Vec3f *getVertices() const {return vertices;}
|
||||
const Vec3f *getNormals() const {return normals;}
|
||||
const Vec2f *getTexCoords() const {return texCoords;}
|
||||
const Vec3f *getTangents() const {return tangents;}
|
||||
const uint32 *getIndices() const {return indices;}
|
||||
|
||||
//material
|
||||
const Vec3f &getDiffuseColor() const {return diffuseColor;}
|
||||
const Vec3f &getSpecularColor() const {return specularColor;}
|
||||
float getSpecularPower() const {return specularPower;}
|
||||
float getOpacity() const {return opacity;}
|
||||
|
||||
//properties
|
||||
bool getTwoSided() const {return twoSided;}
|
||||
bool getCustomTexture() const {return customColor;}
|
||||
|
||||
//external data
|
||||
const InterpolationData *getInterpolationData() const {return interpolationData;}
|
||||
|
||||
//interpolation
|
||||
void buildInterpolationData();
|
||||
void updateInterpolationData(float t, bool cycle) const;
|
||||
void updateInterpolationVertices(float t, bool cycle) const;
|
||||
|
||||
//load
|
||||
void loadV2(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void loadV3(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void load(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void save(const string &dir, FILE *f);
|
||||
|
||||
private:
|
||||
void computeTangents();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Model
|
||||
//
|
||||
// 3D Model, than can be loaded from a g3d file
|
||||
// =====================================================
|
||||
|
||||
class Model{
|
||||
private:
|
||||
TextureManager *textureManager;
|
||||
|
||||
private:
|
||||
uint8 fileVersion;
|
||||
uint32 meshCount;
|
||||
Mesh *meshes;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Model();
|
||||
virtual ~Model();
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
|
||||
//data
|
||||
void updateInterpolationData(float t, bool cycle) const;
|
||||
void updateInterpolationVertices(float t, bool cycle) const;
|
||||
void buildShadowVolumeData() const;
|
||||
|
||||
//get
|
||||
uint8 getFileVersion() const {return fileVersion;}
|
||||
uint32 getMeshCount() const {return meshCount;}
|
||||
const Mesh *getMesh(int i) const {return &meshes[i];}
|
||||
|
||||
uint32 getTriangleCount() const;
|
||||
uint32 getVertexCount() const;
|
||||
|
||||
//io
|
||||
void load(const string &path);
|
||||
void save(const string &path);
|
||||
void loadG3d(const string &path);
|
||||
void saveS3d(const string &path);
|
||||
|
||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||
|
||||
private:
|
||||
void buildInterpolationData() const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
118
source/shared_lib/include/graphics/model_header.h
Normal file
118
source/shared_lib/include/graphics/model_header.h
Normal file
@@ -0,0 +1,118 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICTYPES_MODELHEADER_H_
|
||||
#define _SHARED_GRAPHICTYPES_MODELHEADER_H_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
using Shared::Platform::uint8;
|
||||
using Shared::Platform::uint16;
|
||||
using Shared::Platform::uint32;
|
||||
using Shared::Platform::float32;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct FileHeader{
|
||||
uint8 id[3];
|
||||
uint8 version;
|
||||
};
|
||||
|
||||
//version 4
|
||||
|
||||
struct ModelHeader{
|
||||
uint16 meshCount;
|
||||
uint8 type;
|
||||
};
|
||||
|
||||
enum ModelType{
|
||||
mtMorphMesh
|
||||
};
|
||||
|
||||
enum MeshPropertyFlag{
|
||||
mpfCustomColor= 1,
|
||||
mpfTwoSided= 2
|
||||
};
|
||||
|
||||
enum MeshTexture{
|
||||
mtDiffuse,
|
||||
mtSpecular,
|
||||
mtNormal,
|
||||
mtReflection,
|
||||
mtColorMask,
|
||||
|
||||
meshTextureCount
|
||||
};
|
||||
|
||||
const int meshTextureChannelCount[]= {-1, 1, 3, 1, 1};
|
||||
|
||||
const uint32 meshNameSize= 64;
|
||||
const uint32 mapPathSize= 64;
|
||||
|
||||
struct MeshHeader{
|
||||
uint8 name[meshNameSize];
|
||||
uint32 frameCount;
|
||||
uint32 vertexCount;
|
||||
uint32 indexCount;
|
||||
float32 diffuseColor[3];
|
||||
float32 specularColor[3];
|
||||
float32 specularPower;
|
||||
float32 opacity;
|
||||
uint32 properties;
|
||||
uint32 textures;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
//version 3
|
||||
|
||||
//front faces are clockwise faces
|
||||
struct ModelHeaderV3{
|
||||
uint32 meshCount;
|
||||
};
|
||||
|
||||
enum MeshPropertyV3{
|
||||
mp3NoTexture= 1,
|
||||
mp3TwoSided= 2,
|
||||
mp3CustomColor= 4
|
||||
};
|
||||
|
||||
struct MeshHeaderV3{
|
||||
uint32 vertexFrameCount;
|
||||
uint32 normalFrameCount;
|
||||
uint32 texCoordFrameCount;
|
||||
uint32 colorFrameCount;
|
||||
uint32 pointCount;
|
||||
uint32 indexCount;
|
||||
uint32 properties;
|
||||
uint8 texName[64];
|
||||
};
|
||||
|
||||
//version 2
|
||||
|
||||
struct MeshHeaderV2{
|
||||
uint32 vertexFrameCount;
|
||||
uint32 normalFrameCount;
|
||||
uint32 texCoordFrameCount;
|
||||
uint32 colorFrameCount;
|
||||
uint32 pointCount;
|
||||
uint32 indexCount;
|
||||
uint8 hasTexture;
|
||||
uint8 primitive;
|
||||
uint8 cullFace;
|
||||
uint8 texName[64];
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
51
source/shared_lib/include/graphics/model_manager.h
Normal file
51
source/shared_lib/include/graphics/model_manager.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MODELMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_MODELMANAGER_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class TextureManager;
|
||||
|
||||
// =====================================================
|
||||
// class ModelManager
|
||||
// =====================================================
|
||||
|
||||
class ModelManager{
|
||||
protected:
|
||||
typedef vector<Model*> ModelContainer;
|
||||
|
||||
protected:
|
||||
ModelContainer models;
|
||||
TextureManager *textureManager;
|
||||
|
||||
public:
|
||||
ModelManager();
|
||||
virtual ~ModelManager();
|
||||
|
||||
Model *newModel();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
|
||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
58
source/shared_lib/include/graphics/model_renderer.h
Normal file
58
source/shared_lib/include/graphics/model_renderer.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MODELRENDERER_H_
|
||||
#define _SHARED_GRAPHICS_MODELRENDERER_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class Texture;
|
||||
|
||||
// =====================================================
|
||||
// class MeshCallback
|
||||
//
|
||||
/// This gets called before rendering mesh
|
||||
// =====================================================
|
||||
|
||||
class MeshCallback{
|
||||
public:
|
||||
virtual ~MeshCallback(){};
|
||||
virtual void execute(const Mesh *mesh)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ModelRenderer
|
||||
// =====================================================
|
||||
|
||||
class ModelRenderer{
|
||||
protected:
|
||||
bool renderNormals;
|
||||
bool renderTextures;
|
||||
bool renderColors;
|
||||
MeshCallback *meshCallback;
|
||||
|
||||
public:
|
||||
ModelRenderer() {meshCallback= NULL;}
|
||||
|
||||
virtual ~ModelRenderer(){};
|
||||
|
||||
virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback= NULL)=0;
|
||||
virtual void end()=0;
|
||||
virtual void render(const Model *model)=0;
|
||||
virtual void renderNormalsOnly(const Model *model)=0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
373
source/shared_lib/include/graphics/particle.h
Normal file
373
source/shared_lib/include/graphics/particle.h
Normal file
@@ -0,0 +1,373 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_PARTICLE_H_
|
||||
#define _SHARED_GRAPHICS_PARTICLE_H_
|
||||
|
||||
#include <list>
|
||||
#include <cassert>
|
||||
|
||||
#include "vec.h"
|
||||
#include "pixmap.h"
|
||||
#include "texture_manager.h"
|
||||
#include "random.h"
|
||||
|
||||
using std::list;
|
||||
using Shared::Util::Random;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class ParticleSystem;
|
||||
class FireParticleSystem;
|
||||
class RainParticleSystem;
|
||||
class SnowParticleSystem;
|
||||
class ProjectileParticleSystem;
|
||||
class SplashParticleSystem;
|
||||
class ParticleRenderer;
|
||||
class ModelRenderer;
|
||||
class Model;
|
||||
|
||||
// =====================================================
|
||||
// class Particle
|
||||
// =====================================================
|
||||
|
||||
class Particle{
|
||||
public:
|
||||
//attributes
|
||||
Vec3f pos;
|
||||
Vec3f lastPos;
|
||||
Vec3f speed;
|
||||
Vec3f accel;
|
||||
Vec4f color;
|
||||
float size;
|
||||
int energy;
|
||||
|
||||
public:
|
||||
//get
|
||||
Vec3f getPos() const {return pos;}
|
||||
Vec3f getLastPos() const {return lastPos;}
|
||||
Vec3f getSpeed() const {return speed;}
|
||||
Vec3f getAccel() const {return accel;}
|
||||
Vec4f getColor() const {return color;}
|
||||
float getSize() const {return size;}
|
||||
int getEnergy() const {return energy;}
|
||||
};
|
||||
|
||||
class ParticleSystem;
|
||||
|
||||
// =====================================================
|
||||
// class ParticleObserver
|
||||
// =====================================================
|
||||
|
||||
class ParticleObserver{
|
||||
public:
|
||||
virtual ~ParticleObserver(){};
|
||||
virtual void update(ParticleSystem *particleSystem)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class ParticleSystem{
|
||||
public:
|
||||
enum BlendMode{
|
||||
bmOne,
|
||||
bmOneMinusAlpha
|
||||
};
|
||||
|
||||
protected:
|
||||
enum State{
|
||||
sPause, // No updates
|
||||
sPlay,
|
||||
sFade // No new particles
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
Particle *particles;
|
||||
Random random;
|
||||
|
||||
BlendMode blendMode;
|
||||
State state;
|
||||
bool active;
|
||||
bool visible;
|
||||
int aliveParticleCount;
|
||||
int particleCount;
|
||||
|
||||
|
||||
Texture *texture;
|
||||
Vec3f pos;
|
||||
Vec4f color;
|
||||
Vec4f colorNoEnergy;
|
||||
int emissionRate;
|
||||
int maxParticleEnergy;
|
||||
int varParticleEnergy;
|
||||
float particleSize;
|
||||
float speed;
|
||||
|
||||
ParticleObserver *particleObserver;
|
||||
|
||||
public:
|
||||
//conmstructor and destructor
|
||||
ParticleSystem(int particleCount);
|
||||
virtual ~ParticleSystem();
|
||||
|
||||
//public
|
||||
virtual void update();
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
//get
|
||||
State getState() const {return state;}
|
||||
BlendMode getBlendMode() const {return blendMode;}
|
||||
Texture *getTexture() const {return texture;}
|
||||
Vec3f getPos() const {return pos;}
|
||||
Particle *getParticle(int i) {return &particles[i];}
|
||||
const Particle *getParticle(int i) const {return &particles[i];}
|
||||
int getAliveParticleCount() const {return aliveParticleCount;}
|
||||
bool getActive() const {return active;}
|
||||
bool getVisible() const {return visible;}
|
||||
|
||||
//set
|
||||
void setState(State state);
|
||||
void setTexture(Texture *texture);
|
||||
void setPos(Vec3f pos);
|
||||
void setColor(Vec4f color);
|
||||
void setColorNoEnergy(Vec4f color);
|
||||
void setEmissionRate(int emissionRate);
|
||||
void setMaxParticleEnergy(int maxParticleEnergy);
|
||||
void setVarParticleEnergy(int varParticleEnergy);
|
||||
void setParticleSize(float particleSize);
|
||||
void setSpeed(float speed);
|
||||
void setActive(bool active);
|
||||
void setObserver(ParticleObserver *particleObserver);
|
||||
void setVisible(bool visible);
|
||||
|
||||
//misc
|
||||
void fade();
|
||||
int isEmpty() const;
|
||||
|
||||
protected:
|
||||
//protected
|
||||
Particle *createParticle();
|
||||
void killParticle(Particle *p);
|
||||
|
||||
//virtual protected
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
virtual bool deathTest(Particle *p);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FireParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class FireParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
float radius;
|
||||
Vec3f windSpeed;
|
||||
|
||||
public:
|
||||
FireParticleSystem(int particleCount= 2000);
|
||||
|
||||
//virtual
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
|
||||
//set params
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class RainParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class RainParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
Vec3f windSpeed;
|
||||
float radius;
|
||||
|
||||
public:
|
||||
RainParticleSystem(int particleCount= 4000);
|
||||
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual bool deathTest(Particle *p);
|
||||
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SnowParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class SnowParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
Vec3f windSpeed;
|
||||
float radius;
|
||||
|
||||
public:
|
||||
SnowParticleSystem(int particleCount= 4000);
|
||||
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual bool deathTest(Particle *p);
|
||||
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
};
|
||||
|
||||
// ===========================================================================
|
||||
// AttackParticleSystem
|
||||
//
|
||||
/// Base class for Projectiles and Splashes
|
||||
// ===========================================================================
|
||||
|
||||
class AttackParticleSystem: public ParticleSystem{
|
||||
public:
|
||||
enum Primitive{
|
||||
pQuad,
|
||||
pLine,
|
||||
pLineAlpha
|
||||
};
|
||||
|
||||
protected:
|
||||
Model *model;
|
||||
Primitive primitive;
|
||||
Vec3f offset;
|
||||
float sizeNoEnergy;
|
||||
float gravity;
|
||||
|
||||
Vec3f direction;
|
||||
|
||||
public:
|
||||
AttackParticleSystem(int particleCount);
|
||||
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
Model *getModel() const {return model;}
|
||||
Vec3f getDirection() const {return direction;}
|
||||
|
||||
void setModel(Model *model) {this->model= model;}
|
||||
void setOffset(Vec3f offset) {this->offset= offset;}
|
||||
void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;}
|
||||
void setGravity(float gravity) {this->gravity= gravity;}
|
||||
void setPrimitive(Primitive primitive) {this->primitive= primitive;}
|
||||
|
||||
static Primitive strToPrimitive(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ProjectileParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class ProjectileParticleSystem: public AttackParticleSystem{
|
||||
public:
|
||||
friend class SplashParticleSystem;
|
||||
|
||||
enum Trajectory{
|
||||
tLinear,
|
||||
tParabolic,
|
||||
tSpiral
|
||||
};
|
||||
|
||||
private:
|
||||
SplashParticleSystem *nextParticleSystem;
|
||||
|
||||
Vec3f lastPos;
|
||||
Vec3f startPos;
|
||||
Vec3f endPos;
|
||||
Vec3f flatPos;
|
||||
|
||||
Vec3f xVector;
|
||||
Vec3f yVector;
|
||||
Vec3f zVector;
|
||||
|
||||
Trajectory trajectory;
|
||||
float trajectorySpeed;
|
||||
|
||||
//parabolic
|
||||
float trajectoryScale;
|
||||
float trajectoryFrequency;
|
||||
|
||||
public:
|
||||
ProjectileParticleSystem(int particleCount= 1000);
|
||||
virtual ~ProjectileParticleSystem();
|
||||
|
||||
void link(SplashParticleSystem *particleSystem);
|
||||
|
||||
virtual void update();
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
|
||||
void setTrajectory(Trajectory trajectory) {this->trajectory= trajectory;}
|
||||
void setTrajectorySpeed(float trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;}
|
||||
void setTrajectoryScale(float trajectoryScale) {this->trajectoryScale= trajectoryScale;}
|
||||
void setTrajectoryFrequency(float trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;}
|
||||
void setPath(Vec3f startPos, Vec3f endPos);
|
||||
|
||||
static Trajectory strToTrajectory(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SplashParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class SplashParticleSystem: public AttackParticleSystem{
|
||||
public:
|
||||
friend class ProjectileParticleSystem;
|
||||
|
||||
private:
|
||||
ProjectileParticleSystem *prevParticleSystem;
|
||||
|
||||
int emissionRateFade;
|
||||
float verticalSpreadA;
|
||||
float verticalSpreadB;
|
||||
float horizontalSpreadA;
|
||||
float horizontalSpreadB;
|
||||
|
||||
public:
|
||||
SplashParticleSystem(int particleCount= 1000);
|
||||
virtual ~SplashParticleSystem();
|
||||
|
||||
virtual void update();
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
|
||||
void setEmissionRateFade(int emissionRateFade) {this->emissionRateFade= emissionRateFade;}
|
||||
void setVerticalSpreadA(float verticalSpreadA) {this->verticalSpreadA= verticalSpreadA;}
|
||||
void setVerticalSpreadB(float verticalSpreadB) {this->verticalSpreadB= verticalSpreadB;}
|
||||
void setHorizontalSpreadA(float horizontalSpreadA) {this->horizontalSpreadA= horizontalSpreadA;}
|
||||
void setHorizontalSpreadB(float horizontalSpreadB) {this->horizontalSpreadB= horizontalSpreadB;}
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ParticleManager
|
||||
// =====================================================
|
||||
|
||||
class ParticleManager{
|
||||
private:
|
||||
list<ParticleSystem*> particleSystems;
|
||||
|
||||
public:
|
||||
~ParticleManager();
|
||||
void update();
|
||||
void render(ParticleRenderer *pr, ModelRenderer *mr) const;
|
||||
void manage(ParticleSystem *ps);
|
||||
void end();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
38
source/shared_lib/include/graphics/particle_renderer.h
Normal file
38
source/shared_lib/include/graphics/particle_renderer.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_PARTICLERENDERER_H_
|
||||
#define _SHARED_GRAPHICS_PARTICLERENDERER_H_
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class ModelRenderer;
|
||||
|
||||
// =====================================================
|
||||
// class ParticleRenderer
|
||||
// =====================================================
|
||||
|
||||
class ParticleRenderer{
|
||||
public:
|
||||
//particles
|
||||
virtual ~ParticleRenderer(){};
|
||||
virtual void renderManager(ParticleManager *pm, ModelRenderer *mr)=0;
|
||||
virtual void renderSystem(ParticleSystem *ps)=0;
|
||||
virtual void renderSystemLine(ParticleSystem *ps)=0;
|
||||
virtual void renderSystemLineAlpha(ParticleSystem *ps)=0;
|
||||
virtual void renderSingleModel(AttackParticleSystem *ps, ModelRenderer *mr)=0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
267
source/shared_lib/include/graphics/pixmap.h
Normal file
267
source/shared_lib/include/graphics/pixmap.h
Normal file
@@ -0,0 +1,267 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_PIXMAP_H_
|
||||
#define _SHARED_GRAPHICS_PIXMAP_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "vec.h"
|
||||
#include "types.h"
|
||||
|
||||
using std::string;
|
||||
using Shared::Platform::int8;
|
||||
using Shared::Platform::uint8;
|
||||
using Shared::Platform::int16;
|
||||
using Shared::Platform::uint16;
|
||||
using Shared::Platform::int32;
|
||||
using Shared::Platform::uint32;
|
||||
using Shared::Platform::float32;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class PixmapIo
|
||||
// =====================================================
|
||||
|
||||
class PixmapIo{
|
||||
protected:
|
||||
int w;
|
||||
int h;
|
||||
int components;
|
||||
|
||||
public:
|
||||
virtual ~PixmapIo(){}
|
||||
|
||||
int getW() const {return w;}
|
||||
int getH() const {return h;}
|
||||
int getComponents() const {return components;}
|
||||
|
||||
virtual void openRead(const string &path)= 0;
|
||||
virtual void read(uint8 *pixels)= 0;
|
||||
virtual void read(uint8 *pixels, int components)= 0;
|
||||
|
||||
virtual void openWrite(const string &path, int w, int h, int components)= 0;
|
||||
virtual void write(uint8 *pixels)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PixmapIoTga
|
||||
// =====================================================
|
||||
|
||||
class PixmapIoTga: public PixmapIo{
|
||||
private:
|
||||
FILE *file;
|
||||
|
||||
public:
|
||||
PixmapIoTga();
|
||||
virtual ~PixmapIoTga();
|
||||
|
||||
virtual void openRead(const string &path);
|
||||
virtual void read(uint8 *pixels);
|
||||
virtual void read(uint8 *pixels, int components);
|
||||
|
||||
virtual void openWrite(const string &path, int w, int h, int components);
|
||||
virtual void write(uint8 *pixels);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PixmapIoBmp
|
||||
// =====================================================
|
||||
|
||||
class PixmapIoBmp: public PixmapIo{
|
||||
private:
|
||||
FILE *file;
|
||||
|
||||
public:
|
||||
PixmapIoBmp();
|
||||
virtual ~PixmapIoBmp();
|
||||
|
||||
virtual void openRead(const string &path);
|
||||
virtual void read(uint8 *pixels);
|
||||
virtual void read(uint8 *pixels, int components);
|
||||
|
||||
virtual void openWrite(const string &path, int w, int h, int components);
|
||||
virtual void write(uint8 *pixels);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Pixmap1D
|
||||
// =====================================================
|
||||
|
||||
class Pixmap1D{
|
||||
protected:
|
||||
int w;
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap1D();
|
||||
Pixmap1D(int components);
|
||||
Pixmap1D(int w, int components);
|
||||
void init(int components);
|
||||
void init(int w, int components);
|
||||
~Pixmap1D();
|
||||
|
||||
//load & save
|
||||
void load(const string &path);
|
||||
void loadTga(const string &path);
|
||||
void loadBmp(const string &path);
|
||||
|
||||
//get
|
||||
int getW() const {return w;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Pixmap2D
|
||||
// =====================================================
|
||||
|
||||
class Pixmap2D{
|
||||
protected:
|
||||
int h;
|
||||
int w;
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap2D();
|
||||
Pixmap2D(int components);
|
||||
Pixmap2D(int w, int h, int components);
|
||||
void init(int components);
|
||||
void init(int w, int h, int components);
|
||||
~Pixmap2D();
|
||||
|
||||
//load & save
|
||||
void load(const string &path);
|
||||
void loadTga(const string &path);
|
||||
void loadBmp(const string &path);
|
||||
void save(const string &path);
|
||||
void saveBmp(const string &path);
|
||||
void saveTga(const string &path);
|
||||
|
||||
//get
|
||||
int getW() const {return w;}
|
||||
int getH() const {return h;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
|
||||
//get data
|
||||
void getPixel(int x, int y, uint8 *value) const;
|
||||
void getPixel(int x, int y, float32 *value) const;
|
||||
void getComponent(int x, int y, int component, uint8 &value) const;
|
||||
void getComponent(int x, int y, int component, float32 &value) const;
|
||||
|
||||
//vector get
|
||||
Vec4f getPixel4f(int x, int y) const;
|
||||
Vec3f getPixel3f(int x, int y) const;
|
||||
float getPixelf(int x, int y) const;
|
||||
float getComponentf(int x, int y, int component) const;
|
||||
|
||||
//set data
|
||||
void setPixel(int x, int y, const uint8 *value);
|
||||
void setPixel(int x, int y, const float32 *value);
|
||||
void setComponent(int x, int y, int component, uint8 value);
|
||||
void setComponent(int x, int y, int component, float32 value);
|
||||
|
||||
//vector set
|
||||
void setPixel(int x, int y, const Vec3f &p);
|
||||
void setPixel(int x, int y, const Vec4f &p);
|
||||
void setPixel(int x, int y, float p);
|
||||
|
||||
//mass set
|
||||
void setPixels(const uint8 *value);
|
||||
void setPixels(const float32 *value);
|
||||
void setComponents(int component, uint8 value);
|
||||
void setComponents(int component, float32 value);
|
||||
|
||||
//operations
|
||||
void splat(const Pixmap2D *leftUp, const Pixmap2D *rightUp, const Pixmap2D *leftDown, const Pixmap2D *rightDown);
|
||||
void lerp(float t, const Pixmap2D *pixmap1, const Pixmap2D *pixmap2);
|
||||
void copy(const Pixmap2D *sourcePixmap);
|
||||
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
||||
|
||||
private:
|
||||
bool doDimensionsAgree(const Pixmap2D *pixmap);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Pixmap3D
|
||||
// =====================================================
|
||||
|
||||
class Pixmap3D{
|
||||
protected:
|
||||
int h;
|
||||
int w;
|
||||
int d;
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap3D();
|
||||
Pixmap3D(int w, int h, int d, int components);
|
||||
Pixmap3D(int d, int components);
|
||||
void init(int w, int h, int d, int components);
|
||||
void init(int d, int components);
|
||||
~Pixmap3D();
|
||||
|
||||
//load & save
|
||||
void loadSlice(const string &path, int slice);
|
||||
void loadSliceBmp(const string &path, int slice);
|
||||
void loadSliceTga(const string &path, int slice);
|
||||
|
||||
//get
|
||||
int getW() const {return w;}
|
||||
int getH() const {return h;}
|
||||
int getD() const {return d;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PixmapCube
|
||||
// =====================================================
|
||||
|
||||
class PixmapCube{
|
||||
public:
|
||||
enum Face{
|
||||
fPositiveX,
|
||||
fNegativeX,
|
||||
fPositiveY,
|
||||
fNegativeY,
|
||||
fPositiveZ,
|
||||
fNegativeZ
|
||||
};
|
||||
|
||||
protected:
|
||||
Pixmap2D faces[6];
|
||||
|
||||
public:
|
||||
//init
|
||||
void init(int w, int h, int components);
|
||||
|
||||
//load & save
|
||||
void loadFace(const string &path, int face);
|
||||
void loadFaceBmp(const string &path, int face);
|
||||
void loadFaceTga(const string &path, int face);
|
||||
|
||||
//get
|
||||
Pixmap2D *getFace(int face) {return &faces[face];}
|
||||
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
97
source/shared_lib/include/graphics/quaternion.h
Normal file
97
source/shared_lib/include/graphics/quaternion.h
Normal file
@@ -0,0 +1,97 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_QUATERNION_H_
|
||||
#define _SHARED_GRAPHICS_QUATERNION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "vec.h"
|
||||
#include "matrix.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class AxisAngle
|
||||
// =====================================================
|
||||
|
||||
class AxisAngle{
|
||||
public:
|
||||
Vec3f axis;
|
||||
float angle;
|
||||
|
||||
AxisAngle(){};
|
||||
AxisAngle(const Vec3f &axis, float angle);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class EulerAngles
|
||||
// =====================================================
|
||||
|
||||
class EulerAngles{
|
||||
public:
|
||||
float x, y, z;
|
||||
|
||||
EulerAngles(){};
|
||||
EulerAngles(float x, float y, float z);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Quaternion
|
||||
// =====================================================
|
||||
|
||||
class Quaternion{
|
||||
private:
|
||||
float w;
|
||||
Vec3f v;
|
||||
|
||||
public:
|
||||
Quaternion();
|
||||
Quaternion(float w, const Vec3f &v);
|
||||
Quaternion(const EulerAngles &eulerAngles);
|
||||
Quaternion(const AxisAngle &axisAngle);
|
||||
|
||||
//initializers
|
||||
void setMultIdentity();
|
||||
void setAddIdentity();
|
||||
void setAxisAngle(const AxisAngle &axisAngle);
|
||||
void setEuler(const EulerAngles &eulerAngles);
|
||||
|
||||
//unary operators
|
||||
float length();
|
||||
Quaternion conjugate();
|
||||
void normalize();
|
||||
|
||||
//binary operators
|
||||
Quaternion operator + (const Quaternion &q) const;
|
||||
Quaternion operator * (const Quaternion &q) const;
|
||||
void operator += (const Quaternion &q);
|
||||
void operator *= (const Quaternion &q);
|
||||
|
||||
//ternary operators
|
||||
Quaternion lerp(float t, const Quaternion &q) const;
|
||||
|
||||
//conversions
|
||||
Matrix3f toMatrix3() const;
|
||||
Matrix4f toMatrix4() const;
|
||||
AxisAngle toAxisAngle() const;
|
||||
|
||||
//local axis
|
||||
Vec3f getLocalXAxis() const;
|
||||
Vec3f getLocalYAxis() const;
|
||||
Vec3f getLocalZAxis() const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
86
source/shared_lib/include/graphics/shader.h
Normal file
86
source/shared_lib/include/graphics/shader.h
Normal file
@@ -0,0 +1,86 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_SHADER_H_
|
||||
#define _SHARED_GRAPHICS_SHADER_H_
|
||||
|
||||
#include "vec.h"
|
||||
#include "matrix.h"
|
||||
#include "texture.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderProgram
|
||||
// =====================================================
|
||||
|
||||
class VertexShader;
|
||||
class FragmentShader;
|
||||
|
||||
class ShaderProgram{
|
||||
public:
|
||||
virtual ~ShaderProgram(){}
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
|
||||
virtual void attach(VertexShader *vs, FragmentShader *fs)= 0;
|
||||
virtual bool link(string &messages)= 0;
|
||||
virtual void activate()= 0;
|
||||
virtual void deactivate()= 0;
|
||||
|
||||
virtual void setUniform(const string &name, int value)= 0;
|
||||
virtual void setUniform(const string &name, float value)= 0;
|
||||
virtual void setUniform(const string &name, const Vec2f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Vec3f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Vec4f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Matrix3f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Matrix4f &value)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Shader
|
||||
// =====================================================
|
||||
|
||||
class Shader{
|
||||
public:
|
||||
virtual ~Shader(){}
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
|
||||
virtual void load(const string &path)= 0;
|
||||
virtual bool compile(string &messages)= 0;
|
||||
};
|
||||
|
||||
class VertexShader: virtual public Shader{
|
||||
};
|
||||
|
||||
class FragmentShader: virtual public Shader{
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ShaderSource
|
||||
// =====================================================
|
||||
|
||||
class ShaderSource{
|
||||
private:
|
||||
string pathInfo;
|
||||
string code;
|
||||
|
||||
public:
|
||||
const string &getPathInfo() const {return pathInfo;}
|
||||
const string &getCode() const {return code;}
|
||||
|
||||
void load(const string &path);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
53
source/shared_lib/include/graphics/shader_manager.h
Normal file
53
source/shared_lib/include/graphics/shader_manager.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_SHADERMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_SHADERMANAGER_H_
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderManager
|
||||
// =====================================================
|
||||
|
||||
class ShaderManager{
|
||||
protected:
|
||||
typedef vector<ShaderProgram*> ShaderProgramContainer;
|
||||
typedef vector<Shader*> ShaderContainer;
|
||||
|
||||
protected:
|
||||
ShaderProgramContainer shaderPrograms;
|
||||
ShaderContainer shaders;
|
||||
string logString;
|
||||
|
||||
public:
|
||||
ShaderManager(){}
|
||||
virtual ~ShaderManager();
|
||||
|
||||
ShaderProgram *newShaderProgram();
|
||||
VertexShader *newVertexShader();
|
||||
FragmentShader *newFragmentShader();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
|
||||
const string &getLogString() const {return logString;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
52
source/shared_lib/include/graphics/text_renderer.h
Normal file
52
source/shared_lib/include/graphics/text_renderer.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_TEXTRENDERER_H_
|
||||
#define _SHARED_GRAPHICS_TEXTRENDERER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "vec.h"
|
||||
#include "font.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer2D
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer2D{
|
||||
public:
|
||||
virtual ~TextRenderer2D(){};
|
||||
|
||||
virtual void begin(const Font2D *font)= 0;
|
||||
virtual void render(const string &text, int x, int y, bool centered= false)= 0;
|
||||
virtual void end()= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer3D
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer3D{
|
||||
public:
|
||||
virtual ~TextRenderer3D(){};
|
||||
|
||||
virtual void begin(const Font3D *font)= 0;
|
||||
virtual void render(const string &text, float x, float y, float size, bool centered= false)= 0;
|
||||
virtual void end()= 0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
144
source/shared_lib/include/graphics/texture.h
Normal file
144
source/shared_lib/include/graphics/texture.h
Normal file
@@ -0,0 +1,144 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_TEXTURE_H_
|
||||
#define _SHARED_GRAPHICS_TEXTURE_H_
|
||||
|
||||
#include "types.h"
|
||||
#include "pixmap.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using Shared::Platform::uint8;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class TextureParams;
|
||||
|
||||
// =====================================================
|
||||
// class Texture
|
||||
// =====================================================
|
||||
|
||||
class Texture{
|
||||
public:
|
||||
static const int defaultSize;
|
||||
|
||||
enum WrapMode{
|
||||
wmRepeat,
|
||||
wmClamp,
|
||||
wmClampToEdge
|
||||
};
|
||||
|
||||
enum Filter{
|
||||
fBilinear,
|
||||
fTrilinear
|
||||
};
|
||||
|
||||
enum Format{
|
||||
fAuto,
|
||||
fAlpha,
|
||||
fLuminance,
|
||||
fRgb,
|
||||
fRgba
|
||||
};
|
||||
|
||||
protected:
|
||||
string path;
|
||||
bool mipmap;
|
||||
WrapMode wrapMode;
|
||||
bool pixmapInit;
|
||||
Format format;
|
||||
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
Texture();
|
||||
virtual ~Texture(){};
|
||||
|
||||
bool getMipmap() const {return mipmap;}
|
||||
WrapMode getWrapMode() const {return wrapMode;}
|
||||
bool getPixmapInit() const {return pixmapInit;}
|
||||
Format getFormat() const {return format;}
|
||||
const string getPath() const {return path;}
|
||||
|
||||
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
||||
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
||||
void setPixmapInit(bool pixmapInit) {this->pixmapInit= pixmapInit;}
|
||||
void setFormat(Format format) {this->format= format;}
|
||||
|
||||
virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0;
|
||||
virtual void end()=0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture1D
|
||||
// =====================================================
|
||||
|
||||
class Texture1D: public Texture{
|
||||
protected:
|
||||
Pixmap1D pixmap;
|
||||
|
||||
public:
|
||||
void load(const string &path);
|
||||
|
||||
Pixmap1D *getPixmap() {return &pixmap;}
|
||||
const Pixmap1D *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture2D
|
||||
// =====================================================
|
||||
|
||||
class Texture2D: public Texture{
|
||||
protected:
|
||||
Pixmap2D pixmap;
|
||||
|
||||
public:
|
||||
void load(const string &path);
|
||||
|
||||
Pixmap2D *getPixmap() {return &pixmap;}
|
||||
const Pixmap2D *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture3D
|
||||
// =====================================================
|
||||
|
||||
class Texture3D: public Texture{
|
||||
protected:
|
||||
Pixmap3D pixmap;
|
||||
|
||||
public:
|
||||
void loadSlice(const string &path, int slice);
|
||||
|
||||
Pixmap3D *getPixmap() {return &pixmap;}
|
||||
const Pixmap3D *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextureCube
|
||||
// =====================================================
|
||||
|
||||
class TextureCube: public Texture{
|
||||
protected:
|
||||
PixmapCube pixmap;
|
||||
|
||||
public:
|
||||
void loadFace(const string &path, int face);
|
||||
|
||||
PixmapCube *getPixmap() {return &pixmap;}
|
||||
const PixmapCube *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
57
source/shared_lib/include/graphics/texture_manager.h
Normal file
57
source/shared_lib/include/graphics/texture_manager.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_TEXTUREMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_TEXTUREMANAGER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class TextureManager
|
||||
// =====================================================
|
||||
|
||||
//manages textures, creation on request and deletion on destruction
|
||||
class TextureManager{
|
||||
protected:
|
||||
typedef vector<Texture*> TextureContainer;
|
||||
|
||||
protected:
|
||||
TextureContainer textures;
|
||||
|
||||
Texture::Filter textureFilter;
|
||||
int maxAnisotropy;
|
||||
|
||||
public:
|
||||
TextureManager();
|
||||
~TextureManager();
|
||||
void init();
|
||||
void end();
|
||||
|
||||
void setFilter(Texture::Filter textureFilter);
|
||||
void setMaxAnisotropy(int maxAnisotropy);
|
||||
|
||||
Texture *getTexture(const string &path);
|
||||
Texture1D *newTexture1D();
|
||||
Texture2D *newTexture2D();
|
||||
Texture3D *newTexture3D();
|
||||
TextureCube *newTextureCube();
|
||||
};
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
443
source/shared_lib/include/graphics/vec.h
Normal file
443
source/shared_lib/include/graphics/vec.h
Normal file
@@ -0,0 +1,443 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_VEC_H_
|
||||
#define _SHARED_GRAPHICS_VEC_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
template<typename T> class Vec2;
|
||||
template<typename T> class Vec3;
|
||||
template<typename T> class Vec4;
|
||||
|
||||
// =====================================================
|
||||
// class Vec2
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Vec2{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
public:
|
||||
Vec2(){
|
||||
};
|
||||
|
||||
explicit Vec2(T *p){
|
||||
this->x= p[0];
|
||||
this->y= p[1];
|
||||
}
|
||||
|
||||
explicit Vec2(T xy){
|
||||
this->x= xy;
|
||||
this->y= xy;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec2(const Vec2<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
}
|
||||
|
||||
Vec2(T x, T y){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
bool operator ==(const Vec2<T> &v) const{
|
||||
return x==v.x && y==v.y;
|
||||
}
|
||||
|
||||
bool operator !=(const Vec2<T> &v) const{
|
||||
return x!=v.x || y!=v.y;
|
||||
}
|
||||
|
||||
Vec2<T> operator +(const Vec2<T> &v) const{
|
||||
return Vec2(x+v.x, y+v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator -(const Vec2<T> &v) const{
|
||||
return Vec2(x-v.x, y-v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator -() const{
|
||||
return Vec2(-x, -y);
|
||||
}
|
||||
|
||||
Vec2<T> operator *(const Vec2<T> &v) const{
|
||||
return Vec2(x*v.x, y*v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator *(T s) const{
|
||||
return Vec2(x*s, y*s);
|
||||
}
|
||||
|
||||
Vec2<T> operator /(const Vec2<T> &v) const{
|
||||
return Vec2(x/v.x, y/v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator /(T s) const{
|
||||
return Vec2(x/s, y/s);
|
||||
}
|
||||
|
||||
Vec2<T> operator +=(const Vec2<T> &v){
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator -=(const Vec2<T> &v){
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> lerp(T t, const Vec2<T> &v) const{
|
||||
return *this + (v - *this)*t;
|
||||
}
|
||||
|
||||
T dot(const Vec2<T> &v) const{
|
||||
return x*v.x+y*v.y;
|
||||
}
|
||||
|
||||
float dist(const Vec2<T> &v) const{
|
||||
return Vec2<T>(v-*this).length();
|
||||
}
|
||||
|
||||
float length() const{
|
||||
return static_cast<float>(sqrt(static_cast<float>(x*x + y*y)));
|
||||
}
|
||||
|
||||
void normalize(){
|
||||
T m= length();
|
||||
x/= m;
|
||||
y/= m;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec2<int> Vec2i;
|
||||
typedef Vec2<bool> Vec2b;
|
||||
typedef Vec2<char> Vec2c;
|
||||
typedef Vec2<float> Vec2f;
|
||||
typedef Vec2<double> Vec2d;
|
||||
|
||||
// =====================================================
|
||||
// class Vec3
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Vec3{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
public:
|
||||
Vec3(){
|
||||
};
|
||||
|
||||
explicit Vec3(T *p){
|
||||
this->x= p[0];
|
||||
this->y= p[1];
|
||||
this->z= p[2];
|
||||
}
|
||||
|
||||
explicit Vec3(T xyz){
|
||||
this->x= xyz;
|
||||
this->y= xyz;
|
||||
this->z= xyz;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec3(const Vec3<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
}
|
||||
|
||||
Vec3(T x, T y, T z){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
this->z= z;
|
||||
}
|
||||
|
||||
explicit Vec3(Vec4<T> v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
bool operator ==(const Vec3<T> &v) const{
|
||||
return x==v.x && y==v.y && z==v.z;
|
||||
}
|
||||
|
||||
bool operator !=(const Vec3<T> &v) const{
|
||||
return x!=v.x || y!=v.y || z!=v.z;
|
||||
}
|
||||
|
||||
Vec3<T> operator +(const Vec3<T> &v) const{
|
||||
return Vec3(x+v.x, y+v.y, z+v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator -(const Vec3<T> &v) const{
|
||||
return Vec3(x-v.x, y-v.y, z-v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator -() const{
|
||||
return Vec3(-x, -y, -z);
|
||||
}
|
||||
|
||||
Vec3<T> operator *(const Vec3<T> &v) const{
|
||||
return Vec3(x*v.x, y*v.y, z*v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator *(T s) const{
|
||||
return Vec3(x*s, y*s, z*s);
|
||||
}
|
||||
|
||||
Vec3<T> operator /(const Vec3<T> &v) const{
|
||||
return Vec3(x/v.x, y/v.y, z/v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator /(T s) const{
|
||||
return Vec3(x/s, y/s, z/s);
|
||||
}
|
||||
|
||||
Vec3<T> operator +=(const Vec3<T> &v){
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
z+=v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator -=(const Vec3<T> &v){
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
z-=v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> lerp(T t, const Vec3<T> &v) const{
|
||||
return *this + (v - *this) * t;
|
||||
}
|
||||
|
||||
T dot(const Vec3<T> &v) const{
|
||||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
|
||||
float dist(const Vec3<T> &v) const{
|
||||
return Vec3<T>(v-*this).length();
|
||||
}
|
||||
|
||||
float length() const{
|
||||
return static_cast<float>(sqrt(x*x + y*y + z*z));
|
||||
}
|
||||
|
||||
void normalize(){
|
||||
T m= length();
|
||||
x/= m;
|
||||
y/= m;
|
||||
z/= m;
|
||||
}
|
||||
|
||||
Vec3<T> getNormalized() const{
|
||||
T m= length();
|
||||
return Vec3<T>(x/m, y/m, z/m);
|
||||
}
|
||||
|
||||
Vec3<T> cross(const Vec3<T> &v) const{
|
||||
return Vec3<T>(
|
||||
this->y*v.z-this->z*v.y,
|
||||
this->z*v.x-this->x*v.z,
|
||||
this->x*v.y-this->y*v.x);
|
||||
}
|
||||
|
||||
Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2) const{
|
||||
Vec3<T> rv;
|
||||
rv= (p2-*this).cross(p1-*this);
|
||||
rv.normalize();
|
||||
return rv;
|
||||
}
|
||||
|
||||
Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2, const Vec3<T> &p3, const Vec3<T> &p4) const{
|
||||
Vec3<T> rv;
|
||||
|
||||
rv= this->normal(p1, p2);
|
||||
rv= rv + this->normal(p2, p3);
|
||||
rv= rv + this->normal(p3, p4);
|
||||
rv= rv + this->normal(p4, p1);
|
||||
rv.normalize();
|
||||
return rv;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Vec3<int> Vec3i;
|
||||
typedef Vec3<bool> Vec3b;
|
||||
typedef Vec3<char> Vec3c;
|
||||
typedef Vec3<float> Vec3f;
|
||||
typedef Vec3<double> Vec3d;
|
||||
|
||||
// =====================================================
|
||||
// class Vec4
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Vec4{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
public:
|
||||
Vec4(){
|
||||
};
|
||||
|
||||
explicit Vec4(T *p){
|
||||
this->x= p[0];
|
||||
this->y= p[1];
|
||||
this->z= p[2];
|
||||
this->w= p[3];
|
||||
}
|
||||
|
||||
explicit Vec4(T xyzw){
|
||||
this->x= xyzw;
|
||||
this->y= xyzw;
|
||||
this->z= xyzw;
|
||||
this->w= xyzw;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec4(const Vec4<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= v.w;
|
||||
}
|
||||
|
||||
Vec4(T x, T y, T z, T w){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
this->z= z;
|
||||
this->w= w;
|
||||
}
|
||||
|
||||
Vec4(Vec3<T> v, T w){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= w;
|
||||
}
|
||||
|
||||
explicit Vec4(Vec3<T> v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= 1;
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
bool operator ==(const Vec4<T> &v) const{
|
||||
return x==v.x && y==v.y && z==v.z && w==v.w;
|
||||
}
|
||||
|
||||
bool operator !=(const Vec4<T> &v) const{
|
||||
return x!=v.x || y!=v.y || z!=v.z || w!=v.w;
|
||||
}
|
||||
|
||||
Vec4<T> operator +(const Vec4<T> &v) const{
|
||||
return Vec4(x+v.x, y+v.y, z+v.z, w+v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator -(const Vec4<T> &v) const{
|
||||
return Vec4(x-v.x, y-v.y, z-v.z, w-v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator -() const{
|
||||
return Vec4(-x, -y, -z, -w);
|
||||
}
|
||||
|
||||
Vec4<T> operator *(const Vec4<T> &v) const{
|
||||
return Vec4(x*v.x, y*v.y, z*v.z, w*v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator *(T s) const{
|
||||
return Vec4(x*s, y*s, z*s, w*s);
|
||||
}
|
||||
|
||||
Vec4<T> operator /(const Vec4<T> &v) const{
|
||||
return Vec4(x/v.x, y/v.y, z/v.z, w/v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator /(T s) const{
|
||||
return Vec4(x/s, y/s, z/s, w/s);
|
||||
}
|
||||
|
||||
Vec4<T> operator +=(const Vec4<T> &v){
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
z+=v.z;
|
||||
w+=w.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator -=(const Vec4<T> &v){
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
z-=v.z;
|
||||
w-=w.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> lerp(T t, const Vec4<T> &v) const{
|
||||
return *this + (v - *this) *t;
|
||||
}
|
||||
|
||||
T dot(const Vec4<T> &v) const{
|
||||
return x*v.x + y*v.y + z*v.z + w*v.w;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec4<int> Vec4i;
|
||||
typedef Vec4<bool> Vec4b;
|
||||
typedef Vec4<char> Vec4c;
|
||||
typedef Vec4<float> Vec4f;
|
||||
typedef Vec4<double> Vec4d;
|
||||
|
||||
}} //enmd namespace
|
||||
|
||||
#endif
|
81
source/shared_lib/include/lua/lua_script.h
Normal file
81
source/shared_lib/include/lua/lua_script.h
Normal file
@@ -0,0 +1,81 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_LUA_LUASCRIPT_H_
|
||||
#define _SHARED_LUA_LUASCRIPT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <lua.hpp>
|
||||
|
||||
#include <vec.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
using Shared::Graphics::Vec2i;
|
||||
|
||||
namespace Shared{ namespace Lua{
|
||||
|
||||
typedef lua_State LuaHandle;
|
||||
typedef int(*LuaFunction)(LuaHandle*);
|
||||
|
||||
// =====================================================
|
||||
// class LuaScript
|
||||
// =====================================================
|
||||
|
||||
class LuaScript{
|
||||
private:
|
||||
LuaHandle *luaState;
|
||||
int argumentCount;
|
||||
|
||||
public:
|
||||
LuaScript();
|
||||
~LuaScript();
|
||||
|
||||
void loadCode(const string &code, const string &name);
|
||||
|
||||
void beginCall(const string& functionName);
|
||||
void endCall();
|
||||
|
||||
void registerFunction(LuaFunction luaFunction, const string &functionName);
|
||||
|
||||
private:
|
||||
string errorToString(int errorCode);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class LuaArguments
|
||||
// =====================================================
|
||||
|
||||
class LuaArguments{
|
||||
private:
|
||||
lua_State *luaState;
|
||||
int returnCount;
|
||||
|
||||
public:
|
||||
LuaArguments(lua_State *luaState);
|
||||
|
||||
int getInt(int argumentIndex) const;
|
||||
string getString(int argumentIndex) const;
|
||||
Vec2i getVec2i(int argumentIndex) const;
|
||||
int getReturnCount() const {return returnCount;}
|
||||
|
||||
void returnInt(int value);
|
||||
void returnString(const string &value);
|
||||
void returnVec2i(const Vec2i &value);
|
||||
|
||||
private:
|
||||
void throwLuaError(const string &message) const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
99
source/shared_lib/include/platform/posix/socket.h
Normal file
99
source/shared_lib/include/platform/posix/socket.h
Normal file
@@ -0,0 +1,99 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_SOCKET_H_
|
||||
#define _SHARED_PLATFORM_SOCKET_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class IP
|
||||
// =====================================================
|
||||
|
||||
class Ip{
|
||||
private:
|
||||
unsigned char bytes[4];
|
||||
|
||||
public:
|
||||
Ip();
|
||||
Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3);
|
||||
Ip(const string& ipString);
|
||||
|
||||
unsigned char getByte(int byteIndex) {return bytes[byteIndex];}
|
||||
string getString() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Socket
|
||||
// =====================================================
|
||||
|
||||
class Socket {
|
||||
protected:
|
||||
int sock;
|
||||
|
||||
public:
|
||||
Socket(int sock);
|
||||
Socket();
|
||||
~Socket();
|
||||
|
||||
int getDataToRead();
|
||||
int send(const void *data, int dataSize);
|
||||
int receive(void *data, int dataSize);
|
||||
int peek(void *data, int dataSize);
|
||||
|
||||
void setBlock(bool block);
|
||||
bool isReadable();
|
||||
bool isWritable();
|
||||
bool isConnected();
|
||||
|
||||
string getHostName() const;
|
||||
string getIp() const;
|
||||
|
||||
protected:
|
||||
static void throwException(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ClientSocket
|
||||
// =====================================================
|
||||
|
||||
class ClientSocket: public Socket{
|
||||
public:
|
||||
void connect(const Ip &ip, int port);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ServerSocket
|
||||
// =====================================================
|
||||
|
||||
class ServerSocket: public Socket{
|
||||
public:
|
||||
void bind(int port);
|
||||
void listen(int connectionQueueSize= SOMAXCONN);
|
||||
Socket *accept();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
55
source/shared_lib/include/platform/sdl/factory_repository.h
Normal file
55
source/shared_lib/include/platform/sdl/factory_repository.h
Normal file
@@ -0,0 +1,55 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_FACTORYREPOSITORY_H_
|
||||
#define _SHARED_PLATFORM_FACTORYREPOSITORY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "graphics_factory.h"
|
||||
#include "sound_factory.h"
|
||||
|
||||
#include "graphics_factory_gl.h"
|
||||
#include "sound_factory_openal.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
using Shared::Graphics::GraphicsFactory;
|
||||
using Shared::Sound::SoundFactory;
|
||||
using Shared::Graphics::Gl::GraphicsFactoryGl;
|
||||
using Shared::Sound::OpenAL::SoundFactoryOpenAL;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class FactoryRepository
|
||||
// =====================================================
|
||||
|
||||
class FactoryRepository{
|
||||
private:
|
||||
FactoryRepository(){};
|
||||
FactoryRepository(const FactoryRepository& );
|
||||
void operator=(const FactoryRepository& );
|
||||
|
||||
private:
|
||||
GraphicsFactoryGl graphicsFactoryGl;
|
||||
SoundFactoryOpenAL soundFactoryOpenAL;
|
||||
|
||||
public:
|
||||
static FactoryRepository &getInstance();
|
||||
|
||||
GraphicsFactory *getGraphicsFactory(const string &name);
|
||||
SoundFactory *getSoundFactory(const string &name);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
57
source/shared_lib/include/platform/sdl/gl_wrap.h
Normal file
57
source/shared_lib/include/platform/sdl/gl_wrap.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
#ifndef _SHARED_PLATFORM_GLWRAP_H_
|
||||
#define _SHARED_PLATFORM_GLWRAP_H_
|
||||
|
||||
#include <SDL.h>
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "font.h"
|
||||
#include "types.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
using Shared::Graphics::FontMetrics;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class PlatformContextGl
|
||||
// =====================================================
|
||||
|
||||
class PlatformContextGl {
|
||||
public:
|
||||
virtual ~PlatformContextGl() {}
|
||||
|
||||
virtual void init(int colorBits, int depthBits, int stencilBits);
|
||||
virtual void end();
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
DeviceContextHandle getHandle() const { return 0; }
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Global Fcs
|
||||
// =====================================================
|
||||
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
|
||||
const char *getPlatformExtensions(const PlatformContextGl *pcgl);
|
||||
void* getGlProcAddress(const char *procName);
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
7
source/shared_lib/include/platform/sdl/noimpl.h
Normal file
7
source/shared_lib/include/platform/sdl/noimpl.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _NOIMPL_H_
|
||||
#define _NOIMPL_H_
|
||||
|
||||
#define NOIMPL std::cerr << __PRETTY_FUNCTION__ << " not implemented.\n";
|
||||
|
||||
#endif
|
||||
|
29
source/shared_lib/include/platform/sdl/platform_main.h
Normal file
29
source/shared_lib/include/platform/sdl/platform_main.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
#ifndef _SHARED_PLATFORM_MAIN_H_
|
||||
#define _SHARED_PLATFORM_MAIN_H_
|
||||
|
||||
#include <SDL.h>
|
||||
#include <iostream>
|
||||
|
||||
#define MAIN_FUNCTION(X) int main(int argc, char **argv) \
|
||||
{ \
|
||||
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { \
|
||||
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
SDL_EnableUNICODE(1); \
|
||||
int result = X(argc, argv); \
|
||||
SDL_Quit(); \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#endif
|
107
source/shared_lib/include/platform/sdl/platform_util.h
Normal file
107
source/shared_lib/include/platform/sdl/platform_util.h
Normal file
@@ -0,0 +1,107 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
#ifndef _SHARED_PLATFORM_PLATFORMUTIL_H_
|
||||
#define _SHARED_PLATFORM_PLATFORMUTIL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::exception;
|
||||
|
||||
using Shared::Platform::int64;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class PerformanceTimer
|
||||
// =====================================================
|
||||
|
||||
class PerformanceTimer{
|
||||
private:
|
||||
Uint32 lastTicks;
|
||||
Uint32 updateTicks;
|
||||
|
||||
int times; // number of consecutive times
|
||||
int maxTimes; // maximum number consecutive times
|
||||
|
||||
public:
|
||||
void init(float fps, int maxTimes= -1);
|
||||
|
||||
bool isTime();
|
||||
void reset();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Chrono
|
||||
// =====================================================
|
||||
|
||||
class Chrono {
|
||||
private:
|
||||
Uint32 startCount;
|
||||
Uint32 accumCount;
|
||||
Uint32 freq;
|
||||
bool stopped;
|
||||
|
||||
public:
|
||||
Chrono();
|
||||
void start();
|
||||
void stop();
|
||||
int64 getMicros() const;
|
||||
int64 getMillis() const;
|
||||
int64 getSeconds() const;
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PlatformExceptionHandler
|
||||
// =====================================================
|
||||
|
||||
class PlatformExceptionHandler {
|
||||
public:
|
||||
virtual ~PlatformExceptionHandler() {}
|
||||
void install(string dumpFileName) {}
|
||||
virtual void handle()=0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
|
||||
void findAll(const string &path, vector<string> &results, bool cutExtension=false);
|
||||
|
||||
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
||||
void restoreVideoMode();
|
||||
|
||||
void message(string message);
|
||||
bool ask(string message);
|
||||
void exceptionMessage(const exception &excp);
|
||||
|
||||
int getScreenW();
|
||||
int getScreenH();
|
||||
|
||||
void sleep(int millis);
|
||||
|
||||
void showCursor(bool b);
|
||||
bool isKeyDown(int virtualKey);
|
||||
string getCommandLine();
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
26
source/shared_lib/include/platform/sdl/sdl_private.h
Normal file
26
source/shared_lib/include/platform/sdl/sdl_private.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
#ifndef _SHARED_PLATFORM_SDL_GLOBALS_H_
|
||||
#define _SHARED_PLATFORM_SDL_GLOBALS_H_
|
||||
|
||||
// This header contains things that should not be used outside the platform/sdl
|
||||
// directory
|
||||
|
||||
namespace Shared{ namespace Platform{ namespace Private{
|
||||
|
||||
extern bool shouldBeFullscreen;
|
||||
extern int ScreenWidth;
|
||||
extern int ScreenHeight;
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
67
source/shared_lib/include/platform/sdl/thread.h
Normal file
67
source/shared_lib/include/platform/sdl/thread.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_THREAD_H_
|
||||
#define _SHARED_PLATFORM_THREAD_H_
|
||||
|
||||
#include <SDL_thread.h>
|
||||
#include <SDL_mutex.h>
|
||||
|
||||
// =====================================================
|
||||
// class Thread
|
||||
// =====================================================
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
class Thread{
|
||||
public:
|
||||
enum Priority {
|
||||
pIdle = 0,
|
||||
pLow = 1,
|
||||
pNormal = 2,
|
||||
pHigh = 3,
|
||||
pRealTime = 4
|
||||
};
|
||||
|
||||
private:
|
||||
SDL_Thread* thread;
|
||||
|
||||
public:
|
||||
virtual ~Thread() {}
|
||||
|
||||
void start();
|
||||
virtual void execute()=0;
|
||||
void setPriority(Thread::Priority threadPriority);
|
||||
void suspend();
|
||||
void resume();
|
||||
|
||||
private:
|
||||
static int beginExecution(void *param);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Mutex
|
||||
// =====================================================
|
||||
|
||||
class Mutex{
|
||||
private:
|
||||
SDL_mutex* mutex;
|
||||
|
||||
public:
|
||||
Mutex();
|
||||
~Mutex();
|
||||
void p();
|
||||
void v();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
37
source/shared_lib/include/platform/sdl/types.h
Normal file
37
source/shared_lib/include/platform/sdl/types.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
#ifndef _SHARED_PLATFORM_TYPES_H_
|
||||
#define _SHARED_PLATFORM_TYPES_H_
|
||||
|
||||
#include <SDL_types.h>
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// These don't have a real meaning in the SDL port
|
||||
typedef void* WindowHandle;
|
||||
typedef void* DeviceContextHandle;
|
||||
typedef void* GlContextHandle;
|
||||
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
// don't use Sint8 here because that is defined as signed char
|
||||
// and some parts of the code do std::string str = (int8*) var;
|
||||
typedef char int8;
|
||||
typedef Uint8 uint8;
|
||||
typedef Sint16 int16;
|
||||
typedef Uint16 uint16;
|
||||
typedef Sint32 int32;
|
||||
typedef Uint32 uint32;
|
||||
typedef Sint64 int64;
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
144
source/shared_lib/include/platform/sdl/window.h
Normal file
144
source/shared_lib/include/platform/sdl/window.h
Normal file
@@ -0,0 +1,144 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_WINDOW_H_
|
||||
#define _SHARED_PLATFORM_WINDOW_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
class Timer;
|
||||
class PlatformContextGl;
|
||||
|
||||
enum MouseButton{
|
||||
mbLeft,
|
||||
mbRight,
|
||||
mbCenter
|
||||
};
|
||||
|
||||
enum SizeState{
|
||||
ssMaximized,
|
||||
ssMinimized,
|
||||
ssRestored
|
||||
};
|
||||
|
||||
// keycode constants (unfortunately designed after DirectInput and therefore not
|
||||
// very specific)
|
||||
// They also have to fit into a char. The positive numbers seem to be equal
|
||||
// to ascii, for the rest we have to find sensefull mappings from SDL (which is
|
||||
// alot more fine grained like left/right control instead of just control...)
|
||||
const char vkAdd = -1;
|
||||
const char vkSubtract = -2;
|
||||
const char vkAlt = -3;
|
||||
const char vkControl = -4;
|
||||
const char vkShift = -5;
|
||||
const char vkEscape = -6;
|
||||
const char vkUp = -7;
|
||||
const char vkLeft = -8;
|
||||
const char vkRight = -9;
|
||||
const char vkDown = -10;
|
||||
const char vkReturn = -11;
|
||||
const char vkBack = -12;
|
||||
|
||||
struct MouseState{
|
||||
bool leftMouse;
|
||||
bool rightMouse;
|
||||
bool centerMouse;
|
||||
};
|
||||
|
||||
enum WindowStyle{
|
||||
wsFullscreen,
|
||||
wsWindowedFixed,
|
||||
wsWindowedResizable
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Window
|
||||
// =====================================================
|
||||
|
||||
class Window {
|
||||
private:
|
||||
Uint32 lastMouseDown[3];
|
||||
int lastMouseX[3];
|
||||
int lastMouseY[3];
|
||||
|
||||
protected:
|
||||
int w, h;
|
||||
|
||||
public:
|
||||
static bool handleEvent();
|
||||
|
||||
Window();
|
||||
virtual ~Window();
|
||||
|
||||
WindowHandle getHandle() {return 0;}
|
||||
string getText();
|
||||
int getX() { return 0; }
|
||||
int getY() { return 0; }
|
||||
int getW() { return w; }
|
||||
int getH() { return h; }
|
||||
|
||||
//component state
|
||||
int getClientW() { return getW(); }
|
||||
int getClientH() { return getH(); }
|
||||
float getAspect();
|
||||
|
||||
//object state
|
||||
void setText(string text);
|
||||
void setStyle(WindowStyle windowStyle);
|
||||
void setSize(int w, int h);
|
||||
void setPos(int x, int y);
|
||||
void setEnabled(bool enabled);
|
||||
void setVisible(bool visible);
|
||||
|
||||
//misc
|
||||
void create();
|
||||
void destroy();
|
||||
void minimize();
|
||||
|
||||
protected:
|
||||
virtual void eventCreate(){}
|
||||
virtual void eventMouseDown(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseUp(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseMove(int x, int y, const MouseState* mouseState){}
|
||||
virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventKeyDown(char key){}
|
||||
virtual void eventKeyUp(char key){}
|
||||
virtual void eventKeyPress(char c){}
|
||||
virtual void eventResize(){};
|
||||
virtual void eventPaint(){}
|
||||
virtual void eventTimer(int timerId){}
|
||||
virtual void eventActivate(bool activated){};
|
||||
virtual void eventResize(SizeState sizeState){};
|
||||
virtual void eventMenu(int menuId){}
|
||||
virtual void eventClose(){};
|
||||
virtual void eventDestroy(){};
|
||||
|
||||
private:
|
||||
/// needed to detect double clicks
|
||||
void handleMouseDown(SDL_Event event);
|
||||
|
||||
static MouseButton getMouseButton(int sdlButton);
|
||||
static char getKey(SDL_keysym keysym);
|
||||
static void toggleFullscreen();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
38
source/shared_lib/include/platform/sdl/window_gl.h
Normal file
38
source/shared_lib/include/platform/sdl/window_gl.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_WINDOWGL_H_
|
||||
#define _SHARED_PLATFORM_WINDOWGL_H_
|
||||
|
||||
#include "context_gl.h"
|
||||
#include "window.h"
|
||||
|
||||
using Shared::Graphics::Gl::ContextGl;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class WindowGl
|
||||
// =====================================================
|
||||
|
||||
class WindowGl: public Window{
|
||||
private:
|
||||
ContextGl context;
|
||||
|
||||
public:
|
||||
void initGl(int colorBits, int depthBits, int stencilBits);
|
||||
void makeCurrentGl();
|
||||
void swapBuffersGl();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,58 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_FACTORYREPOSITORY_H_
|
||||
#define _SHARED_PLATFORM_FACTORYREPOSITORY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "graphics_factory.h"
|
||||
#include "sound_factory.h"
|
||||
|
||||
#include "graphics_factory_gl.h"
|
||||
#include "graphics_factory_gl2.h"
|
||||
#include "sound_factory_ds8.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
using Shared::Graphics::GraphicsFactory;
|
||||
using Shared::Sound::SoundFactory;
|
||||
using Shared::Graphics::Gl::GraphicsFactoryGl;
|
||||
using Shared::Graphics::Gl::GraphicsFactoryGl2;
|
||||
using Shared::Sound::Ds8::SoundFactoryDs8;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class FactoryRepository
|
||||
// =====================================================
|
||||
|
||||
class FactoryRepository{
|
||||
private:
|
||||
FactoryRepository(){};
|
||||
FactoryRepository(FactoryRepository &);
|
||||
void operator=(FactoryRepository &);
|
||||
|
||||
private:
|
||||
GraphicsFactoryGl graphicsFactoryGl;
|
||||
GraphicsFactoryGl2 graphicsFactoryGl2;
|
||||
SoundFactoryDs8 soundFactoryDs8;
|
||||
|
||||
public:
|
||||
static FactoryRepository &getInstance();
|
||||
|
||||
GraphicsFactory *getGraphicsFactory(const string &name);
|
||||
SoundFactory *getSoundFactory(const string &name);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
65
source/shared_lib/include/platform/win32/gl_wrap.h
Normal file
65
source/shared_lib/include/platform/win32/gl_wrap.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_GLWRAP_H_
|
||||
#define _SHARED_PLATFORM_GLWRAP_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <gl.h>
|
||||
#include <glu.h>
|
||||
#include <glprocs.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "font.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
#define GLEST_GLPROC(X, Y) inline X( static a= wglGetProcAddress(a); return a;)
|
||||
|
||||
using std::string;
|
||||
|
||||
using Shared::Graphics::FontMetrics;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class PlatformContextGl
|
||||
// =====================================================
|
||||
|
||||
class PlatformContextGl{
|
||||
protected:
|
||||
DeviceContextHandle dch;
|
||||
GlContextHandle glch;
|
||||
|
||||
public:
|
||||
virtual void init(int colorBits, int depthBits, int stencilBits);
|
||||
virtual void end();
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
DeviceContextHandle getHandle() const {return dch;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Global Fcs
|
||||
// =====================================================
|
||||
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
|
||||
const char *getPlatformExtensions(const PlatformContextGl *pcgl);
|
||||
PROC getGlProcAddress(const char *procName);
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,23 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_DEFINITIONS_H_
|
||||
#define _SHARED_PLATFORM_DEFINITIONS_H_
|
||||
|
||||
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
19
source/shared_lib/include/platform/win32/platform_main.h
Normal file
19
source/shared_lib/include/platform/win32/platform_main.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_MAIN_H_
|
||||
#define _SHARED_PLATFORM_MAIN_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define MAIN_FUNCTION(X) int main(int argc, char *argv[]){return X(argc, argv);}
|
||||
|
||||
#endif
|
90
source/shared_lib/include/platform/win32/platform_menu.h
Normal file
90
source/shared_lib/include/platform/win32/platform_menu.h
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef _SHARED_PLATFORM_POPUPMENU_H_
|
||||
#define _SHARED_PLATFORM_POPUPMENU_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
class Menu;
|
||||
|
||||
// =====================================================
|
||||
// class MenuBase
|
||||
// =====================================================
|
||||
|
||||
class MenuBase{
|
||||
private:
|
||||
static int nextId;
|
||||
|
||||
protected:
|
||||
int id;
|
||||
string text;
|
||||
HMENU handle;
|
||||
|
||||
public:
|
||||
void init(const string &text="");
|
||||
virtual ~MenuBase(){};
|
||||
|
||||
virtual void create(Menu *parent)= 0;
|
||||
virtual void destroy(){};
|
||||
|
||||
int getId() const {return id;}
|
||||
const string &getText() const {return text;}
|
||||
HMENU getHandle() const {return handle;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Menu
|
||||
// =====================================================
|
||||
|
||||
class Menu: public MenuBase{
|
||||
private:
|
||||
typedef vector<MenuBase*> MenuChildren;
|
||||
|
||||
private:
|
||||
MenuChildren children;
|
||||
|
||||
public:
|
||||
virtual void create(Menu *parent= NULL);
|
||||
virtual void destroy();
|
||||
|
||||
int getChildCount() const {return children.size();}
|
||||
MenuBase *getChild(int i) const {return children[i];}
|
||||
|
||||
void addChild(MenuBase *menu) {children.push_back(menu);}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class MenuItem
|
||||
// =====================================================
|
||||
|
||||
class MenuItem: public MenuBase{
|
||||
private:
|
||||
bool isChecked;
|
||||
Menu *parent;
|
||||
|
||||
public:
|
||||
virtual void create(Menu *parent);
|
||||
|
||||
void setChecked(bool checked);
|
||||
|
||||
Menu *getParent() const {return parent;}
|
||||
bool getChecked() const {return isChecked;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class MenuSeparator
|
||||
// =====================================================
|
||||
|
||||
class MenuSeparator: public MenuBase{
|
||||
public:
|
||||
virtual void create(Menu *parent);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
118
source/shared_lib/include/platform/win32/platform_util.h
Normal file
118
source/shared_lib/include/platform/win32/platform_util.h
Normal file
@@ -0,0 +1,118 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_PLATFORMUTIL_H_
|
||||
#define _SHARED_PLATFORM_PLATFORMUTIL_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::exception;
|
||||
|
||||
using Shared::Platform::int64;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class PerformanceTimer
|
||||
// =====================================================
|
||||
|
||||
class PerformanceTimer{
|
||||
private:
|
||||
int64 thisTicks;
|
||||
int64 lastTicks;
|
||||
int64 updateTicks;
|
||||
|
||||
int times; // number of consecutive times
|
||||
int maxTimes; // maximum number consecutive times
|
||||
|
||||
public:
|
||||
void init(int fps, int maxTimes= -1);
|
||||
|
||||
bool isTime();
|
||||
void reset();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Chrono
|
||||
// =====================================================
|
||||
|
||||
class Chrono{
|
||||
private:
|
||||
int64 startCount;
|
||||
int64 accumCount;
|
||||
int64 freq;
|
||||
bool stopped;
|
||||
|
||||
public:
|
||||
Chrono();
|
||||
void start();
|
||||
void stop();
|
||||
int64 getMicros() const;
|
||||
int64 getMillis() const;
|
||||
int64 getSeconds() const;
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PlatformExceptionHandler
|
||||
// =====================================================
|
||||
|
||||
LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS *ExceptionInfo);
|
||||
|
||||
class PlatformExceptionHandler{
|
||||
private:
|
||||
static PlatformExceptionHandler *thisPointer;
|
||||
|
||||
private:
|
||||
static LONG WINAPI handler(LPEXCEPTION_POINTERS pointers);
|
||||
string dumpFileName;
|
||||
|
||||
public:
|
||||
void install(string dumpFileName);
|
||||
virtual void handle()=0;
|
||||
static string codeToStr(DWORD code);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
|
||||
void findAll(const string &path, vector<string> &results, bool cutExtension=false);
|
||||
|
||||
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
||||
void restoreVideoMode();
|
||||
|
||||
void message(string message);
|
||||
bool ask(string message);
|
||||
void exceptionMessage(const exception &excp);
|
||||
|
||||
int getScreenW();
|
||||
int getScreenH();
|
||||
|
||||
void sleep(int millis);
|
||||
|
||||
void showCursor(bool b);
|
||||
bool isKeyDown(int virtualKey);
|
||||
string getCommandLine();
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
99
source/shared_lib/include/platform/win32/socket.h
Normal file
99
source/shared_lib/include/platform/win32/socket.h
Normal file
@@ -0,0 +1,99 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_SOCKET_H_
|
||||
#define _SHARED_PLATFORM_SOCKET_H_
|
||||
|
||||
#include <string>
|
||||
#include <winsock.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class IP
|
||||
// =====================================================
|
||||
|
||||
class Ip{
|
||||
private:
|
||||
unsigned char bytes[4];
|
||||
|
||||
public:
|
||||
Ip();
|
||||
Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3);
|
||||
Ip(const string& ipString);
|
||||
|
||||
unsigned char getByte(int byteIndex) {return bytes[byteIndex];}
|
||||
string getString() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Socket
|
||||
// =====================================================
|
||||
|
||||
class Socket{
|
||||
private:
|
||||
class SocketManager{
|
||||
public:
|
||||
SocketManager();
|
||||
~SocketManager();
|
||||
};
|
||||
|
||||
protected:
|
||||
static SocketManager socketManager;
|
||||
SOCKET sock;
|
||||
|
||||
public:
|
||||
Socket(SOCKET sock);
|
||||
Socket();
|
||||
~Socket();
|
||||
|
||||
int getDataToRead();
|
||||
int send(const void *data, int dataSize);
|
||||
int receive(void *data, int dataSize);
|
||||
int peek(void *data, int dataSize);
|
||||
|
||||
void setBlock(bool block);
|
||||
bool isReadable();
|
||||
bool isWritable();
|
||||
bool isConnected();
|
||||
|
||||
string getHostName() const;
|
||||
string getIp() const;
|
||||
|
||||
protected:
|
||||
static void throwException(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ClientSocket
|
||||
// =====================================================
|
||||
|
||||
class ClientSocket: public Socket{
|
||||
public:
|
||||
void connect(const Ip &ip, int port);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ServerSocket
|
||||
// =====================================================
|
||||
|
||||
class ServerSocket: public Socket{
|
||||
public:
|
||||
void bind(int port);
|
||||
void listen(int connectionQueueSize= SOMAXCONN);
|
||||
Socket *accept();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
69
source/shared_lib/include/platform/win32/thread.h
Normal file
69
source/shared_lib/include/platform/win32/thread.h
Normal file
@@ -0,0 +1,69 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_THREAD_H_
|
||||
#define _SHARED_PLATFORM_THREAD_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// =====================================================
|
||||
// class Thread
|
||||
// =====================================================
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
typedef LPTHREAD_START_ROUTINE ThreadFunction;
|
||||
typedef DWORD ThreadId;
|
||||
|
||||
class Thread{
|
||||
public:
|
||||
enum Priority{
|
||||
pIdle= THREAD_PRIORITY_IDLE,
|
||||
pLow= THREAD_PRIORITY_BELOW_NORMAL,
|
||||
pNormal= THREAD_PRIORITY_NORMAL,
|
||||
pHigh= THREAD_PRIORITY_ABOVE_NORMAL,
|
||||
pRealTime= THREAD_PRIORITY_TIME_CRITICAL
|
||||
};
|
||||
|
||||
private:
|
||||
HANDLE threadHandle;
|
||||
static const ThreadId threadIdBase= 1000;
|
||||
static ThreadId nextThreadId;
|
||||
|
||||
public:
|
||||
void start();
|
||||
virtual void execute()=0;
|
||||
void setPriority(Thread::Priority threadPriority);
|
||||
void suspend();
|
||||
void resume();
|
||||
|
||||
private:
|
||||
static DWORD WINAPI beginExecution(void *param);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Mutex
|
||||
// =====================================================
|
||||
|
||||
class Mutex{
|
||||
private:
|
||||
CRITICAL_SECTION mutex;
|
||||
|
||||
public:
|
||||
Mutex();
|
||||
~Mutex();
|
||||
void p();
|
||||
void v();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
35
source/shared_lib/include/platform/win32/types.h
Normal file
35
source/shared_lib/include/platform/win32/types.h
Normal file
@@ -0,0 +1,35 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_TYPES_H_
|
||||
#define _SHARED_PLATFORM_TYPES_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
typedef HWND WindowHandle;
|
||||
typedef HDC DeviceContextHandle;
|
||||
typedef HGLRC GlContextHandle;
|
||||
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
typedef char int8;
|
||||
typedef unsigned char uint8;
|
||||
typedef short int int16;
|
||||
typedef unsigned short int uint16;
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef long long int64;
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
158
source/shared_lib/include/platform/win32/window.h
Normal file
158
source/shared_lib/include/platform/win32/window.h
Normal file
@@ -0,0 +1,158 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_WINDOW_H_
|
||||
#define _SHARED_PLATFORM_WINDOW_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "types.h"
|
||||
#include "platform_menu.h"
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
class Timer;
|
||||
class PlatformContextGl;
|
||||
|
||||
enum MouseButton{
|
||||
mbLeft,
|
||||
mbRight,
|
||||
mbCenter
|
||||
};
|
||||
|
||||
enum SizeState{
|
||||
ssMaximized,
|
||||
ssMinimized,
|
||||
ssRestored
|
||||
};
|
||||
|
||||
const int vkAdd= VK_ADD;
|
||||
const int vkSubtract= VK_SUBTRACT;
|
||||
const int vkAlt= VK_MENU;
|
||||
const int vkControl= VK_CONTROL;
|
||||
const int vkShift= VK_SHIFT;
|
||||
const int vkEscape= VK_ESCAPE;
|
||||
const int vkUp= VK_UP;
|
||||
const int vkLeft= VK_LEFT;
|
||||
const int vkRight= VK_RIGHT;
|
||||
const int vkDown= VK_DOWN;
|
||||
const int vkReturn= VK_RETURN;
|
||||
const int vkBack= VK_BACK;
|
||||
const int vkDelete= VK_DELETE;
|
||||
const int vkF1= VK_F1;
|
||||
|
||||
struct MouseState{
|
||||
bool leftMouse;
|
||||
bool rightMouse;
|
||||
bool centerMouse;
|
||||
};
|
||||
|
||||
enum WindowStyle{
|
||||
wsFullscreen,
|
||||
wsWindowedFixed,
|
||||
wsWindowedResizeable
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Window
|
||||
// =====================================================
|
||||
|
||||
class Window{
|
||||
private:
|
||||
typedef map<WindowHandle, Window*> WindowMap;
|
||||
|
||||
private:
|
||||
static const DWORD fullscreenStyle;
|
||||
static const DWORD windowedFixedStyle;
|
||||
static const DWORD windowedResizeableStyle;
|
||||
|
||||
static int nextClassName;
|
||||
static WindowMap createdWindows;
|
||||
|
||||
protected:
|
||||
WindowHandle handle;
|
||||
WindowStyle windowStyle;
|
||||
string text;
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
string className;
|
||||
DWORD style;
|
||||
DWORD exStyle;
|
||||
bool ownDc;
|
||||
|
||||
public:
|
||||
static bool handleEvent();
|
||||
|
||||
//contructor & destructor
|
||||
Window();
|
||||
virtual ~Window();
|
||||
|
||||
WindowHandle getHandle() {return handle;}
|
||||
string getText();
|
||||
int getX() {return x;}
|
||||
int getY() {return y;}
|
||||
int getW() {return w;}
|
||||
int getH() {return h;}
|
||||
|
||||
//component state
|
||||
int getClientW();
|
||||
int getClientH();
|
||||
float getAspect();
|
||||
|
||||
//object state
|
||||
void setText(string text);
|
||||
void setStyle(WindowStyle windowStyle);
|
||||
void setSize(int w, int h);
|
||||
void setPos(int x, int y);
|
||||
void setEnabled(bool enabled);
|
||||
void setVisible(bool visible);
|
||||
|
||||
//misc
|
||||
void create();
|
||||
void minimize();
|
||||
void maximize();
|
||||
void restore();
|
||||
void showPopupMenu(Menu *menu, int x, int y);
|
||||
void destroy();
|
||||
|
||||
protected:
|
||||
virtual void eventCreate(){}
|
||||
virtual void eventMouseDown(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseUp(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventMouseMove(int x, int y, const MouseState *mouseState){}
|
||||
virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton){}
|
||||
virtual void eventKeyDown(char key){}
|
||||
virtual void eventKeyUp(char key){}
|
||||
virtual void eventKeyPress(char c){};
|
||||
virtual void eventResize(){};
|
||||
virtual void eventPaint(){}
|
||||
virtual void eventActivate(bool activated){};
|
||||
virtual void eventResize(SizeState sizeState){};
|
||||
virtual void eventMenu(int menuId){}
|
||||
virtual void eventClose(){};
|
||||
virtual void eventDestroy(){};
|
||||
|
||||
private:
|
||||
static LRESULT CALLBACK eventRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static int getNextClassName();
|
||||
void registerWindow(WNDPROC wndProc= NULL);
|
||||
void createWindow(LPVOID creationData= NULL);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
38
source/shared_lib/include/platform/win32/window_gl.h
Normal file
38
source/shared_lib/include/platform/win32/window_gl.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_WINDOWGL_H_
|
||||
#define _SHARED_PLATFORM_WINDOWGL_H_
|
||||
|
||||
#include "context_gl.h"
|
||||
#include "window.h"
|
||||
|
||||
using Shared::Graphics::Gl::ContextGl;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class WindowGl
|
||||
// =====================================================
|
||||
|
||||
class WindowGl: public Window{
|
||||
protected:
|
||||
ContextGl context;
|
||||
|
||||
public:
|
||||
void initGl(int colorBits, int depthBits, int stencilBits);
|
||||
void makeCurrentGl();
|
||||
void swapBuffersGl();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
31
source/shared_lib/include/sound/ds8/sound_factory_ds8.h
Normal file
31
source/shared_lib/include/sound/ds8/sound_factory_ds8.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDFACTORYDS8_H_
|
||||
#define _SHARED_SOUND_SOUNDFACTORYDS8_H_
|
||||
|
||||
#include "sound_factory.h"
|
||||
#include "sound_player_ds8.h"
|
||||
|
||||
namespace Shared{ namespace Sound{ namespace Ds8{
|
||||
|
||||
// =====================================================
|
||||
// class SoundFactoryDs8
|
||||
// =====================================================
|
||||
|
||||
class SoundFactoryDs8: public SoundFactory{
|
||||
public:
|
||||
virtual SoundPlayer *newSoundPlayer() {return new SoundPlayerDs8();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
135
source/shared_lib/include/sound/ds8/sound_player_ds8.h
Normal file
135
source/shared_lib/include/sound/ds8/sound_player_ds8.h
Normal file
@@ -0,0 +1,135 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDPLAYERDS8_H_
|
||||
#define _SHARED_SOUND_SOUNDPLAYERDS8_H_
|
||||
|
||||
#include "sound_player.h"
|
||||
#include "platform_util.h"
|
||||
|
||||
#include <dsound.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
|
||||
namespace Shared{ namespace Sound{ namespace Ds8{
|
||||
|
||||
// =====================================================
|
||||
// class SoundBuffer
|
||||
// =====================================================
|
||||
|
||||
class SoundBuffer{
|
||||
protected:
|
||||
IDirectSoundBuffer8 *dsBuffer;
|
||||
Sound *sound;
|
||||
DWORD size;
|
||||
|
||||
public:
|
||||
SoundBuffer();
|
||||
virtual ~SoundBuffer(){};
|
||||
virtual void end()=0;
|
||||
|
||||
IDirectSoundBuffer8 *getDsBuffer() const {return dsBuffer;}
|
||||
Sound *getSound() const {return sound;}
|
||||
|
||||
void setDsBuffer(IDirectSoundBuffer8 *dsBuffer) {this->dsBuffer= dsBuffer;}
|
||||
void setSound(IDirectSound8 *dsObject, Sound *sound) {this->sound= sound;}
|
||||
|
||||
bool isFree();
|
||||
bool isReady();
|
||||
|
||||
protected:
|
||||
void createDsBuffer(IDirectSound8 *dsObject);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class StaticSoundBuffer
|
||||
// =====================================================
|
||||
|
||||
class StaticSoundBuffer: public SoundBuffer{
|
||||
public:
|
||||
StaticSound *getStaticSound() const {return static_cast<StaticSound*>(sound);}
|
||||
void init(IDirectSound8 *dsObject, Sound *sound);
|
||||
void end();
|
||||
void play();
|
||||
private:
|
||||
void fillDsBuffer();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class StrSoundBuffer
|
||||
// =====================================================
|
||||
|
||||
class StrSoundBuffer: public SoundBuffer{
|
||||
private:
|
||||
enum State{sFree, sFadingOn, sPlaying, sFadingOff, sStopped};
|
||||
|
||||
private:
|
||||
DWORD lastPlayCursor;
|
||||
State state;
|
||||
Chrono chrono; //delay-fade chrono
|
||||
int64 fade; //fade on fade off delay
|
||||
|
||||
public:
|
||||
StrSoundBuffer();
|
||||
StrSound *getStrSound() const {return static_cast<StrSound*>(sound);}
|
||||
|
||||
void init(IDirectSound8 *dsObject, Sound *sound, uint32 strBufferSize);
|
||||
void end();
|
||||
void play(int64 fadeOn);
|
||||
void update();
|
||||
void stop(int64 fadeOff);
|
||||
|
||||
|
||||
private:
|
||||
void fillDsBuffer();
|
||||
void refreshDsBuffer();
|
||||
void readChunk(void *writePointer, uint32 size);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SoundPlayerDs8
|
||||
//
|
||||
/// SoundPlayer implementation using Direct Sound 8
|
||||
// =====================================================
|
||||
|
||||
class SoundPlayerDs8: public SoundPlayer{
|
||||
private:
|
||||
IDirectSound8 *dsObject;
|
||||
vector<StaticSoundBuffer> staticSoundBuffers;
|
||||
vector<StrSoundBuffer> strSoundBuffers;
|
||||
SoundPlayerParams params;
|
||||
|
||||
public:
|
||||
SoundPlayerDs8();
|
||||
virtual void init(const SoundPlayerParams *params);
|
||||
virtual void end();
|
||||
virtual void play(StaticSound *staticSound);
|
||||
virtual void play(StrSound *strSound, int64 fadeOn=0);
|
||||
virtual void stop(StrSound *strSound, int64 fadeOff=0);
|
||||
virtual void stopAllSounds();
|
||||
virtual void updateStreams(); //updates str buffers if needed
|
||||
|
||||
private:
|
||||
bool findStaticBuffer(Sound *sound, int *bufferIndex);
|
||||
bool findStrBuffer(Sound *sound, int *bufferIndex);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
|
||||
long dsVolume(float floatVolume);
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -0,0 +1,28 @@
|
||||
//This file is part of Glest Shared Library (www.glest.org)
|
||||
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
|
||||
//You can redistribute this code and/or modify it under
|
||||
//the terms of the GNU General Public License as published by the Free Software
|
||||
//Foundation; either version 2 of the License, or (at your option) any later
|
||||
//version.
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDFACTORYSDL_H_
|
||||
#define _SHARED_SOUND_SOUNDFACTORYSDL_H_
|
||||
|
||||
#include "sound_factory.h"
|
||||
#include "sound_player_openal.h"
|
||||
|
||||
namespace Shared{ namespace Sound{ namespace OpenAL{
|
||||
|
||||
// ===============================
|
||||
// class SoundFactoryOpenAL
|
||||
// ===============================
|
||||
|
||||
class SoundFactoryOpenAL : public SoundFactory{
|
||||
public:
|
||||
virtual SoundPlayer* newSoundPlayer() {return new SoundPlayerOpenAL();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
125
source/shared_lib/include/sound/openal/sound_player_openal.h
Normal file
125
source/shared_lib/include/sound/openal/sound_player_openal.h
Normal file
@@ -0,0 +1,125 @@
|
||||
//This file is part of Glest Shared Library (www.glest.org)
|
||||
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
|
||||
//You can redistribute this code and/or modify it under
|
||||
//the terms of the GNU General Public License as published by the Free Software
|
||||
//Foundation; either version 2 of the License, or (at your option) any later
|
||||
//version.
|
||||
#ifndef _SHARED_SOUND_SOUNDPLAYEROPENAL_H_
|
||||
#define _SHARED_SOUND_SOUNDPLAYEROPENAL_H_
|
||||
|
||||
#include "sound_player.h"
|
||||
#include "platform_util.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
|
||||
namespace Shared{ namespace Sound{ namespace OpenAL{
|
||||
|
||||
class SoundSource {
|
||||
public:
|
||||
SoundSource();
|
||||
virtual ~SoundSource();
|
||||
|
||||
bool playing();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
friend class SoundPlayerOpenAL;
|
||||
ALenum getFormat(Sound* sound);
|
||||
|
||||
ALuint source;
|
||||
};
|
||||
|
||||
class StaticSoundSource : public SoundSource {
|
||||
public:
|
||||
StaticSoundSource();
|
||||
virtual ~StaticSoundSource();
|
||||
|
||||
void play(StaticSound* sound);
|
||||
|
||||
protected:
|
||||
friend class SoundPlayerOpenAL;
|
||||
bool bufferAllocated;
|
||||
ALuint buffer;
|
||||
};
|
||||
|
||||
class StreamSoundSource : public SoundSource {
|
||||
public:
|
||||
StreamSoundSource();
|
||||
virtual ~StreamSoundSource();
|
||||
|
||||
void play(StrSound* sound, int64 fade);
|
||||
void update();
|
||||
void stop();
|
||||
void stop(int64 fade);
|
||||
|
||||
protected:
|
||||
friend class SoundPlayerOpenAL;
|
||||
static const size_t STREAMBUFFERSIZE = 1024 * 500;
|
||||
static const size_t STREAMFRAGMENTS = 5;
|
||||
static const size_t STREAMFRAGMENTSIZE
|
||||
= STREAMBUFFERSIZE / STREAMFRAGMENTS;
|
||||
|
||||
bool fillBufferAndQueue(ALuint buffer);
|
||||
|
||||
StrSound* sound;
|
||||
ALuint buffers[STREAMFRAGMENTS];
|
||||
ALenum format;
|
||||
|
||||
enum FadeState { NoFading, FadingOn, FadingOff };
|
||||
FadeState fadeState;
|
||||
Chrono chrono; // delay-fade chrono
|
||||
int64 fade;
|
||||
};
|
||||
|
||||
// ==============================================================
|
||||
// class SoundPlayerSDL
|
||||
//
|
||||
/// SoundPlayer implementation using SDL_mixer
|
||||
// ==============================================================
|
||||
|
||||
class SoundPlayerOpenAL : public SoundPlayer {
|
||||
public:
|
||||
SoundPlayerOpenAL();
|
||||
virtual ~SoundPlayerOpenAL();
|
||||
virtual void init(const SoundPlayerParams *params);
|
||||
virtual void end();
|
||||
virtual void play(StaticSound *staticSound);
|
||||
virtual void play(StrSound *strSound, int64 fadeOn=0);
|
||||
virtual void stop(StrSound *strSound, int64 fadeOff=0);
|
||||
virtual void stopAllSounds();
|
||||
virtual void updateStreams(); //updates str buffers if needed
|
||||
|
||||
private:
|
||||
friend class SoundSource;
|
||||
friend class StaticSoundSource;
|
||||
friend class StreamSoundSource;
|
||||
|
||||
void printOpenALInfo();
|
||||
|
||||
StaticSoundSource* findStaticSoundSource();
|
||||
StreamSoundSource* findStreamSoundSource();
|
||||
void checkAlcError(const char* message);
|
||||
static void checkAlError(const char* message);
|
||||
|
||||
ALCdevice* device;
|
||||
ALCcontext* context;
|
||||
|
||||
typedef std::vector<StaticSoundSource*> StaticSoundSources;
|
||||
StaticSoundSources staticSources;
|
||||
typedef std::vector<StreamSoundSource*> StreamSoundSources;
|
||||
StreamSoundSources streamSources;
|
||||
|
||||
SoundPlayerParams params;
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
||||
|
109
source/shared_lib/include/sound/sound.h
Normal file
109
source/shared_lib/include/sound/sound.h
Normal file
@@ -0,0 +1,109 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUND_H_
|
||||
#define _SHARED_SOUND_SOUND_H_
|
||||
|
||||
#include <string>
|
||||
#include "sound_file_loader.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::Platform;
|
||||
|
||||
namespace Shared{ namespace Sound{
|
||||
|
||||
// =====================================================
|
||||
// class SoundInfo
|
||||
// =====================================================
|
||||
|
||||
class SoundInfo{
|
||||
private:
|
||||
uint32 channels;
|
||||
uint32 samplesPerSecond;
|
||||
uint32 bitsPerSample;
|
||||
uint32 size;
|
||||
|
||||
public:
|
||||
SoundInfo();
|
||||
virtual ~SoundInfo(){};
|
||||
|
||||
uint32 getChannels() const {return channels;}
|
||||
uint32 getSamplesPerSecond() const {return samplesPerSecond;}
|
||||
uint32 getBitsPerSample() const {return bitsPerSample;}
|
||||
uint32 getSize() const {return size;}
|
||||
|
||||
void setChannels(uint32 channels) {this->channels= channels;}
|
||||
void setsamplesPerSecond(uint32 samplesPerSecond) {this->samplesPerSecond= samplesPerSecond;}
|
||||
void setBitsPerSample(uint32 bitsPerSample) {this->bitsPerSample= bitsPerSample;}
|
||||
void setSize(uint32 size) {this->size= size;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Sound
|
||||
// =====================================================
|
||||
|
||||
class Sound{
|
||||
protected:
|
||||
SoundFileLoader *soundFileLoader;
|
||||
SoundInfo info;
|
||||
float volume;
|
||||
|
||||
public:
|
||||
Sound();
|
||||
virtual ~Sound(){};
|
||||
|
||||
const SoundInfo *getInfo() const {return &info;}
|
||||
float getVolume() const {return volume;}
|
||||
|
||||
void setVolume(float volume) {this->volume= volume;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class StaticSound
|
||||
// =====================================================
|
||||
|
||||
class StaticSound: public Sound{
|
||||
private:
|
||||
int8 * samples;
|
||||
|
||||
public:
|
||||
StaticSound();
|
||||
virtual ~StaticSound();
|
||||
|
||||
int8 *getSamples() const {return samples;}
|
||||
|
||||
void load(const string &path);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class StrSound
|
||||
// =====================================================
|
||||
|
||||
class StrSound: public Sound{
|
||||
private:
|
||||
StrSound *next;
|
||||
|
||||
public:
|
||||
StrSound();
|
||||
virtual ~StrSound();
|
||||
|
||||
StrSound *getNext() const {return next;}
|
||||
void setNext(StrSound *next) {this->next= next;}
|
||||
|
||||
void open(const string &path);
|
||||
uint32 read(int8 *samples, uint32 size);
|
||||
void close();
|
||||
void restart();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
31
source/shared_lib/include/sound/sound_factory.h
Normal file
31
source/shared_lib/include/sound/sound_factory.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDFACTORY_H_
|
||||
#define _SHARED_SOUND_SOUNDFACTORY_H_
|
||||
|
||||
#include "sound_player.h"
|
||||
|
||||
namespace Shared{ namespace Sound{
|
||||
|
||||
// =====================================================
|
||||
// class SoundFactory
|
||||
// =====================================================
|
||||
|
||||
class SoundFactory{
|
||||
public:
|
||||
virtual ~SoundFactory(){}
|
||||
virtual SoundPlayer *newSoundPlayer() {return NULL;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
104
source/shared_lib/include/sound/sound_file_loader.h
Normal file
104
source/shared_lib/include/sound/sound_file_loader.h
Normal file
@@ -0,0 +1,104 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDFILELOADER_H_
|
||||
#define _SHARED_SOUND_SOUNDFILELOADER_H_
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#include "types.h"
|
||||
#include "factory.h"
|
||||
|
||||
struct OggVorbis_File;
|
||||
|
||||
using std::string;
|
||||
using std::ifstream;
|
||||
|
||||
namespace Shared{ namespace Sound{
|
||||
|
||||
using Platform::uint32;
|
||||
using Platform::int8;
|
||||
using Util::MultiFactory;
|
||||
|
||||
class SoundInfo;
|
||||
|
||||
// =====================================================
|
||||
// class SoundFileLoader
|
||||
//
|
||||
/// Interface that all SoundFileLoaders will implement
|
||||
// =====================================================
|
||||
|
||||
class SoundFileLoader{
|
||||
public:
|
||||
virtual ~SoundFileLoader(){}
|
||||
|
||||
virtual void open(const string &path, SoundInfo *soundInfo)= 0;
|
||||
virtual uint32 read(int8 *samples, uint32 size)= 0;
|
||||
virtual void close()= 0;
|
||||
virtual void restart()= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class WavSoundFileLoader
|
||||
//
|
||||
/// Wave file loader
|
||||
// =====================================================
|
||||
|
||||
class WavSoundFileLoader: public SoundFileLoader{
|
||||
private:
|
||||
static const int maxDataRetryCount= 10;
|
||||
|
||||
private:
|
||||
uint32 dataOffset;
|
||||
uint32 dataSize;
|
||||
uint32 bytesPerSecond;
|
||||
ifstream f;
|
||||
|
||||
public:
|
||||
virtual void open(const string &path, SoundInfo *soundInfo);
|
||||
virtual uint32 read(int8 *samples, uint32 size);
|
||||
virtual void close();
|
||||
virtual void restart();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class OggSoundFileLoader
|
||||
//
|
||||
/// OGG sound file loader, uses ogg-vorbis library
|
||||
// =====================================================
|
||||
|
||||
class OggSoundFileLoader: public SoundFileLoader{
|
||||
private:
|
||||
OggVorbis_File *vf;
|
||||
FILE *f;
|
||||
|
||||
public:
|
||||
virtual void open(const string &path, SoundInfo *soundInfo);
|
||||
virtual uint32 read(int8 *samples, uint32 size);
|
||||
virtual void close();
|
||||
virtual void restart();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SoundFileLoaderFactory
|
||||
// =====================================================
|
||||
|
||||
class SoundFileLoaderFactory: public MultiFactory<SoundFileLoader>{
|
||||
private:
|
||||
SoundFileLoaderFactory();
|
||||
public:
|
||||
static SoundFileLoaderFactory * getInstance();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
42
source/shared_lib/include/sound/sound_interface.h
Normal file
42
source/shared_lib/include/sound/sound_interface.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDINTERFACE_H_
|
||||
#define _SHARED_SOUND_SOUNDINTERFACE_H_
|
||||
|
||||
#include "sound_factory.h"
|
||||
|
||||
namespace Shared{ namespace Sound{
|
||||
|
||||
// =====================================================
|
||||
// class SoundInterface
|
||||
// =====================================================
|
||||
|
||||
class SoundInterface{
|
||||
private:
|
||||
SoundFactory *soundFactory;
|
||||
|
||||
private:
|
||||
SoundInterface(){}
|
||||
SoundInterface(SoundInterface &);
|
||||
void operator=(SoundInterface &);
|
||||
|
||||
public:
|
||||
static SoundInterface &getInstance();
|
||||
|
||||
void setFactory(SoundFactory *soundFactory);
|
||||
|
||||
SoundPlayer *newSoundPlayer();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
55
source/shared_lib/include/sound/sound_player.h
Normal file
55
source/shared_lib/include/sound/sound_player.h
Normal file
@@ -0,0 +1,55 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_SOUND_SOUNDPLAYER_H_
|
||||
#define _SHARED_SOUND_SOUNDPLAYER_H_
|
||||
|
||||
#include "sound.h"
|
||||
#include "types.h"
|
||||
|
||||
using Shared::Platform::uint32;
|
||||
|
||||
namespace Shared{ namespace Sound{
|
||||
|
||||
// =====================================================
|
||||
// class SoundPlayerParams
|
||||
// =====================================================
|
||||
|
||||
class SoundPlayerParams{
|
||||
public:
|
||||
uint32 strBufferSize;
|
||||
uint32 strBufferCount;
|
||||
uint32 staticBufferCount;
|
||||
|
||||
SoundPlayerParams();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SoundPlayer
|
||||
//
|
||||
// Interface that every SoundPlayer will implement
|
||||
// =====================================================
|
||||
|
||||
class SoundPlayer{
|
||||
public:
|
||||
virtual ~SoundPlayer(){};
|
||||
virtual void init(const SoundPlayerParams *params)= 0;
|
||||
virtual void end()= 0;
|
||||
virtual void play(StaticSound *staticSound)= 0;
|
||||
virtual void play(StrSound *strSound, int64 fadeOn=0)= 0; //delay and fade in miliseconds
|
||||
virtual void stop(StrSound *strSound, int64 fadeOff=0)= 0;
|
||||
virtual void stopAllSounds()= 0;
|
||||
virtual void updateStreams()= 0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
48
source/shared_lib/include/util/checksum.h
Normal file
48
source/shared_lib/include/util/checksum.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_CHECKSUM_H_
|
||||
#define _SHARED_UTIL_CHECKSUM_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
using std::string;
|
||||
using Shared::Platform::int32;
|
||||
using Shared::Platform::int8;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
// =====================================================
|
||||
// class Checksum
|
||||
// =====================================================
|
||||
|
||||
class Checksum{
|
||||
private:
|
||||
int32 sum;
|
||||
int32 r;
|
||||
int32 c1;
|
||||
int32 c2;
|
||||
|
||||
public:
|
||||
Checksum();
|
||||
|
||||
int32 getSum() const {return sum;}
|
||||
|
||||
void addByte(int8 value);
|
||||
void addString(const string &value);
|
||||
void addFile(const string &path);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
37
source/shared_lib/include/util/conversion.h
Normal file
37
source/shared_lib/include/util/conversion.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_CONVERSION_H_
|
||||
#define _SHARED_UTIL_CONVERSION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
bool strToBool(const string &s);
|
||||
int strToInt(const string &s);
|
||||
float strToFloat(const string &s);
|
||||
|
||||
bool strToBool(const string &s, bool *b);
|
||||
bool strToInt(const string &s, int *i);
|
||||
bool strToFloat(const string &s, float *f);
|
||||
|
||||
string boolToStr(bool b);
|
||||
string intToStr(int i);
|
||||
string intToHex(int i);
|
||||
string floatToStr(float f);
|
||||
string doubleToStr(double f);
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
86
source/shared_lib/include/util/factory.h
Normal file
86
source/shared_lib/include/util/factory.h
Normal file
@@ -0,0 +1,86 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_FACTORY_
|
||||
#define _SHARED_UTIL_FACTORY_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
using std::runtime_error;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
// =====================================================
|
||||
// class SingleFactoryBase
|
||||
// =====================================================
|
||||
|
||||
class SingleFactoryBase{
|
||||
public:
|
||||
virtual ~SingleFactoryBase(){}
|
||||
virtual void *newInstance()= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SingleFactory
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class SingleFactory: public SingleFactoryBase{
|
||||
public:
|
||||
virtual void *newInstance() {return new T();}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class MultiFactory
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class MultiFactory{
|
||||
private:
|
||||
typedef map<string, SingleFactoryBase*> Factories;
|
||||
typedef pair<string, SingleFactoryBase*> FactoryPair;
|
||||
|
||||
private:
|
||||
Factories factories;
|
||||
|
||||
public:
|
||||
virtual ~MultiFactory(){
|
||||
for(Factories::iterator it= factories.begin(); it!=factories.end(); ++it){
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
void registerClass(string classId){
|
||||
factories.insert(FactoryPair(classId, new SingleFactory<R>()));
|
||||
}
|
||||
|
||||
T *newInstance(string classId){
|
||||
Factories::iterator it= factories.find(classId);
|
||||
if(it == factories.end()){
|
||||
throw runtime_error("Unknown class identifier: " + classId);
|
||||
}
|
||||
return static_cast<T*>(it->second->newInstance());
|
||||
}
|
||||
|
||||
bool isClassId(string classId){
|
||||
return factories.find(classId)!=factories.end();
|
||||
}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
121
source/shared_lib/include/util/leak_dumper.h
Normal file
121
source/shared_lib/include/util/leak_dumper.h
Normal file
@@ -0,0 +1,121 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _LEAKDUMPER_H_
|
||||
#define _LEAKDUMPER_H_
|
||||
|
||||
//#define SL_LEAK_DUMP
|
||||
//SL_LEAK_DUMP controls if leak dumping is enabled or not
|
||||
|
||||
#ifdef SL_LEAK_DUMP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
//including this header in any file of a project will cause all
|
||||
//leaks to be dumped into leak_dump.txt, but only allocations that
|
||||
//ocurred in a file where this header is included will have
|
||||
//file and line number
|
||||
|
||||
struct AllocInfo{
|
||||
int line;
|
||||
const char *file;
|
||||
size_t bytes;
|
||||
void *ptr;
|
||||
bool free;
|
||||
bool array;
|
||||
|
||||
AllocInfo();
|
||||
AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class AllocRegistry
|
||||
// =====================================================
|
||||
|
||||
class AllocRegistry{
|
||||
private:
|
||||
static const unsigned maxAllocs= 40000;
|
||||
|
||||
private:
|
||||
AllocRegistry();
|
||||
|
||||
private:
|
||||
AllocInfo allocs[maxAllocs]; //array to store allocation info
|
||||
int allocCount; //allocations
|
||||
size_t allocBytes; //bytes allocated
|
||||
int nonMonitoredCount;
|
||||
size_t nonMonitoredBytes;
|
||||
|
||||
public:
|
||||
~AllocRegistry();
|
||||
|
||||
static AllocRegistry &getInstance();
|
||||
|
||||
void allocate(AllocInfo info);
|
||||
void deallocate(void* ptr, bool array);
|
||||
void reset();
|
||||
void dump(const char *path);
|
||||
};
|
||||
|
||||
//if an allocation ocurrs in a file where "leaks_dumper.h" is not included
|
||||
//this operator new is called and file and line will be unknown
|
||||
inline void * operator new (size_t bytes){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, bytes, false));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete(void *ptr){
|
||||
AllocRegistry::getInstance().deallocate(ptr, false);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
inline void * operator new[](size_t bytes){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, bytes, true));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete [](void *ptr){
|
||||
AllocRegistry::getInstance().deallocate(ptr, true);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
//if an allocation ocurrs in a file where "leaks_dumper.h" is included
|
||||
//this operator new is called and file and line will be known
|
||||
inline void * operator new (size_t bytes, char* file, int line){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, bytes, false));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete(void *ptr, char* file, int line){
|
||||
AllocRegistry::getInstance().deallocate(ptr, false);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
inline void * operator new[](size_t bytes, char* file, int line){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, bytes, true));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete [](void *ptr, char* file, int line){
|
||||
AllocRegistry::getInstance().deallocate(ptr, true);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#define new new(__FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
99
source/shared_lib/include/util/profiler.h
Normal file
99
source/shared_lib/include/util/profiler.h
Normal file
@@ -0,0 +1,99 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_PROFILER_H_
|
||||
#define _SHARED_UTIL_PROFILER_H_
|
||||
|
||||
//#define SL_PROFILE
|
||||
//SL_PROFILE controls if profile is enabled or not
|
||||
|
||||
#include "platform_util.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
using std::list;
|
||||
using std::string;
|
||||
|
||||
using Shared::Platform::Chrono;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
#ifdef SL_PROFILE
|
||||
|
||||
// =====================================================
|
||||
// class Section
|
||||
// =====================================================
|
||||
|
||||
class Section{
|
||||
public:
|
||||
typedef list<Section*> SectionContainer;
|
||||
private:
|
||||
string name;
|
||||
Chrono chrono;
|
||||
int64 milisElapsed;
|
||||
Section *parent;
|
||||
SectionContainer children;
|
||||
|
||||
public:
|
||||
Section(const string &name);
|
||||
|
||||
Section *getParent() {return parent;}
|
||||
const string &getName() const {return name;}
|
||||
|
||||
void setParent(Section *parent) {this->parent= parent;}
|
||||
|
||||
void start() {chrono.start();}
|
||||
void stop() {milisElapsed+=chrono.getMillis();}
|
||||
|
||||
void addChild(Section *child) {children.push_back(child);}
|
||||
Section *getChild(const string &name);
|
||||
|
||||
void print(FILE *outSream, int tabLevel=0);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Profiler
|
||||
// =====================================================
|
||||
|
||||
class Profiler{
|
||||
private:
|
||||
Section *rootSection;
|
||||
Section *currSection;
|
||||
private:
|
||||
Profiler();
|
||||
public:
|
||||
~Profiler();
|
||||
static Profiler &getInstance();
|
||||
void sectionBegin(const string &name);
|
||||
void sectionEnd(const string &name);
|
||||
};
|
||||
|
||||
#endif //SL_PROFILE
|
||||
|
||||
// =====================================================
|
||||
// class funtions
|
||||
// =====================================================
|
||||
|
||||
inline void profileBegin(const string §ionName){
|
||||
#ifdef SL_PROFILE
|
||||
Profiler::getInstance().sectionBegin(sectionName);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void profileEnd(const string §ionName){
|
||||
#ifdef SL_PROFILE
|
||||
Profiler::getInstance().sectionEnd(sectionName);
|
||||
#endif
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
74
source/shared_lib/include/util/properties.h
Normal file
74
source/shared_lib/include/util/properties.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_PROPERTIES_H_
|
||||
#define _SHARED_UTIL_PROPERTIES_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
// =====================================================
|
||||
// class Properties
|
||||
//
|
||||
/// ini-like file loader
|
||||
// =====================================================
|
||||
|
||||
class Properties{
|
||||
private:
|
||||
static const int maxLine= 1024;
|
||||
|
||||
public:
|
||||
typedef pair<string, string> PropertyPair;
|
||||
typedef map<string, string> PropertyMap;
|
||||
typedef vector<PropertyPair> PropertyVector;
|
||||
|
||||
private:
|
||||
PropertyVector propertyVector;
|
||||
PropertyMap propertyMap;
|
||||
string path;
|
||||
|
||||
public:
|
||||
void clear();
|
||||
void load(const string &path);
|
||||
void save(const string &path);
|
||||
|
||||
int getPropertyCount() {return propertyVector.size();}
|
||||
string getKey(int i) {return propertyVector[i].first;}
|
||||
string getString(int i) {return propertyVector[i].second;}
|
||||
|
||||
bool getBool(const string &key) const;
|
||||
int getInt(const string &key) const;
|
||||
int getInt(const string &key, int min, int max) const;
|
||||
float getFloat(const string &key) const;
|
||||
float getFloat(const string &key, float min, float max) const;
|
||||
const string &getString(const string &key) const;
|
||||
|
||||
void setInt(const string &key, int value);
|
||||
void setBool(const string &key, bool value);
|
||||
void setFloat(const string &key, float value);
|
||||
void setString(const string &key, const string &value);
|
||||
|
||||
string toString();
|
||||
|
||||
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
41
source/shared_lib/include/util/random.h
Normal file
41
source/shared_lib/include/util/random.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_RANDOM_H_
|
||||
#define _SHARED_UTIL_RANDOM_H_
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
// =====================================================
|
||||
// class Random
|
||||
// =====================================================
|
||||
|
||||
class Random{
|
||||
private:
|
||||
static const int m;
|
||||
static const int a;
|
||||
static const int b;
|
||||
|
||||
private:
|
||||
int lastNumber;
|
||||
|
||||
public:
|
||||
Random();
|
||||
void init(int seed);
|
||||
|
||||
int rand();
|
||||
int randRange(int min, int max);
|
||||
float randRange(float min, float max);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
58
source/shared_lib/include/util/util.h
Normal file
58
source/shared_lib/include/util/util.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_UTIL_UTIL_H_
|
||||
#define _SHARED_UTIL_UTIL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
const string sharedLibVersionString= "v0.4.1";
|
||||
|
||||
//string fcs
|
||||
string lastDir(const string &s);
|
||||
string lastFile(const string &s);
|
||||
string cutLastFile(const string &s);
|
||||
string cutLastExt(const string &s);
|
||||
string ext(const string &s);
|
||||
string replaceBy(const string &s, char c1, char c2);
|
||||
string toLower(const string &s);
|
||||
void copyStringToBuffer(char *buffer, int bufferSize, const string& s);
|
||||
|
||||
//numeric fcs
|
||||
int clamp(int value, int min, int max);
|
||||
float clamp(float value, float min, float max);
|
||||
float saturate(float value);
|
||||
int round(float f);
|
||||
|
||||
//misc
|
||||
bool fileExists(const string &path);
|
||||
|
||||
template<typename T>
|
||||
void deleteValues(T beginIt, T endIt){
|
||||
for(T it= beginIt; it!=endIt; ++it){
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void deleteMapValues(T beginIt, T endIt){
|
||||
for(T it= beginIt; it!=endIt; ++it){
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
156
source/shared_lib/include/xml/xml_parser.h
Normal file
156
source/shared_lib/include/xml/xml_parser.h
Normal file
@@ -0,0 +1,156 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_XML_XMLPARSER_H_
|
||||
#define _SHARED_XML_XMLPARSER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace XERCES_CPP_NAMESPACE{
|
||||
class DOMImplementation;
|
||||
class DOMDocument;
|
||||
class DOMNode;
|
||||
class DOMElement;
|
||||
}
|
||||
|
||||
namespace Shared{ namespace Xml{
|
||||
|
||||
const int strSize= 256;
|
||||
|
||||
class XmlIo;
|
||||
class XmlTree;
|
||||
class XmlNode;
|
||||
class XmlAttribute;
|
||||
|
||||
// =====================================================
|
||||
// class XmlIo
|
||||
//
|
||||
/// Wrapper for Xerces C++
|
||||
// =====================================================
|
||||
|
||||
class XmlIo{
|
||||
private:
|
||||
static bool initialized;
|
||||
XERCES_CPP_NAMESPACE::DOMImplementation *implementation;
|
||||
|
||||
private:
|
||||
XmlIo();
|
||||
|
||||
public:
|
||||
static XmlIo &getInstance();
|
||||
~XmlIo();
|
||||
XmlNode *load(const string &path);
|
||||
void save(const string &path, const XmlNode *node);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class XmlTree
|
||||
// =====================================================
|
||||
|
||||
class XmlTree{
|
||||
private:
|
||||
XmlNode *rootNode;
|
||||
|
||||
private:
|
||||
XmlTree(XmlTree&);
|
||||
void operator =(XmlTree&);
|
||||
|
||||
public:
|
||||
XmlTree();
|
||||
~XmlTree();
|
||||
|
||||
void init(const string &name);
|
||||
void load(const string &path);
|
||||
void save(const string &path);
|
||||
|
||||
XmlNode *getRootNode() const {return rootNode;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class XmlNode
|
||||
// =====================================================
|
||||
|
||||
class XmlNode{
|
||||
private:
|
||||
string name;
|
||||
string text;
|
||||
vector<XmlNode*> children;
|
||||
vector<XmlAttribute*> attributes;
|
||||
|
||||
private:
|
||||
XmlNode(XmlNode&);
|
||||
void operator =(XmlNode&);
|
||||
|
||||
public:
|
||||
XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node);
|
||||
XmlNode(const string &name);
|
||||
~XmlNode();
|
||||
|
||||
const string &getName() const {return name;}
|
||||
int getChildCount() const {return children.size();}
|
||||
int getAttributeCount() const {return attributes.size();}
|
||||
const string &getText() const {return text;}
|
||||
|
||||
XmlAttribute *getAttribute(int i) const;
|
||||
XmlAttribute *getAttribute(const string &name) const;
|
||||
XmlNode *getChild(int i) const;
|
||||
XmlNode *getChild(const string &childName, int childIndex=0) const;
|
||||
XmlNode *getParent() const;
|
||||
|
||||
|
||||
XmlNode *addChild(const string &name);
|
||||
XmlAttribute *addAttribute(const string &name, const string &value);
|
||||
|
||||
XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const;
|
||||
|
||||
private:
|
||||
string getTreeString() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class XmlAttribute
|
||||
// =====================================================
|
||||
|
||||
class XmlAttribute{
|
||||
private:
|
||||
string value;
|
||||
string name;
|
||||
|
||||
private:
|
||||
XmlAttribute(XmlAttribute&);
|
||||
void operator =(XmlAttribute&);
|
||||
|
||||
public:
|
||||
XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute);
|
||||
XmlAttribute(const string &name, const string &value);
|
||||
|
||||
public:
|
||||
const string &getName() const {return name;}
|
||||
const string &getValue() const {return value;}
|
||||
|
||||
bool getBoolValue() const;
|
||||
int getIntValue() const;
|
||||
int getIntValue(int min, int max) const;
|
||||
float getFloatValue() const;
|
||||
float getFloatValue(float min, float max) const;
|
||||
const string &getRestrictedValue() const;
|
||||
};
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
55
source/shared_lib/sources/graphics/buffer.cpp
Normal file
55
source/shared_lib/sources/graphics/buffer.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "buffer.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class VertexBuffer
|
||||
// =====================================================
|
||||
|
||||
VertexBuffer::VertexBuffer(){
|
||||
positionPointer= NULL;
|
||||
normalPointer= NULL;
|
||||
for(int i= 0; i<texCoordCount; ++i){
|
||||
texCoordPointers[i]= NULL;
|
||||
texCoordCoordCounts[i]= -1;
|
||||
}
|
||||
for(int i= 0; i<attribCount; ++i){
|
||||
attribPointers[i]= NULL;
|
||||
attribCoordCounts[i]= -1;
|
||||
}
|
||||
}
|
||||
|
||||
void VertexBuffer::setPositionPointer(void *pointer){
|
||||
positionPointer= pointer;
|
||||
}
|
||||
|
||||
void VertexBuffer::setNormalPointer(void *pointer){
|
||||
normalPointer= pointer;
|
||||
}
|
||||
|
||||
void VertexBuffer::setTexCoordPointer(void *pointer, int texCoordIndex, int coordCount){
|
||||
texCoordPointers[texCoordIndex]= pointer;
|
||||
texCoordCoordCounts[texCoordIndex]= coordCount;
|
||||
}
|
||||
|
||||
void VertexBuffer::setAttribPointer(void *pointer, int attribIndex, int coordCount, const string &name){
|
||||
attribPointers[attribIndex]= pointer;
|
||||
attribCoordCounts[attribIndex]= coordCount;
|
||||
attribNames[attribIndex]= name;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class IndexBuffer
|
||||
// =====================================================
|
||||
|
||||
IndexBuffer::IndexBuffer(){
|
||||
indexPointer= NULL;
|
||||
}
|
||||
|
||||
void IndexBuffer::setIndexPointer(void *pointer){
|
||||
indexPointer= pointer;
|
||||
}
|
||||
|
||||
}}//end namespace
|
53
source/shared_lib/sources/graphics/camera.cpp
Normal file
53
source/shared_lib/sources/graphics/camera.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class Camera
|
||||
// =====================================================
|
||||
|
||||
Camera::Camera(){
|
||||
position= Vec3f(0.0f);
|
||||
}
|
||||
|
||||
void Camera::moveLocalX(float amount){
|
||||
position= position + orientation.getLocalXAxis()*amount;
|
||||
}
|
||||
|
||||
void Camera::moveLocalY(float amount){
|
||||
position= position + orientation.getLocalYAxis()*amount;
|
||||
}
|
||||
|
||||
void Camera::moveLocalZ(float amount){
|
||||
position= position + orientation.getLocalZAxis()*amount;
|
||||
}
|
||||
|
||||
void Camera::addYaw(float amount){
|
||||
Quaternion q(EulerAngles(0, amount, 0));
|
||||
orientation*= q;
|
||||
}
|
||||
|
||||
void Camera::addPitch(float amount){
|
||||
Quaternion q(EulerAngles(amount, 0, 0));
|
||||
orientation*= q;
|
||||
}
|
||||
|
||||
void Camera::addRoll(float amount){
|
||||
Quaternion q(EulerAngles(0, 0, amount));
|
||||
orientation*= q;
|
||||
}
|
||||
|
||||
}}//end namespace
|
28
source/shared_lib/sources/graphics/context.cpp
Normal file
28
source/shared_lib/sources/graphics/context.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "context.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class Context
|
||||
// =====================================================
|
||||
|
||||
Context::Context(){
|
||||
colorBits= 32;
|
||||
depthBits= 24;
|
||||
stencilBits= 0;
|
||||
}
|
||||
|
||||
}}//end namespace
|
73
source/shared_lib/sources/graphics/d3d9/context_d3d9.cpp
Normal file
73
source/shared_lib/sources/graphics/d3d9/context_d3d9.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "context_d3d9.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "d3d9_util.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================================
|
||||
// class ContextD3d9
|
||||
// ===============================================
|
||||
|
||||
ContextD3d9::ContextD3d9(){
|
||||
windowed= true;
|
||||
hardware= true;
|
||||
}
|
||||
|
||||
void ContextD3d9::init(){
|
||||
|
||||
//create object
|
||||
d3dObject= Direct3DCreate9(D3D_SDK_VERSION);
|
||||
if(d3dObject==NULL){
|
||||
throw runtime_error("Direct3DCreate9==NULL");
|
||||
}
|
||||
|
||||
//present parameters
|
||||
memset(&d3dPresentParameters, 0, sizeof(d3dPresentParameters));
|
||||
d3dPresentParameters.Windowed = TRUE;
|
||||
d3dPresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
d3dPresentParameters.BackBufferFormat = D3DFMT_A8R8G8B8;
|
||||
d3dPresentParameters.EnableAutoDepthStencil= TRUE;
|
||||
d3dPresentParameters.AutoDepthStencilFormat= D3DFMT_D24X8;
|
||||
d3dPresentParameters.PresentationInterval= D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
|
||||
//create device
|
||||
D3DCALL(d3dObject->CreateDevice(
|
||||
D3DADAPTER_DEFAULT,
|
||||
hardware? D3DDEVTYPE_HAL: D3DDEVTYPE_REF,
|
||||
GetActiveWindow(),
|
||||
hardware? D3DCREATE_HARDWARE_VERTEXPROCESSING: D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
||||
&d3dPresentParameters,
|
||||
&d3dDevice));
|
||||
|
||||
//get caps
|
||||
D3DCALL(d3dDevice->GetDeviceCaps(&caps));
|
||||
}
|
||||
|
||||
void ContextD3d9::end(){
|
||||
D3DCALL(d3dDevice->Release());
|
||||
D3DCALL(d3dObject->Release());
|
||||
}
|
||||
|
||||
void ContextD3d9::makeCurrent(){
|
||||
|
||||
}
|
||||
|
||||
void ContextD3d9::swapBuffers(){
|
||||
D3DCALL(d3dDevice->Present(NULL, NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
void ContextD3d9::reset(){
|
||||
d3dPresentParameters.BackBufferWidth= 0;
|
||||
d3dPresentParameters.BackBufferHeight= 0;
|
||||
D3DCALL(d3dDevice->Reset(&d3dPresentParameters));
|
||||
}
|
||||
|
||||
|
||||
}}}//end namespace
|
21
source/shared_lib/sources/graphics/d3d9/d3d9_util.cpp
Normal file
21
source/shared_lib/sources/graphics/d3d9/d3d9_util.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "d3d9_util.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
string d3dErrorToStr(HRESULT result){
|
||||
switch(result){
|
||||
case D3D_OK: return "D3D_OK";
|
||||
case D3DERR_DEVICELOST: return "D3DERR_DEVICELOST";
|
||||
case D3DERR_DEVICENOTRESET: return "D3DERR_DEVICENOTRESET";
|
||||
case D3DERR_DRIVERINTERNALERROR: return "D3DERR_DRIVERINTERNALERROR";
|
||||
case D3DERR_INVALIDCALL: return "D3DERR_INVALIDCALL";
|
||||
case D3DERR_MOREDATA: return "D3DERR_MOREDATA";
|
||||
case D3DERR_NOTFOUND: return "D3DERR_NOTFOUND";
|
||||
case D3DERR_OUTOFVIDEOMEMORY: return "D3DERR_OUTOFVIDEOMEMORY";
|
||||
case E_OUTOFMEMORY: return "E_OUTOFMEMORY";
|
||||
default:
|
||||
return "Unkown D3D error";
|
||||
}
|
||||
}
|
||||
|
||||
}}}//end namespace
|
38
source/shared_lib/sources/graphics/d3d9/font_d3d9.cpp
Normal file
38
source/shared_lib/sources/graphics/d3d9/font_d3d9.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "font_d3d9.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
#include "graphics_interface.h"
|
||||
#include "context_d3d9.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================================
|
||||
// class Font2DD3d9
|
||||
// ===============================================
|
||||
|
||||
void Font2DD3d9::init(){
|
||||
GraphicsInterface &gi= GraphicsInterface::getInstance();
|
||||
IDirect3DDevice9 *d3dDevice= static_cast<ContextD3d9*>(gi.getCurrentContext())->getD3dDevice();
|
||||
|
||||
HFONT hFont=CreateFont(size, 0, 0, 0, width, 0, FALSE, FALSE, ANSI_CHARSET,
|
||||
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, type.c_str());
|
||||
|
||||
HRESULT result= D3DXCreateFont(d3dDevice, hFont, &d3dFont);
|
||||
if(result!=D3D_OK){
|
||||
throw runtime_error("FontD3d9::init() -> Can't create D3D font");
|
||||
}
|
||||
DeleteObject(hFont);
|
||||
}
|
||||
|
||||
void Font2DD3d9::end(){
|
||||
d3dFont->Release();
|
||||
}
|
||||
|
||||
|
||||
}}}//end namespace
|
173
source/shared_lib/sources/graphics/d3d9/model_renderer_d3d9.cpp
Normal file
173
source/shared_lib/sources/graphics/d3d9/model_renderer_d3d9.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
#include "model_renderer_d3d9.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "graphics_interface.h"
|
||||
#include "context_d3d9.h"
|
||||
#include "texture_d3d9.h"
|
||||
#include "interpolation.h"
|
||||
#include "d3d9_util.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================================
|
||||
// class ModelRendererD3d9
|
||||
// ===============================================
|
||||
|
||||
D3DVERTEXELEMENT9 d3dVertexElementsPNT[]=
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
|
||||
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
D3DVERTEXELEMENT9 d3dVertexElementsPNTT[]=
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
|
||||
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
{0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
ModelRendererD3d9::ModelRendererD3d9(){
|
||||
rendering= false;
|
||||
|
||||
GraphicsInterface &gi= GraphicsInterface::getInstance();
|
||||
d3dDevice= static_cast<ContextD3d9*>(gi.getCurrentContext())->getD3dDevice();
|
||||
|
||||
bufferPointCount= 0;
|
||||
bufferIndexCount= 0;
|
||||
|
||||
D3DCALL(d3dDevice->CreateVertexDeclaration(d3dVertexElementsPNT, &d3dVertexDeclarationPNT));
|
||||
D3DCALL(d3dDevice->CreateVertexDeclaration(d3dVertexElementsPNTT, &d3dVertexDeclarationPNTT));
|
||||
|
||||
readyBuffers(defBufferPointCount, defBufferIndexCount);
|
||||
}
|
||||
|
||||
ModelRendererD3d9::~ModelRendererD3d9(){
|
||||
d3dVertexBuffer->Release();
|
||||
}
|
||||
|
||||
void ModelRendererD3d9::begin(bool renderNormals, bool renderTextures, bool renderColors){
|
||||
rendering= true;
|
||||
}
|
||||
|
||||
void ModelRendererD3d9::end(){
|
||||
rendering= false;
|
||||
}
|
||||
|
||||
void ModelRendererD3d9::render(const Model *model){
|
||||
assert(rendering);
|
||||
|
||||
//render every mesh
|
||||
for(uint32 i=0; i<model->getMeshCount(); ++i){
|
||||
renderMesh(model->getMesh(i));
|
||||
}
|
||||
}
|
||||
|
||||
void ModelRendererD3d9::renderNormalsOnly(const Model *model){
|
||||
}
|
||||
|
||||
// ====================== Private ===============================================
|
||||
|
||||
void ModelRendererD3d9::renderMesh(const Mesh *mesh){
|
||||
|
||||
CustomVertexPNTT *vertices;
|
||||
uint32 *indices;
|
||||
|
||||
readyBuffers(mesh->getVertexCount(), mesh->getIndexCount());
|
||||
|
||||
//lock vertex buffer
|
||||
D3DCALL(d3dVertexBuffer->Lock(0, mesh->getVertexCount()*sizeof(CustomVertexPNTT), (void**) &vertices, 0));
|
||||
|
||||
//copy data vertex buffer
|
||||
const InterpolationData *interpolationData= mesh->getInterpolationData();
|
||||
|
||||
for(int i=0; i<mesh->getVertexCount(); ++i){
|
||||
vertices[i].vertex= interpolationData->getVertices()[i];
|
||||
vertices[i].normal= interpolationData->getNormals()[i];
|
||||
Vec2f texCoord= mesh->getTexCoords()[i];
|
||||
vertices[i].texCoord= Vec2f(texCoord.x, texCoord.y);
|
||||
}
|
||||
if(mesh->getTangents()!=NULL){
|
||||
for(int i=0; i<mesh->getVertexCount(); ++i){
|
||||
vertices[i].tangent= mesh->getTangents()[i];
|
||||
}
|
||||
}
|
||||
|
||||
//unlock vertex buffer
|
||||
D3DCALL(d3dVertexBuffer->Unlock());
|
||||
|
||||
//lock index buffer
|
||||
D3DCALL(d3dIndexBuffer->Lock(0, mesh->getIndexCount()*sizeof(uint32), (void**) &indices, 0));
|
||||
|
||||
//copy data
|
||||
for(int i=0; i<mesh->getIndexCount(); i+=3){
|
||||
indices[i]= mesh->getIndices()[i];
|
||||
indices[i+1]= mesh->getIndices()[i+2];
|
||||
indices[i+2]= mesh->getIndices()[i+1];
|
||||
}
|
||||
|
||||
//unlock
|
||||
D3DCALL(d3dIndexBuffer->Unlock());
|
||||
|
||||
//set stream data
|
||||
D3DCALL(d3dDevice->SetStreamSource(0, d3dVertexBuffer, 0, sizeof(CustomVertexPNTT)));
|
||||
D3DCALL(d3dDevice->SetVertexDeclaration(mesh->getTangents()==NULL? d3dVertexDeclarationPNT: d3dVertexDeclarationPNTT));
|
||||
D3DCALL(d3dDevice->SetIndices(d3dIndexBuffer));
|
||||
|
||||
//set textures
|
||||
int textureUnit= 0;
|
||||
for(int i=0; i<meshTextureCount; ++i){
|
||||
if(mesh->getTexture(i)!=NULL){
|
||||
const Texture2DD3d9* texture2DD3d9= static_cast<const Texture2DD3d9*>(mesh->getTexture(i));
|
||||
D3DCALL(d3dDevice->SetTexture(textureUnit, texture2DD3d9->getD3dTexture()));
|
||||
++textureUnit;
|
||||
}
|
||||
}
|
||||
|
||||
//render
|
||||
D3DCALL(d3dDevice->BeginScene());
|
||||
D3DCALL(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->getVertexCount(), 0, mesh->getIndexCount()/3));
|
||||
D3DCALL(d3dDevice->EndScene());
|
||||
|
||||
//reset textures
|
||||
for(int i=0; i<meshTextureCount; ++i){
|
||||
D3DCALL(d3dDevice->SetTexture(i, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
void ModelRendererD3d9::readyBuffers(int newPointCount, int newIndexCount){
|
||||
|
||||
//vertices, if the buffer is to small allocate a new buffer
|
||||
if(bufferPointCount<newPointCount){
|
||||
bufferPointCount= newPointCount;
|
||||
|
||||
D3DCALL(d3dDevice->CreateVertexBuffer(
|
||||
bufferPointCount*sizeof(CustomVertexPNTT),
|
||||
0,
|
||||
0,
|
||||
D3DPOOL_MANAGED,
|
||||
&d3dVertexBuffer,
|
||||
NULL));
|
||||
}
|
||||
|
||||
//indices
|
||||
if(bufferIndexCount<newIndexCount){
|
||||
bufferIndexCount= newIndexCount;
|
||||
|
||||
D3DCALL(d3dDevice->CreateIndexBuffer(
|
||||
bufferIndexCount*sizeof(uint32),
|
||||
0,
|
||||
D3DFMT_INDEX32,
|
||||
D3DPOOL_MANAGED,
|
||||
&d3dIndexBuffer,
|
||||
NULL));
|
||||
}
|
||||
}
|
||||
|
||||
}}}//end namespace
|
253
source/shared_lib/sources/graphics/d3d9/shader_d3d9.cpp
Normal file
253
source/shared_lib/sources/graphics/d3d9/shader_d3d9.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
#include "shader_d3d9.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "graphics_interface.h"
|
||||
#include "context_d3d9.h"
|
||||
#include "texture_d3d9.h"
|
||||
#include "d3d9_util.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================================
|
||||
// class ShaderD3d9
|
||||
// ===============================================
|
||||
|
||||
ShaderProgramD3d9::ShaderProgramD3d9(){
|
||||
GraphicsInterface &gi= GraphicsInterface::getInstance();
|
||||
d3dDevice= static_cast<ContextD3d9*>(gi.getCurrentContext())->getD3dDevice();
|
||||
vertexShader= NULL;
|
||||
pixelShader= NULL;
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::attach(VertexShader *vs, FragmentShader *fs){
|
||||
vertexShader= static_cast<VertexShaderD3d9*>(vs);
|
||||
pixelShader= static_cast<PixelShaderD3d9*>(fs);
|
||||
}
|
||||
|
||||
bool ShaderProgramD3d9::link(string &messages){
|
||||
d3dVsConstantTable= vertexShader->getD3dConstantTable();
|
||||
d3dPsConstantTable= pixelShader->getD3dConstantTable();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::activate(){
|
||||
d3dDevice->SetVertexShader(vertexShader->getD3dVertexShader());
|
||||
d3dDevice->SetPixelShader(pixelShader->getD3dPixelShader());
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, int value){
|
||||
D3DXHANDLE vsHandle= d3dVsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
D3DXHANDLE psHandle= d3dPsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
HRESULT vsResult= d3dVsConstantTable->SetInt(d3dDevice, vsHandle, value);
|
||||
HRESULT psResult= d3dPsConstantTable->SetInt(d3dDevice, psHandle, value);
|
||||
if(vsResult!=D3D_OK && psResult!=D3D_OK){
|
||||
throw runtime_error("Error setting shader uniform: "+string(name));
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, float value){
|
||||
D3DXHANDLE vsHandle= d3dVsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
D3DXHANDLE psHandle= d3dPsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
HRESULT vsResult= d3dVsConstantTable->SetFloat(d3dDevice, vsHandle, value);
|
||||
HRESULT psResult= d3dPsConstantTable->SetFloat(d3dDevice, psHandle, value);
|
||||
if(vsResult!=D3D_OK && psResult!=D3D_OK){
|
||||
throw runtime_error("Error setting shader uniform: "+string(name));
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, const Vec2f &value){
|
||||
setUniform(name, Vec4f(value.x, value.y, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, const Vec3f &value){
|
||||
setUniform(name, Vec4f(value.x, value.y, value.z, 0.0f));
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, const Vec4f &value){
|
||||
D3DXVECTOR4 v;
|
||||
memcpy(&v, &value, sizeof(float)*4);
|
||||
|
||||
D3DXHANDLE vsHandle= d3dVsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
D3DXHANDLE psHandle= d3dPsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
HRESULT vsResult= d3dVsConstantTable->SetVector(d3dDevice, vsHandle, &v);
|
||||
HRESULT psResult= d3dPsConstantTable->SetVector(d3dDevice, psHandle, &v);
|
||||
if(vsResult!=D3D_OK && psResult!=D3D_OK){
|
||||
throw runtime_error("Error setting shader uniform: "+string(name));
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, const Matrix3f &value){
|
||||
throw runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
void ShaderProgramD3d9::setUniform(const string &name, const Matrix4f &value){
|
||||
D3DXMATRIX m;
|
||||
memcpy(&m, &value, sizeof(float)*16);
|
||||
|
||||
D3DXHANDLE vsHandle= d3dVsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
D3DXHANDLE psHandle= d3dPsConstantTable->GetConstantByName(NULL, name.c_str());
|
||||
HRESULT vsResult= d3dVsConstantTable->SetMatrix(d3dDevice, vsHandle, &m);
|
||||
HRESULT psResult= d3dPsConstantTable->SetMatrix(d3dDevice, psHandle, &m);
|
||||
if(vsResult!=D3D_OK && psResult!=D3D_OK){
|
||||
throw runtime_error("Error setting shader uniform: "+string(name));
|
||||
}
|
||||
}
|
||||
|
||||
/*void ShaderD3d9::setUniform(const string &name, const Texture *value){
|
||||
D3DXHANDLE handle= d3dConstantTable->GetConstantByName(NULL, name);
|
||||
D3DXCONSTANT_DESC d3dDesc;
|
||||
UINT i=1;
|
||||
IDirect3DTexture9 *d3dTexture= static_cast<const Texture2DD3d9*>(value)->getD3dTexture();
|
||||
HRESULT result= d3dConstantTable->GetConstantDesc(handle, &d3dDesc, &i);
|
||||
if(result==D3D_OK)
|
||||
d3dDevice->SetTexture(d3dDesc.RegisterIndex, d3dTexture);
|
||||
else
|
||||
throw runtime_error("Error setting shader uniform sampler: "+string(name));
|
||||
}
|
||||
|
||||
bool ShaderD3d9::isUniform(char *name){
|
||||
D3DXCONSTANT_DESC d3dDesc;
|
||||
UINT i=1;
|
||||
D3DXHANDLE handle= d3dConstantTable->GetConstantByName(NULL, name);
|
||||
HRESULT result= d3dConstantTable->GetConstantDesc(handle, &d3dDesc, &i);
|
||||
return result==D3D_OK;
|
||||
}*/
|
||||
|
||||
// ===============================================
|
||||
// class ShaderD3d9
|
||||
// ===============================================
|
||||
|
||||
ShaderD3d9::ShaderD3d9(){
|
||||
GraphicsInterface &gi= GraphicsInterface::getInstance();
|
||||
d3dDevice= static_cast<ContextD3d9*>(gi.getCurrentContext())->getD3dDevice();
|
||||
d3dConstantTable= NULL;
|
||||
}
|
||||
|
||||
void ShaderD3d9::end(){
|
||||
if(d3dConstantTable!=NULL){
|
||||
d3dConstantTable->Release();
|
||||
d3dConstantTable= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderD3d9::load(const string &path){
|
||||
source.load(path);
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class VertexShaderD3d9
|
||||
// ===============================================
|
||||
|
||||
VertexShaderD3d9::VertexShaderD3d9(){
|
||||
target= "vs_2_0";
|
||||
d3dVertexShader= NULL;
|
||||
}
|
||||
|
||||
void VertexShaderD3d9::end(){
|
||||
ShaderD3d9::end();
|
||||
if(d3dVertexShader!=NULL){
|
||||
d3dVertexShader->Release();
|
||||
d3dVertexShader= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool VertexShaderD3d9::compile(string &messages){
|
||||
//compile shader
|
||||
ID3DXBuffer *code= NULL;
|
||||
ID3DXBuffer *errors= NULL;
|
||||
|
||||
HRESULT result= D3DXCompileShader(
|
||||
source.getCode().c_str(), source.getCode().size(), NULL, NULL,
|
||||
"main", target.c_str(), 0, &code, &errors,
|
||||
&d3dConstantTable);
|
||||
|
||||
if(errors!=NULL){
|
||||
messages+= reinterpret_cast<char*>(errors->GetBufferPointer());
|
||||
}
|
||||
|
||||
if(FAILED(result)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//create shader
|
||||
D3DCALL(d3dDevice->CreateVertexShader((DWORD*) code->GetBufferPointer(), &d3dVertexShader));
|
||||
|
||||
//release
|
||||
if(code!=NULL){
|
||||
code->Release();
|
||||
}
|
||||
if(errors!=NULL){
|
||||
errors->Release();
|
||||
}
|
||||
|
||||
//set defaults
|
||||
if(d3dConstantTable!=NULL){
|
||||
d3dConstantTable->SetDefaults(d3dDevice);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class PixelShaderD3d9
|
||||
// ===============================================
|
||||
|
||||
PixelShaderD3d9::PixelShaderD3d9(){
|
||||
target= "ps_2_0";
|
||||
d3dPixelShader= NULL;
|
||||
}
|
||||
|
||||
void PixelShaderD3d9::end(){
|
||||
ShaderD3d9::end();
|
||||
if(d3dPixelShader!=NULL){
|
||||
d3dPixelShader->Release();
|
||||
d3dPixelShader= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool PixelShaderD3d9::compile(string &messages){
|
||||
|
||||
messages+= "Compiling shader: " + source.getPathInfo() + "\n";
|
||||
|
||||
//compile shader
|
||||
ID3DXBuffer *code= NULL;
|
||||
ID3DXBuffer *errors= NULL;
|
||||
|
||||
HRESULT result= D3DXCompileShader(
|
||||
source.getCode().c_str(), source.getCode().size(), NULL, NULL,
|
||||
"main", target.c_str(), 0, &code, &errors,
|
||||
&d3dConstantTable);
|
||||
|
||||
if(errors!=NULL){
|
||||
messages+= reinterpret_cast<char*>(errors->GetBufferPointer());
|
||||
}
|
||||
|
||||
if(FAILED(result)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//create shader
|
||||
D3DCALL(d3dDevice->CreatePixelShader((DWORD*) code->GetBufferPointer(), &d3dPixelShader));
|
||||
|
||||
//release
|
||||
if(code!=NULL){
|
||||
code->Release();
|
||||
}
|
||||
if(errors!=NULL){
|
||||
errors->Release();
|
||||
}
|
||||
|
||||
//set defaults
|
||||
if(d3dConstantTable!=NULL){
|
||||
d3dConstantTable->SetDefaults(d3dDevice);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}}}//end namespace
|
@@ -0,0 +1,40 @@
|
||||
#include "text_renderer_d3d9.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
#include <d3d9types.h>
|
||||
|
||||
#include "font_d3d9.h"
|
||||
#include "d3d9_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================================
|
||||
// class TextRenderer2DD3d9
|
||||
// ===============================================
|
||||
|
||||
void TextRenderer2DD3d9::begin(const Font2D *font){
|
||||
this->font= font;
|
||||
this->color= Vec4f(1.0f);
|
||||
}
|
||||
|
||||
void TextRenderer2DD3d9::render(const string &text, int x, int y, bool centered){
|
||||
RECT rect;
|
||||
rect.bottom= y;
|
||||
rect.left= x;
|
||||
rect.top= y;
|
||||
rect.right= x;
|
||||
|
||||
D3DCOLOR d3dColor= D3DCOLOR_ARGB(
|
||||
static_cast<int>(color.w*255),
|
||||
static_cast<int>(color.x*255),
|
||||
static_cast<int>(color.y*255),
|
||||
static_cast<int>(color.z*255));
|
||||
|
||||
static_cast<const Font2DD3d9*>(font)->getD3dFont()->DrawText(text.c_str(), -1, &rect, DT_NOCLIP, d3dColor);
|
||||
}
|
||||
|
||||
void TextRenderer2DD3d9::end(){
|
||||
}
|
||||
|
||||
}}}//end namespace
|
192
source/shared_lib/sources/graphics/d3d9/texture_d3d9.cpp
Normal file
192
source/shared_lib/sources/graphics/d3d9/texture_d3d9.cpp
Normal file
@@ -0,0 +1,192 @@
|
||||
#include "texture_d3d9.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "graphics_interface.h"
|
||||
#include "context_d3d9.h"
|
||||
#include "d3d9_util.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::Graphics;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================================
|
||||
// class Texture2DD3d9
|
||||
// ===============================================
|
||||
|
||||
D3DFORMAT toFormatD3d(Texture::Format format, int components){
|
||||
switch(format){
|
||||
case Texture::fAuto:
|
||||
switch(components){
|
||||
case 1:
|
||||
return D3DFMT_L8;
|
||||
case 3:
|
||||
return D3DFMT_X8R8G8B8;
|
||||
case 4:
|
||||
return D3DFMT_A8R8G8B8;
|
||||
default:
|
||||
assert(false);
|
||||
return D3DFMT_A8R8G8B8;
|
||||
}
|
||||
break;
|
||||
case Texture::fLuminance:
|
||||
return D3DFMT_L8;
|
||||
case Texture::fAlpha:
|
||||
return D3DFMT_A8;
|
||||
case Texture::fRgb:
|
||||
return D3DFMT_X8R8G8B8;
|
||||
case Texture::fRgba:
|
||||
return D3DFMT_A8R8G8B8;
|
||||
default:
|
||||
assert(false);
|
||||
return D3DFMT_A8R8G8B8;
|
||||
}
|
||||
}
|
||||
|
||||
void fillPixels(uint8 *texturePixels, const Pixmap2D *pixmap){
|
||||
|
||||
for(int i=0; i<pixmap->getW(); ++i){
|
||||
for(int j=0; j<pixmap->getH(); ++j){
|
||||
int k= j*pixmap->getW()+i;
|
||||
|
||||
Vec4<uint8> pixel;
|
||||
|
||||
pixmap->getPixel(i, j, pixel.ptr());
|
||||
switch(pixmap->getComponents()){
|
||||
case 1:
|
||||
texturePixels[k]= pixel.x;
|
||||
break;
|
||||
case 3:
|
||||
texturePixels[k*4]= pixel.z;
|
||||
texturePixels[k*4+1]= pixel.y;
|
||||
texturePixels[k*4+2]= pixel.x;
|
||||
break;
|
||||
case 4:
|
||||
texturePixels[k*4]= pixel.z;
|
||||
texturePixels[k*4+1]= pixel.y;
|
||||
texturePixels[k*4+2]= pixel.x;
|
||||
texturePixels[k*4+3]= pixel.w;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Texture2DD3d9::init(Filter textureFilter, int maxAnisotropy){
|
||||
if(!inited){
|
||||
|
||||
//get device
|
||||
GraphicsInterface &gi= GraphicsInterface::getInstance();
|
||||
ContextD3d9 *context= static_cast<ContextD3d9*>(gi.getCurrentContext());
|
||||
IDirect3DDevice9 *d3dDevice= context->getD3dDevice();
|
||||
|
||||
bool mipmapCaps= (context->getCaps()->TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP) != 0;
|
||||
bool autogenMipmap= mipmapCaps && mipmap;
|
||||
|
||||
int w= pixmapInit? pixmap.getW(): defaultSize;
|
||||
int h= pixmapInit? pixmap.getH(): defaultSize;
|
||||
|
||||
//create texture
|
||||
D3DCALL(d3dDevice->CreateTexture(
|
||||
w,
|
||||
h,
|
||||
autogenMipmap? 0: 1,
|
||||
autogenMipmap? D3DUSAGE_AUTOGENMIPMAP: 0,
|
||||
toFormatD3d(format, pixmap.getComponents()),
|
||||
D3DPOOL_MANAGED,
|
||||
&d3dTexture,
|
||||
NULL));
|
||||
|
||||
if(pixmapInit){
|
||||
//lock
|
||||
D3DLOCKED_RECT lockedRect;
|
||||
D3DCALL(d3dTexture->LockRect(0, &lockedRect, NULL, 0));
|
||||
|
||||
//copy
|
||||
fillPixels(reinterpret_cast<uint8*>(lockedRect.pBits), &pixmap);
|
||||
|
||||
//unlock
|
||||
D3DCALL(d3dTexture->UnlockRect(0));
|
||||
}
|
||||
inited= true;
|
||||
}
|
||||
}
|
||||
|
||||
void Texture2DD3d9::end(){
|
||||
if(inited){
|
||||
d3dTexture->Release();
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class TextureCubeD3d9
|
||||
// ===============================================
|
||||
|
||||
void TextureCubeD3d9::init(Filter textureFilter, int maxAnisotropy){
|
||||
//get device
|
||||
if(!inited){
|
||||
GraphicsInterface &gi= GraphicsInterface::getInstance();
|
||||
ContextD3d9 *context= static_cast<ContextD3d9*>(gi.getCurrentContext());
|
||||
IDirect3DDevice9 *d3dDevice= context->getD3dDevice();
|
||||
|
||||
const Pixmap2D *face0= pixmap.getFace(0);
|
||||
int l= pixmapInit? face0->getW(): defaultSize;
|
||||
int components= face0->getComponents();
|
||||
|
||||
//check dimensions and face components
|
||||
if(pixmapInit){
|
||||
for(int i=0; i<6; ++i){
|
||||
const Pixmap2D *currentFace= pixmap.getFace(i);
|
||||
if(currentFace->getW()!=l || currentFace->getH()!=l){
|
||||
throw runtime_error("Can't create Direct3D cube texture: dimensions don't agree");
|
||||
}
|
||||
if(currentFace->getComponents()!=components){
|
||||
throw runtime_error("Can't create Direct3D cube texture: components don't agree");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool mipmapCaps= (context->getCaps()->TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP) != 0;
|
||||
bool autogenMipmap= mipmapCaps && mipmap;
|
||||
|
||||
//create texture
|
||||
D3DCALL(d3dDevice->CreateCubeTexture(
|
||||
l,
|
||||
autogenMipmap? 0: 1,
|
||||
autogenMipmap? D3DUSAGE_AUTOGENMIPMAP: 0,
|
||||
toFormatD3d(format, components),
|
||||
D3DPOOL_MANAGED,
|
||||
&d3dCubeTexture,
|
||||
NULL));
|
||||
|
||||
if(pixmapInit){
|
||||
for(int i=0; i<6; ++i){
|
||||
|
||||
//lock
|
||||
D3DLOCKED_RECT lockedRect;
|
||||
D3DCALL(d3dCubeTexture->LockRect(static_cast<D3DCUBEMAP_FACES>(i), 0, &lockedRect, NULL, 0));
|
||||
|
||||
//copy
|
||||
fillPixels(reinterpret_cast<uint8*>(lockedRect.pBits), pixmap.getFace(i));
|
||||
|
||||
//unlock
|
||||
D3DCALL(d3dCubeTexture->UnlockRect(static_cast<D3DCUBEMAP_FACES>(i), 0));
|
||||
}
|
||||
}
|
||||
inited= true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureCubeD3d9::end(){
|
||||
if(inited){
|
||||
d3dCubeTexture->Release();
|
||||
}
|
||||
}
|
||||
|
||||
}}}//end namespace
|
75
source/shared_lib/sources/graphics/font.cpp
Normal file
75
source/shared_lib/sources/graphics/font.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2007 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class FontMetrics
|
||||
// =====================================================
|
||||
|
||||
FontMetrics::FontMetrics(){
|
||||
widths= new float[Font::charCount];
|
||||
height= 0;
|
||||
|
||||
for(int i=0; i<Font::charCount; ++i){
|
||||
widths[i]= 0;
|
||||
}
|
||||
}
|
||||
|
||||
FontMetrics::~FontMetrics(){
|
||||
delete [] widths;
|
||||
}
|
||||
|
||||
float FontMetrics::getTextWidth(const string &str) const{
|
||||
float width= 0.f;
|
||||
for(int i=0; i<str.size(); ++i){
|
||||
width+= widths[str[i]];
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
float FontMetrics::getHeight() const{
|
||||
return height;
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class Font
|
||||
// ===============================================
|
||||
|
||||
const int Font::charCount= 256;
|
||||
|
||||
Font::Font(){
|
||||
inited= false;
|
||||
type= "Times New Roman";
|
||||
width= 400;
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class Font2D
|
||||
// ===============================================
|
||||
|
||||
Font2D::Font2D(){
|
||||
size= 10;
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class Font3D
|
||||
// ===============================================
|
||||
|
||||
Font3D::Font3D(){
|
||||
depth= 10.f;
|
||||
}
|
||||
|
||||
}}//end namespace
|
55
source/shared_lib/sources/graphics/font_manager.cpp
Normal file
55
source/shared_lib/sources/graphics/font_manager.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "font_manager.h"
|
||||
|
||||
#include "graphics_interface.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class FontManager
|
||||
// =====================================================
|
||||
|
||||
FontManager::~FontManager(){
|
||||
end();
|
||||
}
|
||||
|
||||
Font2D *FontManager::newFont2D(){
|
||||
Font2D *font= GraphicsInterface::getInstance().getFactory()->newFont2D();
|
||||
fonts.push_back(font);
|
||||
return font;
|
||||
}
|
||||
|
||||
Font3D *FontManager::newFont3D(){
|
||||
Font3D *font= GraphicsInterface::getInstance().getFactory()->newFont3D();
|
||||
fonts.push_back(font);
|
||||
return font;
|
||||
}
|
||||
|
||||
void FontManager::init(){
|
||||
for(size_t i=0; i<fonts.size(); ++i){
|
||||
fonts[i]->init();
|
||||
}
|
||||
}
|
||||
|
||||
void FontManager::end(){
|
||||
for(size_t i=0; i<fonts.size(); ++i){
|
||||
fonts[i]->end();
|
||||
delete fonts[i];
|
||||
}
|
||||
fonts.clear();
|
||||
}
|
||||
|
||||
|
||||
}}//end namespace
|
44
source/shared_lib/sources/graphics/gl/context_gl.cpp
Normal file
44
source/shared_lib/sources/graphics/gl/context_gl.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "context_gl.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ContextGl
|
||||
// =====================================================
|
||||
|
||||
void ContextGl::init(){
|
||||
pcgl.init(colorBits, depthBits, stencilBits);
|
||||
}
|
||||
|
||||
void ContextGl::end(){
|
||||
pcgl.end();
|
||||
}
|
||||
|
||||
void ContextGl::makeCurrent(){
|
||||
pcgl.makeCurrent();
|
||||
}
|
||||
|
||||
void ContextGl::swapBuffers(){
|
||||
pcgl.swapBuffers();
|
||||
}
|
||||
|
||||
}}}//end namespace
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user