From 58d09aa3ca4409e2a15473b0ac3c0446f0acb1a2 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 22 Oct 2018 21:30:21 +0800 Subject: *misc --- src/libjin/Common/je_exception.h | 22 ++++ src/libjin/Common/je_noncopyable.h | 24 ++++ src/libjin/Common/je_object.h | 16 +++ src/libjin/Common/je_pool.hpp | 11 ++ src/libjin/Common/je_temporary.h | 31 +++++ src/libjin/Filesystem/je_asset_database.cpp | 7 +- src/libjin/Filesystem/je_asset_database.h | 21 +++- src/libjin/Filesystem/je_buffer.h | 7 +- src/libjin/Game/je_entity.cpp | 11 ++ src/libjin/Game/je_entity.h | 31 ++++- src/libjin/Game/je_scene.cpp | 0 src/libjin/Game/je_scene.h | 4 +- src/libjin/Graphics/Font/je_texture_font.cpp | 4 +- src/libjin/Graphics/Font/je_texture_font.h | 4 +- src/libjin/Graphics/Font/je_ttf.h | 2 +- src/libjin/Graphics/Shader/je_default.shader.h | 2 +- src/libjin/Graphics/Shader/je_jsl_compiler.cpp | 40 ++++++- src/libjin/Graphics/Shader/je_jsl_compiler.h | 12 +- src/libjin/Graphics/Shader/je_shader.cpp | 73 ++++++------ src/libjin/Graphics/animation/je_animation.h | 3 + src/libjin/Graphics/animation/je_clip.h | 3 + src/libjin/Graphics/je_bitmap.h | 4 +- src/libjin/Graphics/je_canvas.cpp | 10 +- src/libjin/Graphics/je_canvas.h | 4 +- src/libjin/Graphics/je_color.h | 3 +- src/libjin/Graphics/je_drawable.cpp | 125 --------------------- src/libjin/Graphics/je_drawable.h | 89 --------------- src/libjin/Graphics/je_graphic.cpp | 117 +++++++++++++++++++ src/libjin/Graphics/je_graphic.h | 94 ++++++++++++++++ src/libjin/Graphics/je_sprite.h | 9 +- src/libjin/Graphics/je_texture.cpp | 2 +- src/libjin/Graphics/je_texture.h | 4 +- src/libjin/Graphics/je_window.cpp | 26 ++--- src/libjin/Graphics/je_window.h | 12 +- src/libjin/Graphics/particle/je_particle.h | 1 + src/libjin/Graphics/particle/je_particle_batch.h | 20 ++++ .../Graphics/particle/je_particle_emitter.cpp | 11 ++ src/libjin/Graphics/particle/je_particle_emitter.h | 23 ++++ src/libjin/core/je_configuration.h | 7 +- 39 files changed, 571 insertions(+), 318 deletions(-) create mode 100644 src/libjin/Common/je_noncopyable.h create mode 100644 src/libjin/Common/je_object.h create mode 100644 src/libjin/Common/je_pool.hpp create mode 100644 src/libjin/Common/je_temporary.h create mode 100644 src/libjin/Game/je_entity.cpp create mode 100644 src/libjin/Game/je_scene.cpp delete mode 100644 src/libjin/Graphics/je_drawable.cpp delete mode 100644 src/libjin/Graphics/je_drawable.h create mode 100644 src/libjin/Graphics/je_graphic.cpp create mode 100644 src/libjin/Graphics/je_graphic.h (limited to 'src/libjin') diff --git a/src/libjin/Common/je_exception.h b/src/libjin/Common/je_exception.h index e69de29..7c66af8 100644 --- a/src/libjin/Common/je_exception.h +++ b/src/libjin/Common/je_exception.h @@ -0,0 +1,22 @@ +#ifndef __JE_EXCEPTION_H +#define __JE_EXCEPTION_H + +#include + +namespace JinEngine +{ + + /// + /// Built-in exception class. + /// + class JinException : public std::exception + { + public: + JinException(); + const char* what() const throw(); + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_noncopyable.h b/src/libjin/Common/je_noncopyable.h new file mode 100644 index 0000000..89a3e68 --- /dev/null +++ b/src/libjin/Common/je_noncopyable.h @@ -0,0 +1,24 @@ +#ifndef __JE_NONCOPYABLE_H +#define __JE_NONCOPYABLE_H + +namespace JinEngine +{ + + /// + /// Class inherites this could not be copied. + /// + class Noncopyable + { + public: + Noncopyable(void) { } + virtual ~Noncopyable(void) { } + + private: + Noncopyable(const Noncopyable& other); + Noncopyable& operator=(const Noncopyable& other); + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h new file mode 100644 index 0000000..c256879 --- /dev/null +++ b/src/libjin/Common/je_object.h @@ -0,0 +1,16 @@ +#ifndef __JE_OBJECT_H +#define __JE_OBJECT_H + +namespace JinEngine +{ + + /// + /// Base class of all objects in Jin. + /// + class Object + { + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_pool.hpp b/src/libjin/Common/je_pool.hpp new file mode 100644 index 0000000..1107fd5 --- /dev/null +++ b/src/libjin/Common/je_pool.hpp @@ -0,0 +1,11 @@ +#ifndef __JE_POOL_H +#define __JE_POOL_H + +namespace JinEngine +{ + + + +} + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_temporary.h b/src/libjin/Common/je_temporary.h new file mode 100644 index 0000000..5af8704 --- /dev/null +++ b/src/libjin/Common/je_temporary.h @@ -0,0 +1,31 @@ +#ifndef __JE_ON_STACK_H +#define __JE_ON_STACK_H + +namespace JinEngine +{ + + /// + /// Class inherites this clound only be created on stack or static zone. + /// + class Temporary + { + public: + Temporary() {}; + virtual ~Temporary() {}; +/* + protected: + void operator delete(void* t) + { + if(t != nullptr) + free(t); + } +*/ + private: + // Disable new operands. + void* operator new(size_t); + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Filesystem/je_asset_database.cpp b/src/libjin/Filesystem/je_asset_database.cpp index 738b18f..ac547f0 100644 --- a/src/libjin/Filesystem/je_asset_database.cpp +++ b/src/libjin/Filesystem/je_asset_database.cpp @@ -46,7 +46,7 @@ namespace JinEngine Buffer* read(const char* path) { - + return nullptr; } void* AssetDatabase::read(const char* path, unsigned int* len) @@ -74,6 +74,11 @@ namespace JinEngine return smtexists(mSmt, path) == 0; } + std::vector AssetDatabase::getFiles(const char* path, bool recursive) + { + + } + } // namespace Filesystem } // namespace JinEngine diff --git a/src/libjin/Filesystem/je_asset_database.h b/src/libjin/Filesystem/je_asset_database.h index 3d47f15..8c30fc1 100644 --- a/src/libjin/Filesystem/je_asset_database.h +++ b/src/libjin/Filesystem/je_asset_database.h @@ -4,6 +4,8 @@ #include "../core/je_configuration.h" #if defined(jin_filesystem) +#include + #include "../3rdparty/smount/smount.h" #include "je_buffer.h" @@ -31,6 +33,13 @@ namespace JinEngine /// AssetDatabase(); + /// + /// Set asset root folder. + /// + /// @param root Root folder of assets. + /// + void mount(const char* root); + /// /// Check if the path is directory. /// @@ -73,11 +82,13 @@ namespace JinEngine void* read(const char* path, unsigned int* length); /// - /// Set asset root folder. - /// - /// @param root Root folder of assets. + /// Get files under given directory. + /// + /// @param path Path of directory. + /// @param recursive Recursivily search folder. + /// @return File list under given directory. /// - void mount(const char* root); + std::vector getFiles(const char* path, bool recursive); /// /// Get full path of asset. @@ -89,7 +100,9 @@ namespace JinEngine private: static AssetDatabase* mAssetDatabase; +#if jin_filesystem == jin_filesystem_smount smtShared* mSmt; +#endif }; diff --git a/src/libjin/Filesystem/je_buffer.h b/src/libjin/Filesystem/je_buffer.h index a2f4deb..0726e1d 100644 --- a/src/libjin/Filesystem/je_buffer.h +++ b/src/libjin/Filesystem/je_buffer.h @@ -7,6 +7,7 @@ #include #include +#include "../common/je_temporary.h" #include "../common/je_types.h" namespace JinEngine @@ -17,7 +18,7 @@ namespace JinEngine /// /// Data buffer allocated on heap. /// - class Buffer + class Buffer : public Temporary { public: /// @@ -158,10 +159,6 @@ namespace JinEngine byte* mData; size_t mSize; - // diasble new and delete - void* operator new(size_t t); - void operator delete(void*); - }; } // namespace Filesystem diff --git a/src/libjin/Game/je_entity.cpp b/src/libjin/Game/je_entity.cpp new file mode 100644 index 0000000..1396518 --- /dev/null +++ b/src/libjin/Game/je_entity.cpp @@ -0,0 +1,11 @@ +#include "je_entity.h" + +namespace JinEngine +{ + namespace Game + { + + + + } // namespace Game +} // namespace JinEngine \ No newline at end of file diff --git a/src/libjin/Game/je_entity.h b/src/libjin/Game/je_entity.h index 41a3c10..4a252da 100644 --- a/src/libjin/Game/je_entity.h +++ b/src/libjin/Game/je_entity.h @@ -4,9 +4,11 @@ #include "../core/je_configuration.h" #if defined(jin_game) +#include #include #include +#include "../common/je_object.h" #include "../common/je_types.h" namespace JinEngine @@ -17,24 +19,41 @@ namespace JinEngine /// /// Game object base class. /// - class Entity + class Entity : public Object { public: + + /// + /// + /// virtual ~Entity(); + /// + /// + /// void lifecycle(); + /// + /// + /// + void setVisible(bool isVisible); + + /// + /// + /// + void setActive(bool isActive); + protected: virtual void onAlive(); virtual void onUpdate(float dt); virtual void onDraw(); virtual void onDie(); - uint32 layer; // layer where entity belongs - uint32 index; // render index in layer - uint64 tag; // tag of entity - bool mIsVisible; - bool mIsActive; + uint32 layer; // layer where entity belongs + uint32 index; // render index in layer + uint64 tag; // tag of entity, 64 now + bool mIsVisible; // if the entity is visible or not + bool mIsActive; // if the entity is joined into the logic }; diff --git a/src/libjin/Game/je_scene.cpp b/src/libjin/Game/je_scene.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libjin/Game/je_scene.h b/src/libjin/Game/je_scene.h index 34d4569..f510a1f 100644 --- a/src/libjin/Game/je_scene.h +++ b/src/libjin/Game/je_scene.h @@ -65,8 +65,8 @@ namespace JinEngine }; - } -} + } // namespace Game +} // namespace JinEngine #endif // jin_game diff --git a/src/libjin/Graphics/Font/je_texture_font.cpp b/src/libjin/Graphics/Font/je_texture_font.cpp index f85a8ce..2c04815 100644 --- a/src/libjin/Graphics/Font/je_texture_font.cpp +++ b/src/libjin/Graphics/Font/je_texture_font.cpp @@ -245,7 +245,7 @@ namespace JinEngine } TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) - : Drawable(bitmap) + : Graphic(bitmap) , Font(cellh) { TextureGlyph glyph; @@ -266,7 +266,7 @@ namespace JinEngine } TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) - : Drawable(bitmap) + : Graphic(bitmap) , Font(cellh) { TextureGlyph glyph; diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h index 43d92c8..6276350 100644 --- a/src/libjin/Graphics/Font/je_texture_font.h +++ b/src/libjin/Graphics/Font/je_texture_font.h @@ -6,7 +6,7 @@ #include "../../math/je_vector4.hpp" -#include "../je_drawable.h" +#include "../je_graphic.h" #include "../je_bitmap.h" #include "je_page.h" @@ -22,7 +22,7 @@ namespace JinEngine /// /// class TextureFont : public Font - , public Drawable + , public Graphic { public: diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h index 7bc6934..e3d63b2 100644 --- a/src/libjin/Graphics/Font/je_ttf.h +++ b/src/libjin/Graphics/Font/je_ttf.h @@ -10,7 +10,7 @@ #include "../../math/je_quad.h" #include "../je_color.h" -#include "../je_drawable.h" +#include "../je_graphic.h" #include "je_page.h" #include "je_font.h" diff --git a/src/libjin/Graphics/Shader/je_default.shader.h b/src/libjin/Graphics/Shader/je_default.shader.h index f0175d7..3f57c44 100644 --- a/src/libjin/Graphics/Shader/je_default.shader.h +++ b/src/libjin/Graphics/Shader/je_default.shader.h @@ -14,7 +14,7 @@ Vertex vert(Vertex v) Color frag(Color col, Texture tex, Vertex v) { - return col; + return col * texel(tex, v.uv); } #END_FRAGMENT_SHADER diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp index 2683969..81b14e8 100644 --- a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp +++ b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp @@ -1,16 +1,54 @@ #include "../../core/je_configuration.h" #if defined(jin_graphics) && (jin_graphics & jin_graphics_shader) +#include "../../Filesystem/je_buffer.h" + #include "je_jsl_compiler.h" +using namespace std; +using namespace JinEngine::Filesystem; + namespace JinEngine { namespace Graphics { +#include "je_base.shader.h" + bool JSLCompiler::compile(const string& jsl, string* vertex_shader, string* fragment_shader) + { + // parse shader source, need some optimizations + int loc_VERTEX_SHADER = jsl.find("#VERTEX_SHADER"); + int loc_END_VERTEX_SHADER = jsl.find("#END_VERTEX_SHADER"); + int loc_FRAGMENT_SHADER = jsl.find("#FRAGMENT_SHADER"); + int loc_END_FRAGMENT_SHADER = jsl.find("#END_FRAGMENT_SHADER"); + if (loc_VERTEX_SHADER == string::npos + || loc_END_VERTEX_SHADER == string::npos + || loc_FRAGMENT_SHADER == string::npos + || loc_END_FRAGMENT_SHADER == string::npos + ) + return false; + // Load vertex and fragment shader source into buffers. + { + // Compile JSL vertex program. + int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER"); + *vertex_shader = jsl.substr(start, loc_END_VERTEX_SHADER - start); + Buffer vbuffer = Buffer(vertex_shader->length() + BASE_VERTEX_SHADER_SIZE); + formatVertexShader((char*)&vbuffer, vertex_shader->c_str()); + vertex_shader->assign((char*)&vbuffer); + } + { + // Compile JSL fragment program. + int start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER"); + *fragment_shader = jsl.substr(start, loc_END_FRAGMENT_SHADER - start); + Buffer fbuffer = Buffer(fragment_shader->length() + BASE_FRAGMENT_SHADER_SIZE); + formatFragmentShader((char*)&fbuffer, fragment_shader->c_str()); + fragment_shader->assign((char*)&fbuffer); + } + return true; + } } // namespace Graphics -} // namespace JinEngine +} // namespace JinEngine #endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.h b/src/libjin/Graphics/Shader/je_jsl_compiler.h index 1817a7b..29129e1 100644 --- a/src/libjin/Graphics/Shader/je_jsl_compiler.h +++ b/src/libjin/Graphics/Shader/je_jsl_compiler.h @@ -4,6 +4,8 @@ #include "../../core/je_configuration.h" #if defined(jin_graphics) && (jin_graphics & jin_graphics_shader) +#include + #include "../../common/je_singleton.hpp" namespace JinEngine @@ -17,7 +19,15 @@ namespace JinEngine class JSLCompiler : public Singleton { public: - + /// + /// Compile JSL shader source into GLSL. + /// + /// @param jsl JSL shader source. + /// @param glsl_vertex Output of vertex glsl shader source. + /// @param glsl_fragment Output of fragment glsl shader source. + /// @return True if compile successful, otherwise return false. + /// + bool compile(const std::string& jsl, std::string* glsl_vertex, std::string* glsl_fragment); private: singleton(JSLCompiler); diff --git a/src/libjin/Graphics/Shader/je_shader.cpp b/src/libjin/Graphics/Shader/je_shader.cpp index 6c8076a..b0e7506 100644 --- a/src/libjin/Graphics/Shader/je_shader.cpp +++ b/src/libjin/Graphics/Shader/je_shader.cpp @@ -6,6 +6,7 @@ #include "../../filesystem/je_buffer.h" #include "../../utils/je_macros.h" +#include "je_jsl_compiler.h" #include "je_shader.h" namespace JinEngine @@ -13,8 +14,8 @@ namespace JinEngine namespace Graphics { + using namespace std; using namespace JinEngine::Filesystem; - using namespace std; // // default_texture @@ -82,49 +83,39 @@ namespace JinEngine bool Shader::compile(const string& program) { - // parse shader source, need some optimizations - int loc_VERTEX_SHADER = program.find("#VERTEX_SHADER"); - int loc_END_VERTEX_SHADER = program.find("#END_VERTEX_SHADER"); - int loc_FRAGMENT_SHADER = program.find("#FRAGMENT_SHADER"); - int loc_END_FRAGMENT_SHADER = program.find("#END_FRAGMENT_SHADER"); - if (loc_VERTEX_SHADER == string::npos - || loc_END_VERTEX_SHADER == string::npos - || loc_FRAGMENT_SHADER == string::npos - || loc_END_FRAGMENT_SHADER == string::npos - ) - return false; - // load vertex and fragment shader source into buffers - int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER"); - string vertex_shader = program.substr(start, loc_END_VERTEX_SHADER - start); - Buffer vbuffer = Buffer(vertex_shader.length() + BASE_VERTEX_SHADER_SIZE); - formatVertexShader((char*)&vbuffer, vertex_shader.c_str()); - start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER"); - string fragment_shader = program.substr(start, loc_END_FRAGMENT_SHADER - start); - Buffer fbuffer = Buffer(fragment_shader.length() + BASE_FRAGMENT_SHADER_SIZE); - formatFragmentShader((char*)&fbuffer, fragment_shader.c_str()); - // compile - GLint success; - GLuint vshader = glCreateShader(GL_VERTEX_SHADER); - const byte* _data = &vbuffer; - glShaderSource(vshader, 1, (const GLchar**)&_data, NULL); - glCompileShader(vshader); - glGetShaderiv(vshader, GL_COMPILE_STATUS, &success); - if (success == GL_FALSE) - return false; - GLuint fshader = glCreateShader(GL_FRAGMENT_SHADER); - _data = &fbuffer; - glShaderSource(fshader, 1, (const GLchar**)&_data, NULL); - glCompileShader(fshader); - glGetShaderiv(fshader, GL_COMPILE_STATUS, &success); - if (success == GL_FALSE) - return false; + string vertex_shader, fragment_shader; + // Compile JSL shader source into GLSL shader source. + JSLCompiler* compiler = JSLCompiler::get(); + if (!compiler->compile(program, &vertex_shader, &fragment_shader)) + { + return false; + } +#define glsl(SHADER_MODE, SHADER, SRC) \ +do{ \ +const GLchar* src = SRC.c_str(); \ +glShaderSource(SHADER, 1, &src, NULL); \ +glCompileShader(SHADER); \ +GLint success; \ +glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \ +if (success == GL_FALSE) \ + return false; \ +}while(0) + // Compile vertex shader. + GLuint vid = glCreateShader(GL_VERTEX_SHADER); + glsl(GL_VERTEX_SHADER, vid, vertex_shader); + // Compile fragment shader. + GLuint fid = glCreateShader(GL_FRAGMENT_SHADER); + glsl(GL_FRAGMENT_SHADER, fid, fragment_shader); +#undef glsl + // Create OpenGL shader program. mPID = glCreateProgram(); - glAttachShader(mPID, vshader); - glAttachShader(mPID, fshader); + glAttachShader(mPID, vid); + glAttachShader(mPID, fid); glLinkProgram(mPID); + GLint success; glGetProgramiv(mPID, GL_LINK_STATUS, &success); if (success == GL_FALSE) - throw false; + return false; } static inline GLint getMaxTextureUnits() @@ -133,7 +124,7 @@ namespace JinEngine glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); return maxTextureUnits; } - + void Shader::use() { glUseProgram(mPID); diff --git a/src/libjin/Graphics/animation/je_animation.h b/src/libjin/Graphics/animation/je_animation.h index c006f83..f330a0c 100644 --- a/src/libjin/Graphics/animation/je_animation.h +++ b/src/libjin/Graphics/animation/je_animation.h @@ -6,6 +6,9 @@ namespace JinEngine namespace Graphics { + /// + /// + /// class Animation { diff --git a/src/libjin/Graphics/animation/je_clip.h b/src/libjin/Graphics/animation/je_clip.h index 35a35b3..d6709dc 100644 --- a/src/libjin/Graphics/animation/je_clip.h +++ b/src/libjin/Graphics/animation/je_clip.h @@ -6,6 +6,9 @@ namespace JinEngine namespace Graphics { + /// + /// Animation clip with key. + /// class Clip { diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h index 445bf91..ae97d0d 100644 --- a/src/libjin/Graphics/je_bitmap.h +++ b/src/libjin/Graphics/je_bitmap.h @@ -13,11 +13,11 @@ namespace JinEngine { namespace Graphics { + /// /// A RGBA32 bitmap. /// - /// A bitmap keeps pixels and can't render directly onto screen. To render bitmap, - /// a texture is required. A texture is create from specific bitmap. + /// A bitmap keeps pixels and can't draw directly onto screen. To render bitmap, a texture is required. /// class Bitmap { diff --git a/src/libjin/Graphics/je_canvas.cpp b/src/libjin/Graphics/je_canvas.cpp index 6406e5f..3841206 100644 --- a/src/libjin/Graphics/je_canvas.cpp +++ b/src/libjin/Graphics/je_canvas.cpp @@ -24,16 +24,16 @@ namespace JinEngine } Canvas::Canvas(int w, int h) - : Drawable(w, h) + : Graphic(w, h) { GLint current_fbo; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - // generate a new render buffer object + // Generate a new render buffer object fbo = gl.genFrameBuffer(); gl.bindFrameBuffer(fbo); - // generate texture save target + // Generate texture save target mTexture = gl.genTexture(); gl.bindTexture(mTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -44,7 +44,7 @@ namespace JinEngine GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - /* unbind framebuffer */ + // Unbind framebuffer gl.bindFrameBuffer(current_fbo); } @@ -67,7 +67,7 @@ namespace JinEngine gl.bindFrameBuffer(canvas->fbo); int w = canvas->mSize.w; int h = canvas->mSize.h; - /* set view port to canvas */ + // Set view port to canvas. glViewport(0, 0, w, h); gl.ProjectionMatrix.setOrtho(0, w, 0, h, -1, 1); } diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h index a4c0330..f39b0de 100644 --- a/src/libjin/Graphics/je_canvas.h +++ b/src/libjin/Graphics/je_canvas.h @@ -3,7 +3,7 @@ #include "../core/je_configuration.h" #if defined(jin_graphics) -#include "je_drawable.h" +#include "je_graphic.h" namespace JinEngine { @@ -14,7 +14,7 @@ namespace JinEngine /// /// A canvas is a rendering target. /// - class Canvas: public Drawable + class Canvas: public Graphic { public: /// diff --git a/src/libjin/Graphics/je_color.h b/src/libjin/Graphics/je_color.h index 80c1e4d..8fe7691 100644 --- a/src/libjin/Graphics/je_color.h +++ b/src/libjin/Graphics/je_color.h @@ -6,6 +6,7 @@ #include "../core/je_configuration.h" #if defined(jin_graphics) +#include "../common/je_types.h" #include "../utils/je_endian.h" namespace JinEngine @@ -13,7 +14,7 @@ namespace JinEngine namespace Graphics { - typedef unsigned char Channel; + typedef uint8 Channel; class Color { diff --git a/src/libjin/Graphics/je_drawable.cpp b/src/libjin/Graphics/je_drawable.cpp deleted file mode 100644 index 7480a32..0000000 --- a/src/libjin/Graphics/je_drawable.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "../core/je_configuration.h" -#if defined(jin_graphics) - -#include - -#include "../math/je_matrix.h" - -#include "shader/je_shader.h" -#include "je_drawable.h" - -namespace JinEngine -{ - namespace Graphics - { - - Drawable::Drawable(int w, int h) - : mTexture(0) - , mSize(w, h) - , mOrigin(0, 0) - { - mVertexCoords[0] = 0; mVertexCoords[1] = 0; - mVertexCoords[2] = 0; mVertexCoords[3] = h; - mVertexCoords[4] = w; mVertexCoords[5] = h; - mVertexCoords[6] = w; mVertexCoords[7] = 0; - - mTextureCoords[0] = 0; mTextureCoords[1] = 0; - mTextureCoords[2] = 0; mTextureCoords[3] = 1; - mTextureCoords[4] = 1; mTextureCoords[5] = 1; - mTextureCoords[6] = 1; mTextureCoords[7] = 0; - } - - Drawable::Drawable(const Bitmap* bitmap) - : mTexture(0) - , mOrigin(0, 0) - { - uint32 w = mSize.w = bitmap->getWidth(); - uint32 h = mSize.h = bitmap->getHeight(); - - mVertexCoords[0] = 0; mVertexCoords[1] = 0; - mVertexCoords[2] = 0; mVertexCoords[3] = h; - mVertexCoords[4] = w; mVertexCoords[5] = h; - mVertexCoords[6] = w; mVertexCoords[7] = 0; - - mTextureCoords[0] = 0; mTextureCoords[1] = 0; - mTextureCoords[2] = 0; mTextureCoords[3] = 1; - mTextureCoords[4] = 1; mTextureCoords[5] = 1; - mTextureCoords[6] = 1; mTextureCoords[7] = 0; - - const Color* pixels = bitmap->getPixels(); - - mTexture = gl.genTexture(); - gl.bindTexture(mTexture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - gl.bindTexture(0); - } - - Drawable::~Drawable() - { - glDeleteTextures(1, &mTexture); - } - - void Drawable::setOrigin(int x, int y) - { - mOrigin.x = x; - mOrigin.y = y; - } - - void Drawable::draw(int x, int y, float sx, float sy, float r) - { - gl.ModelMatrix.setTransformation(x, y, r, sx, sy, mOrigin.x, mOrigin.y); - - Shader* shader = Shader::getCurrentShader(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - shader->bindVertexPointer(2, GL_FLOAT, 0, mVertexCoords); - shader->bindUVPointer(2, GL_FLOAT, 0, mTextureCoords); - - gl.bindTexture(mTexture); - gl.drawArrays(GL_QUADS, 0, 4); - gl.bindTexture(0); - } - - void Drawable::draw(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) - { - float vertCoords[8] = { - 0, 0, - 0, slice.h, - slice.w, slice.h, - slice.w, 0 - }; - float slx = slice.x / mSize.w; - float sly = slice.y / mSize.h; - float slw = slice.w / mSize.w; - float slh = slice.h / mSize.h; - float texCoords[8] = { - slx, sly, - slx, sly + slh, - slx + slw, sly + slh, - slx + slw, sly - }; - - gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay); - - Shader* shader = Shader::getCurrentShader(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords); - shader->bindUVPointer(2, GL_FLOAT, 0, texCoords); - - gl.bindTexture(mTexture); - gl.drawArrays(GL_QUADS, 0, 4); - gl.bindTexture(0); - } - - //void Drawable::setFilter(GLint min, GLint max) - //{ - // glTexParameteri(GL_) - //} - - } // namespace Graphics -} // namespace JinEngine - -#endif // defined(jin_graphics) \ No newline at end of file diff --git a/src/libjin/Graphics/je_drawable.h b/src/libjin/Graphics/je_drawable.h deleted file mode 100644 index fdf9ea2..0000000 --- a/src/libjin/Graphics/je_drawable.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef __JE_DRAWABLE -#define __JE_DRAWABLE -#include "../core/je_configuration.h" -#if defined(jin_graphics) - -#include "../math/je_quad.h" -#include "../math/je_vector2.hpp" - -#include "je_gl.h" -#include "je_bitmap.h" - -namespace JinEngine -{ - namespace Graphics - { - /// - /// - /// - class Drawable - { - public: - /// - /// - /// - Drawable(int w = 0, int h = 0); - - /// - /// - /// - Drawable(const Bitmap* bitmap); - - /// - /// - /// - virtual ~Drawable(); - - /// - /// - /// - void setOrigin(int x, int y); - - /// - /// - /// - void draw(int x, int y, float sx = 1, float sy = 1, float r = 0); - - /// - /// - /// - void draw(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0); - - /// - /// - /// - inline int getWidth() const { return mSize.w; } - - /// - /// - /// - inline int getHeight() const { return mSize.h; } - - /// - /// - /// - inline GLuint getTexture() const { return mTexture; } - - /// - /// - /// - void setFilter(GLint min, GLint max); - - protected: - static const int DRAWABLE_V_SIZE = 8; - - GLuint mTexture; - GLuint mVBO; - JinEngine::Math::Vector2 mSize; - JinEngine::Math::Vector2 mOrigin; - float mVertexCoords[DRAWABLE_V_SIZE]; - float mTextureCoords[DRAWABLE_V_SIZE]; - - }; - - } // namespace Graphics -} // namespace JinEngine - -#endif // defined(jin_graphics) - -#endif // __JE_DRAWABLE \ No newline at end of file diff --git a/src/libjin/Graphics/je_graphic.cpp b/src/libjin/Graphics/je_graphic.cpp new file mode 100644 index 0000000..831e409 --- /dev/null +++ b/src/libjin/Graphics/je_graphic.cpp @@ -0,0 +1,117 @@ +#include "../core/je_configuration.h" +#if defined(jin_graphics) + +#include + +#include "../math/je_matrix.h" + +#include "shader/je_shader.h" +#include "je_graphic.h" + +namespace JinEngine +{ + namespace Graphics + { + + Graphic::Graphic(int w, int h) + : mTexture(0) + , mSize(w, h) + { + mVertexCoords[0] = 0; mVertexCoords[1] = 0; + mVertexCoords[2] = 0; mVertexCoords[3] = h; + mVertexCoords[4] = w; mVertexCoords[5] = h; + mVertexCoords[6] = w; mVertexCoords[7] = 0; + + mTextureCoords[0] = 0; mTextureCoords[1] = 0; + mTextureCoords[2] = 0; mTextureCoords[3] = 1; + mTextureCoords[4] = 1; mTextureCoords[5] = 1; + mTextureCoords[6] = 1; mTextureCoords[7] = 0; + } + + Graphic::Graphic(const Bitmap* bitmap) + : mTexture(0) + { + uint32 w = mSize.w = bitmap->getWidth(); + uint32 h = mSize.h = bitmap->getHeight(); + + mVertexCoords[0] = 0; mVertexCoords[1] = 0; + mVertexCoords[2] = 0; mVertexCoords[3] = h; + mVertexCoords[4] = w; mVertexCoords[5] = h; + mVertexCoords[6] = w; mVertexCoords[7] = 0; + + mTextureCoords[0] = 0; mTextureCoords[1] = 0; + mTextureCoords[2] = 0; mTextureCoords[3] = 1; + mTextureCoords[4] = 1; mTextureCoords[5] = 1; + mTextureCoords[6] = 1; mTextureCoords[7] = 0; + + const Color* pixels = bitmap->getPixels(); + + mTexture = gl.genTexture(); + gl.bindTexture(mTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + gl.bindTexture(0); + } + + Graphic::~Graphic() + { + glDeleteTextures(1, &mTexture); + } + + void Graphic::draw(int x, int y, float sx, float sy, float r, float ox, float oy) + { + gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy); + + Shader* shader = Shader::getCurrentShader(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, mVertexCoords); + shader->bindUVPointer(2, GL_FLOAT, 0, mTextureCoords); + + gl.bindTexture(mTexture); + gl.drawArrays(GL_QUADS, 0, 4); + gl.bindTexture(0); + } + + void Graphic::draw(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) + { + float vertCoords[8] = { + 0, 0, + 0, slice.h, + slice.w, slice.h, + slice.w, 0 + }; + float slx = slice.x / mSize.w; + float sly = slice.y / mSize.h; + float slw = slice.w / mSize.w; + float slh = slice.h / mSize.h; + float texCoords[8] = { + slx, sly, + slx, sly + slh, + slx + slw, sly + slh, + slx + slw, sly + }; + + gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay); + + Shader* shader = Shader::getCurrentShader(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords); + shader->bindUVPointer(2, GL_FLOAT, 0, texCoords); + + gl.bindTexture(mTexture); + gl.drawArrays(GL_QUADS, 0, 4); + gl.bindTexture(0); + } + + //void Graphic::setFilter(GLint min, GLint max) + //{ + // glTexParameteri(GL_) + //} + + } // namespace Graphics +} // namespace JinEngine + +#endif // defined(jin_graphics) \ No newline at end of file diff --git a/src/libjin/Graphics/je_graphic.h b/src/libjin/Graphics/je_graphic.h new file mode 100644 index 0000000..d7e3254 --- /dev/null +++ b/src/libjin/Graphics/je_graphic.h @@ -0,0 +1,94 @@ +#ifndef __JE_DRAWABLE +#define __JE_DRAWABLE +#include "../core/je_configuration.h" +#if defined(jin_graphics) + +#include "../math/je_quad.h" +#include "../math/je_vector2.hpp" + +#include "je_gl.h" +#include "je_bitmap.h" + +namespace JinEngine +{ + namespace Graphics + { + + // + // Graphic + // |-Texture + // |-Canvas + // + + /// + /// Class inherites Graphic doesn't keep any state such as origin, scale and other + /// properties. + /// + class Graphic + { + public: + /// + /// + /// + Graphic(int w = 0, int h = 0); + + /// + /// + /// + Graphic(const Bitmap* bitmap); + + /// + /// + /// + virtual ~Graphic(); + + /// + /// + /// + void draw(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0); + + /// + /// + /// + void draw(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0); + + /// + /// + /// + inline int getWidth() const { return mSize.w; } + + /// + /// + /// + inline int getHeight() const { return mSize.h; } + + /// + /// + /// + inline GLuint getTexture() const { return mTexture; } + + /// + /// + /// + void setFilter(GLint min, GLint max); + + protected: + static const int DRAWABLE_V_SIZE = 8; + + GLuint mTexture; + + // Size of drawable thing. + JinEngine::Math::Vector2 mSize; + + // Screen coordinates and uv coordinates. + float mVertexCoords[DRAWABLE_V_SIZE]; + float mTextureCoords[DRAWABLE_V_SIZE]; + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif // defined(jin_graphics) + +#endif // __JE_DRAWABLE \ No newline at end of file diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index 4273240..3b96162 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -17,11 +17,16 @@ namespace JinEngine class Sprite { public: + void setOrigin(float x, float y); + void setPosition(int x, int y); + void setScale(float x, float y); + void setColor(Color color); + void setShader(const Shader* shader); private: Math::Vector2 mPosition; - Math::Vector2 mOrigin; - Math::Vector2 mScale; + Math::Vector2 mOrigin; + Math::Vector2 mScale; Color mColor; const Shader* mShader; diff --git a/src/libjin/Graphics/je_texture.cpp b/src/libjin/Graphics/je_texture.cpp index d191c8b..8aa3f9a 100644 --- a/src/libjin/Graphics/je_texture.cpp +++ b/src/libjin/Graphics/je_texture.cpp @@ -30,7 +30,7 @@ namespace JinEngine } Texture::Texture(const Bitmap* bitmap) - : Drawable(bitmap) + : Graphic(bitmap) { } diff --git a/src/libjin/Graphics/je_texture.h b/src/libjin/Graphics/je_texture.h index 5238aa1..ddc8cfc 100644 --- a/src/libjin/Graphics/je_texture.h +++ b/src/libjin/Graphics/je_texture.h @@ -6,7 +6,7 @@ #include "../3rdparty/GLee/GLee.h" #include "je_color.h" -#include "je_drawable.h" +#include "je_graphic.h" #include "je_bitmap.h" namespace JinEngine @@ -17,7 +17,7 @@ namespace JinEngine /// /// /// - class Texture: public Drawable + class Texture: public Graphic { public: /// diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp index 8c36c85..f0b789e 100644 --- a/src/libjin/Graphics/je_window.cpp +++ b/src/libjin/Graphics/je_window.cpp @@ -27,15 +27,15 @@ namespace JinEngine return false; const Setting* setting = (Setting*)s; - size.w = setting->width; - size.h = setting->height; - fps = setting->fps; + mSize.w = setting->width; + mSize.h = setting->height; + mFps = setting->fps; bool vsync = setting->vsync; const char* title = setting->title; - if (wnd) + if (mWnd) { - SDL_DestroyWindow(wnd); + SDL_DestroyWindow(mWnd); SDL_FlushEvent(SDL_WINDOWEVENT); } @@ -62,14 +62,14 @@ namespace JinEngine if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN; if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE; - wnd = SDL_CreateWindow(title, wx, wy, size.w, size.h, flag); - if (wnd == NULL) + mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag); + if (mWnd == NULL) return false; - ctx = SDL_GL_CreateContext(wnd); + ctx = SDL_GL_CreateContext(mWnd); if (ctx == NULL) return false; SDL_GL_SetSwapInterval(vsync ? 1 : 0); - SDL_GL_MakeCurrent(wnd, ctx); + SDL_GL_MakeCurrent(mWnd, ctx); // default configuration gl.setClearColor(0, 0, 0, 0xff); gl.pushColor(0xff, 0xff, 0xff, 0xff); @@ -90,19 +90,19 @@ namespace JinEngine gl.disable(GL_BLEND); gl.disable(GL_TEXTURE_2D); // close window - SDL_DestroyWindow(wnd); + SDL_DestroyWindow(mWnd); SDL_Quit(); } void Window::swapBuffers() { - if (wnd) - SDL_GL_SwapWindow(wnd); + if (mWnd) + SDL_GL_SwapWindow(mWnd); } void Window::setTitle(const char* title) { - SDL_SetWindowTitle(wnd, title); + SDL_SetWindowTitle(mWnd, title); }; } // namespace Graphics diff --git a/src/libjin/Graphics/je_window.h b/src/libjin/Graphics/je_window.h index 0969a36..7ca1e5e 100644 --- a/src/libjin/Graphics/je_window.h +++ b/src/libjin/Graphics/je_window.h @@ -41,17 +41,17 @@ namespace JinEngine /// /// /// - inline int getW(){ return size.w; } + inline int getW(){ return mSize.w; } /// /// /// - inline int getH(){ return size.h; } + inline int getH(){ return mSize.h; } /// /// /// - inline int getFPS(){ return fps; } + inline int getFPS(){ return mFps; } /// /// @@ -83,9 +83,9 @@ namespace JinEngine /// void quitSystem() override; - SDL_Window* wnd; - JinEngine::Math::Vector2 size; - int fps; + SDL_Window* mWnd; + JinEngine::Math::Vector2 mSize; + int mFps; }; diff --git a/src/libjin/Graphics/particle/je_particle.h b/src/libjin/Graphics/particle/je_particle.h index ba4dd18..2a5c54f 100644 --- a/src/libjin/Graphics/particle/je_particle.h +++ b/src/libjin/Graphics/particle/je_particle.h @@ -11,6 +11,7 @@ namespace JinEngine /// class Particle { + }; diff --git a/src/libjin/Graphics/particle/je_particle_batch.h b/src/libjin/Graphics/particle/je_particle_batch.h index e69de29..19f4ded 100644 --- a/src/libjin/Graphics/particle/je_particle_batch.h +++ b/src/libjin/Graphics/particle/je_particle_batch.h @@ -0,0 +1,20 @@ +#ifndef __JE_PARTICLE_BATCH_H +#define __JE_PARTICLE_BATCH_H + +namespace JinEngine +{ + namespace Graphics + { + + /// + /// + /// + class ParticleBatch + { + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Graphics/particle/je_particle_emitter.cpp b/src/libjin/Graphics/particle/je_particle_emitter.cpp index e69de29..d57d5ed 100644 --- a/src/libjin/Graphics/particle/je_particle_emitter.cpp +++ b/src/libjin/Graphics/particle/je_particle_emitter.cpp @@ -0,0 +1,11 @@ +#include "je_particle_emitter.h" + +namespace JinEngine +{ + namespace Graphics + { + + + + } +} diff --git a/src/libjin/Graphics/particle/je_particle_emitter.h b/src/libjin/Graphics/particle/je_particle_emitter.h index e69de29..e191e36 100644 --- a/src/libjin/Graphics/particle/je_particle_emitter.h +++ b/src/libjin/Graphics/particle/je_particle_emitter.h @@ -0,0 +1,23 @@ +#ifndef __JE_PARTICLE_EMMITTER_H +#define __JE_PARTICLE_EMMITTER_H + +namespace JinEngine +{ + namespace Graphics + { + + /// + /// Particle emitter + /// + class ParticleEmitter + { + public: + + private: + + }; + + } +} + +#endif \ No newline at end of file diff --git a/src/libjin/core/je_configuration.h b/src/libjin/core/je_configuration.h index 167ffd0..34c3a74 100644 --- a/src/libjin/core/je_configuration.h +++ b/src/libjin/core/je_configuration.h @@ -1,6 +1,8 @@ #ifndef __JE_COMMON_MODULES_H #define __JE_COMMON_MODULES_H +#define jin_undefined 0x00 + #define jin_debug #define jin_os_windows 0x01 @@ -18,14 +20,13 @@ #define jin_audio_openal 0x02 #define jin_audio jin_audio_sdl -#define jin_filesystem +#define jin_filesystem_smount 0x01 +#define jin_filesystem jin_filesystem_smount #define jin_game #define jin_core -#define jin_filesystem - #define jin_input_sdl 0x01 #define jin_input jin_input_sdl -- cgit v1.1-26-g67d0