public static void set( ClassTexture texture, ClassBitmap bitmap, CompoundVector2 pos ) { int[] data = bitmap.property_data; int count = data.Length; int w = bitmap.property_width; int h = bitmap.property_height; Color[] colors = new Color[w*h]; int src_pos = -1; int dest_pos = -1; for (int j=h; j>0; --j) { for (int i=w; i>0; --i) { // premultiply color components by alpha component int c = data[++src_pos]; int a = (c >> 24) & 255; int r = (c >> 16) & 255; int g = (c >> 8) & 255; int b = c & 255; colors[++dest_pos] = new Color( (r*a)/255, (g*a)/255, (b*a)/255, a ); } } Texture2D tex = ((NativeTextureData) texture.property_native_data).texture; tex.SetData<Color>( 0, new Rectangle((int)pos.property_x,(int)pos.property_y,w,h), colors, 0, w*h ); }
public static void set_textured_triangle_mode( ClassTexture texture, ClassTexture alpha_mask ) { if (alpha_mask == null) { set_textured_triangle_mode( ((NativeTextureData) texture.property_native_data).texture, null ); } else { set_textured_triangle_mode( ((NativeTextureData) texture.property_native_data).texture, (alpha_mask.property_native_data as NativeTextureData).texture ); } }
public static void init( ClassTexture texture, CompoundVector2 size, int pixel_format ) { int w = (int) size.property_x; int h = (int) size.property_y; int wp2 = 1; while (wp2 < w) wp2 <<= 1; int hp2 = 1; while (hp2 < h) hp2 <<= 1; Texture2D tex = new Texture2D( Plasmacore.device, wp2, hp2, false, SurfaceFormat.Color ); texture.property_native_data = new NativeTextureData(tex); texture.property_image_size.property_x = w; texture.property_image_size.property_y = h; texture.property_texture_size.property_x = wp2; texture.property_texture_size.property_y = hp2; }
public static void native_release( ClassTexture texture ) { if (texture.property_native_data != null) { texture.property_native_data.release(); texture.property_native_data = null; } }
public static void init( ClassTexture texture, ClassBitmap bitmap, int pixel_format ) { int[] data = bitmap.property_data; int count = data.Length; int w = bitmap.property_width; int h = bitmap.property_height; int wp2 = 1; while (wp2 < w) wp2 <<= 1; int hp2 = 1; while (hp2 < h) hp2 <<= 1; int dest_skip = wp2 - w; Color[] colors = new Color[wp2*hp2]; int src_pos = -1; int dest_pos = -1; for (int j=h; j>0; --j) { for (int i=w; i>0; --i) { // premultiply color components by alpha component int c = data[++src_pos]; int a = (c >> 24) & 255; int r = (c >> 16) & 255; int g = (c >> 8) & 255; int b = c & 255; colors[++dest_pos] = new Color( (r*a)/255, (g*a)/255, (b*a)/255, a ); } dest_pos += dest_skip; } Texture2D tex = new Texture2D( Plasmacore.device, wp2, hp2, false, SurfaceFormat.Color ); tex.SetData<Color>( colors ); texture.property_native_data = new NativeTextureData(tex); texture.property_image_size.property_x = w; texture.property_image_size.property_y = h; texture.property_texture_size.property_x = wp2; texture.property_texture_size.property_y = hp2; }
public static void init( ClassTexture texture, CompoundVector2 size ) { // TODO: implement for offscreen buffers /* int w = (int) size.property_x; int h = (int) size.property_y; int wp2 = 1; while (wp2 < w) wp2 <<= 1; int hp2 = 1; while (hp2 < h) hp2 <<= 1; Texture2D tex = new Texture2D( Plasmacore.device, wp2, hp2, false, SurfaceFormat.Color ); texture.property_native_data = new NativeTextureData(tex); texture.property_image_size.property_x = w; texture.property_image_size.property_y = h; texture.property_texture_size.property_x = wp2; texture.property_texture_size.property_y = hp2; */ }
public static void draw_tile( ClassTexture texture, CompoundCorners uv, CompoundVector2 pos, CompoundVector2 size, int render_flags) { Bard.log("TODO: NativeTexture::draw_tile()"); }
public static void draw_tile( ClassTexture texture, CompoundCorners uv, CompoundVector2 pos, CompoundVector2 size, CompoundRender render_flags) { draw_tile( texture, uv, pos, size, render_flags.property_flags ); }
public static void draw( ClassTexture texture, CompoundCorners uv, CompoundVector2 size, CompoundColor color, CompoundRender render_flags, CompoundBlend blend_fn, ClassTexture alpha_texture, CompoundCorners alpha_uv) { Bard.log("TODO: NativeTexture::draw()"); }
public static void draw( ClassTexture texture, CompoundCorners uv, CompoundQuad vertices, CompoundColorGradient colors, CompoundRender render_flags, CompoundBlend blend_fn) { DrawBuffer.set_render_flags( render_flags.property_flags, blend_fn.property_src_blend, blend_fn.property_dest_blend ); DrawBuffer.set_textured_triangle_mode( texture, null ); Vector3 pt1 = Plasmacore.v3( vertices.property_top_left ); Vector3 pt2 = Plasmacore.v3( vertices.property_top_right ); Vector3 pt3 = Plasmacore.v3( vertices.property_bottom_right ); Vector3 pt4 = Plasmacore.v3( vertices.property_bottom_left ); NativeTransformManager.update(); pt1 = NativeTransformManager.transform.transform( pt1 ); pt2 = NativeTransformManager.transform.transform( pt2 ); pt3 = NativeTransformManager.transform.transform( pt3 ); pt4 = NativeTransformManager.transform.transform( pt4 ); int argb = colors.property_top_left.property_argb; Color c1 = new Color((argb>>16)&255,(argb>>8)&255,argb&255,(argb>>24)&255); argb = colors.property_top_right.property_argb; Color c2 = new Color((argb>>16)&255,(argb>>8)&255,argb&255,(argb>>24)&255); argb = colors.property_bottom_right.property_argb; Color c3 = new Color((argb>>16)&255,(argb>>8)&255,argb&255,(argb>>24)&255); argb = colors.property_bottom_left.property_argb; Color c4 = new Color((argb>>16)&255,(argb>>8)&255,argb&255,(argb>>24)&255); float uv_a_x = (float) uv.property_top_left.property_x; float uv_a_y = (float) uv.property_top_left.property_y; float uv_b_x = (float) uv.property_bottom_right.property_x; float uv_b_y = (float) uv.property_bottom_right.property_y; VertexPositionColorTexture v1, v2, v3, v4; v1 = new VertexPositionColorTexture( pt1, c1, new Vector2( uv_a_x, uv_a_y ) ); v2 = new VertexPositionColorTexture( pt2, c2, new Vector2( uv_b_x, uv_a_y ) ); v3 = new VertexPositionColorTexture( pt3, c3, new Vector2( uv_b_x, uv_b_y ) ); v4 = new VertexPositionColorTexture( pt4, c4, new Vector2( uv_a_x, uv_b_y ) ); DrawBuffer.add( v1, v2, v4 ); DrawBuffer.add( v4, v2, v3 ); }
public static void draw( ClassTexture texture, CompoundCorners uv, CompoundVector2 size, CompoundColor color, CompoundRender render_flags, CompoundBlend blend_fn) { DrawBuffer.set_render_flags( render_flags.property_flags, blend_fn.property_src_blend, blend_fn.property_dest_blend ); DrawBuffer.set_textured_triangle_mode( texture, null ); Vector3 pt1 = new Vector3( 0, 0, 0 ); Vector3 pt2 = new Vector3( (float) size.property_x, 0, 0 ); Vector3 pt3 = new Vector3( (float) size.property_x, (float) size.property_y, 0 ); Vector3 pt4 = new Vector3( 0, (float) size.property_y, 0 ); NativeTransformManager.update(); pt1 = NativeTransformManager.transform.transform( pt1 ); pt2 = NativeTransformManager.transform.transform( pt2 ); pt3 = NativeTransformManager.transform.transform( pt3 ); pt4 = NativeTransformManager.transform.transform( pt4 ); Color c; //if ((render_flags.property_flags & DrawBuffer.RENDER_FLAG_FIXED_COLOR) != 0) //{ //c = Color.White; //} //else //{ int argb = color.property_argb; c = new Color((argb>>16)&255,(argb>>8)&255,argb&255,(argb>>24)&255); //} float uv_a_x = (float) uv.property_top_left.property_x; float uv_a_y = (float) uv.property_top_left.property_y; float uv_b_x = (float) uv.property_bottom_right.property_x; float uv_b_y = (float) uv.property_bottom_right.property_y; VertexPositionColorTexture v1, v2, v3, v4; v1 = new VertexPositionColorTexture( pt1, c, new Vector2( uv_a_x, uv_a_y ) ); v2 = new VertexPositionColorTexture( pt2, c, new Vector2( uv_b_x, uv_a_y ) ); v3 = new VertexPositionColorTexture( pt3, c, new Vector2( uv_b_x, uv_b_y ) ); v4 = new VertexPositionColorTexture( pt4, c, new Vector2( uv_a_x, uv_b_y ) ); DrawBuffer.add( v1, v2, v4 ); DrawBuffer.add( v4, v2, v3 ); }