From f6d001803f91fa5571299b1574dfca799f7078ed Mon Sep 17 00:00:00 2001 From: badlogicgames Date: Fri, 17 Dec 2010 15:53:15 +0000 Subject: [PATCH] [added] stubs for gdx2d pixmap backend. let's get rid of all the texture shit so far... --- gdx/jni/gdx2d/Android.mk | 3 +- gdx/jni/gdx2d/Gdx2DPixmap.cpp | 112 +++++++++++++++++ gdx/jni/gdx2d/Gdx2DPixmap.h | 109 +++++++++++++++++ gdx/jni/gdx2d/gdx2d.c | 1 + gdx/jni/gdx2d/gdx2d.h | 79 ++++++++++++ gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java | 136 +++++++++++++++++++++ 6 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 gdx/jni/gdx2d/Gdx2DPixmap.cpp create mode 100644 gdx/jni/gdx2d/Gdx2DPixmap.h create mode 100644 gdx/jni/gdx2d/gdx2d.h create mode 100644 gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java diff --git a/gdx/jni/gdx2d/Android.mk b/gdx/jni/gdx2d/Android.mk index 22c320a70..0f4b1bb67 100644 --- a/gdx/jni/gdx2d/Android.mk +++ b/gdx/jni/gdx2d/Android.mk @@ -1 +1,2 @@ -GDX_SRC_FILES += gdx2d/gdx2d.c \ No newline at end of file +GDX_SRC_FILES += gdx2d/gdx2d.c \ + gdx2d/Gdx2DPixmap.cpp \ No newline at end of file diff --git a/gdx/jni/gdx2d/Gdx2DPixmap.cpp b/gdx/jni/gdx2d/Gdx2DPixmap.cpp new file mode 100644 index 000000000..14b32d1b4 --- /dev/null +++ b/gdx/jni/gdx2d/Gdx2DPixmap.cpp @@ -0,0 +1,112 @@ +#include "Gdx2DPixmap.h" +#include "gdx2d.h" + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: load + * Signature: ([J[BII)Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_load + (JNIEnv *, jclass, jlongArray, jbyteArray, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: newPixmap + * Signature: ([JIII)Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_newPixmap + (JNIEnv *, jclass, jlongArray, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_free + (JNIEnv *, jclass, jlong) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: clear + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_clear + (JNIEnv *, jclass, jlong, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: setPixel + * Signature: (JIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setPixel + (JNIEnv *, jclass, jlong, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawLine + * Signature: (JIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawLine + (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawRect + * Signature: (JIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawRect + (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawCircle + * Signature: (JIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawCircle + (JNIEnv *, jclass, jlong, jint, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: fillRect + * Signature: (JIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillRect + (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: fillCircle + * Signature: (JIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillCircle + (JNIEnv *, jclass, jlong, jint, jint, jint, jint) { + +} + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawPixmap + * Signature: (JJIIIIIIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawPixmap + (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint) { + +} diff --git a/gdx/jni/gdx2d/Gdx2DPixmap.h b/gdx/jni/gdx2d/Gdx2DPixmap.h new file mode 100644 index 000000000..760f9c49f --- /dev/null +++ b/gdx/jni/gdx2d/Gdx2DPixmap.h @@ -0,0 +1,109 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_badlogic_gdx_graphics_Gdx2DPixmap */ + +#ifndef _Included_com_badlogic_gdx_graphics_Gdx2DPixmap +#define _Included_com_badlogic_gdx_graphics_Gdx2DPixmap +#ifdef __cplusplus +extern "C" { +#endif +#undef com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_ALPHA +#define com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_ALPHA 1L +#undef com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_ALPHA_LUMINANCE +#define com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_ALPHA_LUMINANCE 2L +#undef com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_RGB +#define com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_RGB 3L +#undef com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_RGBA +#define com_badlogic_gdx_graphics_Gdx2DPixmap_GDX2D_FORMAT_RGBA 4L +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: load + * Signature: ([J[BII)Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_load + (JNIEnv *, jclass, jlongArray, jbyteArray, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: newPixmap + * Signature: ([JIII)Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_newPixmap + (JNIEnv *, jclass, jlongArray, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_free + (JNIEnv *, jclass, jlong); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: clear + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_clear + (JNIEnv *, jclass, jlong, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: setPixel + * Signature: (JIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setPixel + (JNIEnv *, jclass, jlong, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawLine + * Signature: (JIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawLine + (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawRect + * Signature: (JIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawRect + (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawCircle + * Signature: (JIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawCircle + (JNIEnv *, jclass, jlong, jint, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: fillRect + * Signature: (JIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillRect + (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: fillCircle + * Signature: (JIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillCircle + (JNIEnv *, jclass, jlong, jint, jint, jint, jint); + +/* + * Class: com_badlogic_gdx_graphics_Gdx2DPixmap + * Method: drawPixmap + * Signature: (JJIIIIIIIIII)V + */ +JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawPixmap + (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/gdx/jni/gdx2d/gdx2d.c b/gdx/jni/gdx2d/gdx2d.c index 175518e71..d844f8026 100644 --- a/gdx/jni/gdx2d/gdx2d.c +++ b/gdx/jni/gdx2d/gdx2d.c @@ -10,6 +10,7 @@ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ +#include "gdx2d.h" #define STB_TRUETYPE_IMPLEMENTATION #define STBI_HEADER_FILE_ONLY #include "stb_image.c" diff --git a/gdx/jni/gdx2d/gdx2d.h b/gdx/jni/gdx2d/gdx2d.h new file mode 100644 index 000000000..93c2401d7 --- /dev/null +++ b/gdx/jni/gdx2d/gdx2d.h @@ -0,0 +1,79 @@ +/* + * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +#ifndef __GDX2D__ +#define __GDX2D__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * pixmap formats, components are laid out in memory + * in the order they appear in the constant name. E.g. + * GDX_FORMAT_RGB => pixmap[0] = r, pixmap[1] = g, pixmap[2] = b. + * Components are 8-bit each. + */ +#define GDX2D_FORMAT_ALPHA 1 +#define GDX2D_FORMAT_ALPHA_LUMINANCE 2 +#define GDX2D_FORMAT_RGB 3 +#define GDX2D_FORMAT_RGBA 4 + +/** + * blending modes, to be extended + */ +#define GDX2D_BLEND_NONE 0 +#define GDX2D_BLEND_SRC_OVER 1 + +/** + * scaling modes, to be extended + */ +#define GDX2D_SCALE_NEAREST 0 +#define GDX2D_SCALE_BILINEAR 1 + +/** + * simple pixmap struct holding the pixel data, + * the dimensions and the format of the pixmap. + * the format is one of the GDX2D_FORMAT_XXX constants. + */ +struct { + int width; + int height; + int format; + const char* pixels; +} gdx2d_pixmap_struct; +typedef struct gdx2d_pixmap_struct gdx2d_pixmap; + + +gdx2d_pixmap* gdx2d_load_buffer (const char *buffer, int len, int req_format); +gdx2d_pixmap* gdx2d_load_file (const char *filename, int req_format); +gdx2d_pixmap* gdx2d_new (int width, int height, int format); +void gdx2d_free (const gdx2d_pixmap* pixmap); + +void gdx2d_clear (const gdx2d_pixmap* pixmap, int col); +void gdx2d_set_pixel (const gdx2d_pixmap* pixmap, int x, int y, int col); +void gdx2d_draw_line (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col); +void gdx2d_draw_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col); +void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col); +void gdx2d_fill_rect (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col); +void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col); +void gdx2d_draw_pixmap (const gdx2d_pixmap* src_pixmap, + const gdx2d_pixmap* dst_pixmap, + int src_x, int src_y, int src_width, int src_height, + int dst_x, int dst_y, int dst_width, int dst_height, + int blend, int scale); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java b/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java new file mode 100644 index 000000000..0afad1717 --- /dev/null +++ b/gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java @@ -0,0 +1,136 @@ +/* + * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package com.badlogic.gdx.graphics; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; + +/** + * Experimental. Do not use! + * @author mzechner + * + */ +public class Gdx2DPixmap { + static final int GDX2D_FORMAT_ALPHA = 1; + static final int GDX2D_FORMAT_ALPHA_LUMINANCE = 2; + static final int GDX2D_FORMAT_RGB = 3; + static final int GDX2D_FORMAT_RGBA = 4; + + final long basePtr; + final int width; + final int height; + final int format; + final ByteBuffer pixelPtr; + static final long[] nativeData = new long[4]; + + private Gdx2DPixmap(InputStream in, int requestedFormat) throws IOException { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int readBytes = 0; + + while((readBytes = in.read(buffer)) != -1) { + bytes.write(buffer); + } + + buffer = bytes.toByteArray(); + pixelPtr = load(nativeData, buffer, buffer.length, requestedFormat); + if(pixelPtr == null) + throw new IOException("couldn't load pixmap"); + + basePtr = nativeData[0]; + width = (int)nativeData[1]; + height = (int)nativeData[2]; + format = (int)nativeData[3]; + } + + private Gdx2DPixmap(int width, int height, int format) throws IllegalArgumentException { + pixelPtr = newPixmap(nativeData, width, height, format); + if(pixelPtr == null) + throw new IllegalArgumentException("couldn't load pixmap"); + + this.basePtr = nativeData[0]; + this.width = (int)nativeData[1]; + this.height = (int)nativeData[2]; + this.format = (int)nativeData[3]; + } + + public void dispose() { + free(basePtr); + } + + public void clear(int color) { + clear(basePtr, color); + } + + public void setPixel(int x, int y, int color) { + setPixel(basePtr, x, y, color); + } + + public void drawLine(int x, int y, int x2, int y2, int color) { + drawLine(basePtr, x, y, x2, y2, color); + } + + public void drawRect(int x, int y, int width, int height, int color) { + drawRect(basePtr, x, y, width, height, color); + } + + public void drawCircle(int x, int y, int radius, int color) { + drawCircle(basePtr, x, y, radius, color); + } + + public void fillRect(int x, int y, int width, int height, int color) { + drawRect(basePtr, x, y, width, height, color); + } + + public void fillCircle(int x, int y, int radius, int color) { + drawCircle(basePtr, x, y, radius, color); + } + + private void drawPixmap(Gdx2DPixmap src, + int srcX, int srcY, int srcWidth, int srcHeight, + int dstX, int dstY, int dstWidth, int dstHeight, + int blend, int scale) { + drawPixmap(src.basePtr, basePtr, srcX, srcY, srcWidth, srcHeight, dstX, dstY, dstWidth, dstHeight, blend, scale); + } + + + public static Gdx2DPixmap newPixmap(InputStream in, int requestedFormat) { + try { + return new Gdx2DPixmap(in, requestedFormat); + } catch(IOException e) { + return null; + } + } + + public static Gdx2DPixmap newPixmap(int width, int height, int format) { + try { + return new Gdx2DPixmap(width, height, format); + } catch(IllegalArgumentException e) { + return null; + } + } + + private static native ByteBuffer load(long[] nativeData, byte[] buffer, int len, int requestedFormat); + private static native ByteBuffer newPixmap(long[] nativeData, int width, int height, int format); + private static native void free(long basePtr); + private static native void clear(long pixmap, int color); + private static native void setPixel(long pixmap, int x, int y, int color); + private static native void drawLine(long pixmap, int x, int y, int x2, int y2, int color); + private static native void drawRect(long pixmap, int x, int y, int width, int height, int color); + private static native void drawCircle(long pixmap, int x, int y, int radius, int color); + private static native void fillRect(long pixmap, int x, int y, int width, int height, int color); + private static native void fillCircle(long pixmap, int x, int y, int radius, int color); + private static native void drawPixmap(long src, long dst, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int blend, int scale); +} -- 2.11.0