diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/Graphics/Bitmap.h | 101 | ||||
-rw-r--r-- | src/libjin/Graphics/Canvas.h | 31 | ||||
-rw-r--r-- | src/libjin/Graphics/Drawable.cpp | 5 | ||||
-rw-r--r-- | src/libjin/Graphics/Drawable.h | 5 | ||||
-rw-r--r-- | src/libjin/Graphics/Image.h | 3 | ||||
-rw-r--r-- | src/libjin/Graphics/Shader/Shader.cpp | 96 | ||||
-rw-r--r-- | src/libjin/Graphics/Shader/Shader.h | 6 | ||||
-rw-r--r-- | src/libjin/Graphics/Sprite.h | 10 | ||||
-rw-r--r-- | src/libjin/Graphics/Texture.h | 18 |
9 files changed, 203 insertions, 72 deletions
diff --git a/src/libjin/Graphics/Bitmap.h b/src/libjin/Graphics/Bitmap.h index bb30bdc..4341256 100644 --- a/src/libjin/Graphics/Bitmap.h +++ b/src/libjin/Graphics/Bitmap.h @@ -44,7 +44,7 @@ namespace jin /// /// @param width Width of bitmap. /// @param height Height of bitmap. - /// @param color Color of bitmap. + /// @param color Color of bitmap, black by default. /// @return Return bitmap pointer if created, otherwise return null. /// static Bitmap* createBitmap(int width, int height, Color color = Color::BLACK); @@ -61,23 +61,104 @@ namespace jin /// Destructor of bitmap /// virtual ~Bitmap(); - /* init pixels */ - void bind(Color* pixels, int w, int h); - void resetPixels(const Color* pixels, int w, int h); - void resetPixels(const Color& pixels, int w, int h); - /* modify pixels */ - void setPixel(const Color& pixel, int x, int y); - void setPixels(Color pixels); - void setPixels(Color* pixels); + + /// + /// Directly bind pixels with given pixels data + /// + /// @param pixels Pixels to be binded. + /// @param width Width of bitmap + /// @param height Height of bitmap + /// + void bind(Color* pixels, int width, int height); + + /// + /// Reset pixel data with given pixels data. + /// + /// @param pixels Pixels to be set. + /// @param width Width of bitmap + /// @param height Height of bitmap + /// + void resetPixels(const Color* pixels, int width, int height); + + /// + /// Reset pixel data with given color. + /// + /// @param color Color to be set. + /// @param width Width of bitmap + /// @param height Height of bitmap + /// + void resetPixels(const Color& color, int width, int height); + + /// + /// Set pixel with given color. + /// + /// @param color Color to be set. + /// @param x X value of pixel. + /// @param y Y value of pixel. + /// + void setPixel(const Color& color, int x, int y); + + /// + /// Set pixels with given color. + /// + /// @param color Color to be set. + /// + void setPixels(Color color); + + /// + /// Set pixels with given color data. + /// + /// @param colors New pixels' colors. + /// + void setPixels(Color* colors); + + /// + /// Get pixel in given position. + /// + /// @param x X value of position. + /// @param y Y value of position. + /// Color getPixel(int x, int y); + + /// + /// Get pixels. + /// @return Colors of the bitmap. + /// const Color* getPixels() const; - /* get width and height */ + + /// + /// Get bitmap width. + /// + /// @return Width of bitmap. + /// inline int getWidth() const { return width; } + + /// + /// Get bitmap height. + /// + /// @return Height of bitmap. + /// inline int getHeight() const { return height; } + + /// + /// Get bitmap size. + /// + /// @return Size of bitmap. + /// inline math::Vector2<int> getSize() const { return math::Vector2<int>(width, height); } protected: + /// + /// Constructor of bitmap. + /// Bitmap(); + + /// + /// Constructor of bitmap. + /// + /// @param width Width of bitmap. + /// @param height Height of bitmap. + /// Bitmap(unsigned w, unsigned h); Color * pixels; diff --git a/src/libjin/Graphics/Canvas.h b/src/libjin/Graphics/Canvas.h index 0a261a8..53070bf 100644 --- a/src/libjin/Graphics/Canvas.h +++ b/src/libjin/Graphics/Canvas.h @@ -8,28 +8,55 @@ namespace jin { namespace graphics { - + /// + /// Renderable canvas. + /// + /// A canvas is a rendering target. + /// class Canvas: public Drawable { public: + /// + /// + /// static Canvas* createCanvas(int w, int h); + /// + /// + /// static void bind(Canvas*); + + /// + /// + /// static void unbind(); + + /// + /// + /// static bool isBinded(const Canvas*); + /// + /// + /// ~Canvas(); protected: static const Canvas* const DEFAULT_CANVAS; static const Canvas* current; + /// + /// + /// Canvas(int w, int h); + + /// + /// + /// Canvas(GLuint n); GLuint fbo; - }; } // namespace graphics diff --git a/src/libjin/Graphics/Drawable.cpp b/src/libjin/Graphics/Drawable.cpp index 80a6cce..f819c9c 100644 --- a/src/libjin/Graphics/Drawable.cpp +++ b/src/libjin/Graphics/Drawable.cpp @@ -112,6 +112,11 @@ namespace jin gl.bindTexture(0); } + //void Drawable::setFilter(GLint min, GLint max) + //{ + // glTexParameteri(GL_) + //} + } // namespace graphics } // namespace jin diff --git a/src/libjin/Graphics/Drawable.h b/src/libjin/Graphics/Drawable.h index 95af75e..007a9a1 100644 --- a/src/libjin/Graphics/Drawable.h +++ b/src/libjin/Graphics/Drawable.h @@ -63,6 +63,11 @@ namespace jin /// inline GLuint getTexture() const { return texture; } + /// + /// + /// + void setFilter(GLint min, GLint max); + protected: static const int DRAWABLE_V_SIZE = 8; diff --git a/src/libjin/Graphics/Image.h b/src/libjin/Graphics/Image.h index 53eb0d7..55798be 100644 --- a/src/libjin/Graphics/Image.h +++ b/src/libjin/Graphics/Image.h @@ -11,8 +11,7 @@ namespace jin /// /// A readonly bitmap. /// - /// Just like bitmap but only from image file. The pixels data - /// is readonly. + /// Just like bitmap but only from image file. The pixels data is readonly. /// class Image : public Bitmap { diff --git a/src/libjin/Graphics/Shader/Shader.cpp b/src/libjin/Graphics/Shader/Shader.cpp index 877ef5b..a075d7d 100644 --- a/src/libjin/Graphics/Shader/Shader.cpp +++ b/src/libjin/Graphics/Shader/Shader.cpp @@ -1,6 +1,6 @@ #include <regex> #include "../../configuration.h" -#if LIBJIN_MODULES_RENDER +#if defined(jin_graphics_shader) #include <iostream> @@ -15,37 +15,37 @@ namespace jin using namespace jin::filesystem; using namespace std; - /** - * default_texture - * base_shader - * SHADER_FORMAT_SIZE - * formatShader - */ + // + // default_texture + // base_shader + // SHADER_FORMAT_SIZE + // formatShader + // #include "default.shader.h" - /** - * https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value - * The default value of a sampler variable is 0. From the GLSL 3.30 spec, - * section "4.3.5 Uniforms": - * - * The link time initial value is either the value of the variable's - * initializer, if present, or 0 if no initializer is present.Sampler - * types cannot have initializers. - * - * Since a value of 0 means that it's sampling from texture unit 0, it will - * work without ever setting the value as long as you bind your textures to - * unit 0. This is well defined behavior. - * - * Since texture unit 0 is also the default until you call glActiveTexture() - * with a value other than GL_TEXTURE0, it's very common to always use unit - * 0 as long as shaders do not need more than one texture.Which means that - * often times, setting the sampler uniforms is redundant for simple - * applications. - * - * I would still prefer to always set the values.If nothing else, it makes - * it clear to anybody reading your code that you really mean to sample from - * texture unit 0, and did not just forget to set the value. - */ + // + // https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value + // The default value of a sampler variable is 0. From the GLSL 3.30 spec, + // section "4.3.5 Uniforms": + // + // The link time initial value is either the value of the variable's + // initializer, if present, or 0 if no initializer is present.Sampler + // types cannot have initializers. + // + // Since a value of 0 means that it's sampling from texture unit 0, it will + // work without ever setting the value as long as you bind your textures to + // unit 0. This is well defined behavior. + // + // Since texture unit 0 is also the default until you call glActiveTexture() + // with a value other than GL_TEXTURE0, it's very common to always use unit + // 0 as long as shaders do not need more than one texture.Which means that + // often times, setting the sampler uniforms is redundant for simple + // applications. + // + // I would still prefer to always set the values.If nothing else, it makes + // it clear to anybody reading your code that you really mean to sample from + // texture unit 0, and did not just forget to set the value. + // const int DEFAULT_TEXTURE_UNIT = 0; /*static*/ Shader* Shader::CurrentShader = nullptr; @@ -79,7 +79,7 @@ namespace jin bool Shader::compile(const string& program) { - /* parse shader source, need some optimizations */ + // 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"); @@ -90,7 +90,7 @@ namespace jin || loc_END_FRAGMENT_SHADER == string::npos ) return false; - /* load vertex and fragment shader source into buffers */ + // 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); @@ -99,7 +99,7 @@ namespace jin string fragment_shader = program.substr(start, loc_END_FRAGMENT_SHADER - start); Buffer fbuffer = Buffer(fragment_shader.length() + BASE_FRAGMENT_SHADER_SIZE); formatFragmentShader((char*)fbuffer.data, fragment_shader.c_str()); - /* compile */ + // compile GLint success; GLuint vshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vshader, 1, (const GLchar**)&vbuffer.data, NULL); @@ -172,20 +172,20 @@ namespace jin glUniform1f(loc, number); } - /** - * https://www.douban.com/note/627332677/ - * struct TextureUnit - * { - * GLuint targetTexture1D; - * GLuint targetTexture2D; - * GLuint targetTexture3D; - * GLuint targetTextureCube; - * ... - * }; - * - * TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS] - * GLuint mCurrentTextureUnit = 0; - */ + // + // https://www.douban.com/note/627332677/ + // struct TextureUnit + // { + // GLuint targetTexture1D; + // GLuint targetTexture2D; + // GLuint targetTexture3D; + // GLuint targetTextureCube; + // ... + // }; + // + // TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS] + // GLuint mCurrentTextureUnit = 0; + // void Shader::sendTexture(const char* variable, const Texture* tex) { checkJSL(); @@ -279,4 +279,4 @@ namespace jin } // namespace graphics } // namespace jin -#endif // LIBJIN_MODULES_RENDER
\ No newline at end of file +#endif // jin_graphics_shader
\ No newline at end of file diff --git a/src/libjin/Graphics/Shader/Shader.h b/src/libjin/Graphics/Shader/Shader.h index d91b539..71579a9 100644 --- a/src/libjin/Graphics/Shader/Shader.h +++ b/src/libjin/Graphics/Shader/Shader.h @@ -20,9 +20,9 @@ namespace jin /// /// Built in shader program. /// - /// Built in shader program written with custom shading language called JSL - /// (jin shading language). A JSL program is compiled into glsl, so most glsl - /// built in functions and structs are available in JSL. + /// Built in shader program written with custom shading language called JSL (jin + /// shading language). A JSL program is compiled into glsl, so most glsl built in + /// functions and structs are available in JSL. /// class Shader { diff --git a/src/libjin/Graphics/Sprite.h b/src/libjin/Graphics/Sprite.h index 2c7e0f5..7a4e53a 100644 --- a/src/libjin/Graphics/Sprite.h +++ b/src/libjin/Graphics/Sprite.h @@ -5,11 +5,13 @@ namespace jin { namespace graphics { - - /* just like texture but with x,y */ - class Sprite + /// + /// A sprite is a transformable texture. + /// + class Sprite { - + public: + }; } diff --git a/src/libjin/Graphics/Texture.h b/src/libjin/Graphics/Texture.h index 45f3f34..3e0161c 100644 --- a/src/libjin/Graphics/Texture.h +++ b/src/libjin/Graphics/Texture.h @@ -1,7 +1,7 @@ #ifndef __LIBJIN_TEXTURE_H #define __LIBJIN_TEXTURE_H #include "../configuration.h" -#if LIBJIN_MODULES_RENDER +#if defined(jin_graphics) #include "../3rdparty/GLee/GLee.h" #include "Color.h" @@ -11,15 +11,26 @@ namespace jin { namespace graphics { - + /// + /// + /// class Texture: public Drawable { public: + /// + /// + /// static Texture* createTexture(Bitmap* bitmap); + /// + /// + /// ~Texture(); private: + /// + /// + /// Texture(const Bitmap* bitmap); }; @@ -27,5 +38,6 @@ namespace jin } // namespace graphics } // namespace jin -#endif // LIBJIN_MODULES_RENDER +#endif // jin_graphics + #endif // __LIBJIN_TEXTURE_H
\ No newline at end of file |