diff --git a/include/JSFML/JNI/org_jsfml_graphics_Shader.h b/include/JSFML/JNI/org_jsfml_graphics_Shader.h index fdce3ae..cdb7071 100644 --- a/include/JSFML/JNI/org_jsfml_graphics_Shader.h +++ b/include/JSFML/JNI/org_jsfml_graphics_Shader.h @@ -42,10 +42,10 @@ JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeDelete /* * Class: org_jsfml_graphics_Shader * Method: nativeLoadFromSource1 - * Signature: (Ljava/lang/String;Lorg/jsfml/graphics/Shader/Type;)Z + * Signature: (Ljava/lang/String;I)Z */ JNIEXPORT jboolean JNICALL Java_org_jsfml_graphics_Shader_nativeLoadFromSource1 - (JNIEnv *, jobject, jstring, jobject); + (JNIEnv *, jobject, jstring, jint); /* * Class: org_jsfml_graphics_Shader @@ -57,50 +57,50 @@ JNIEXPORT jboolean JNICALL Java_org_jsfml_graphics_Shader_nativeLoadFromSource2 /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterFloat * Signature: (Ljava/lang/String;F)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2F +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterFloat (JNIEnv *, jobject, jstring, jfloat); /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterVec2 * Signature: (Ljava/lang/String;FF)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2FF +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterVec2 (JNIEnv *, jobject, jstring, jfloat, jfloat); /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterVec3 * Signature: (Ljava/lang/String;FFF)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2FFF +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterVec3 (JNIEnv *, jobject, jstring, jfloat, jfloat, jfloat); /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterVec4 * Signature: (Ljava/lang/String;FFFF)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2FFFF +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterVec4 (JNIEnv *, jobject, jstring, jfloat, jfloat, jfloat, jfloat); /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter - * Signature: (Ljava/lang/String;Lorg/jsfml/graphics/Transform;)V + * Method: nativeSetParameterMat4 + * Signature: (Ljava/lang/String;Ljava/nio/Buffer;)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2Lorg_jsfml_graphics_Transform_2 +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterMat4 (JNIEnv *, jobject, jstring, jobject); /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterSampler2d * Signature: (Ljava/lang/String;Lorg/jsfml/graphics/Texture;)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2Lorg_jsfml_graphics_Texture_2 +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterSampler2d (JNIEnv *, jobject, jstring, jobject); /* diff --git a/src/cpp/JNI/org_jsfml_graphics_Shader.cpp b/src/cpp/JNI/org_jsfml_graphics_Shader.cpp index 1c0b6b1..5d14806 100644 --- a/src/cpp/JNI/org_jsfml_graphics_Shader.cpp +++ b/src/cpp/JNI/org_jsfml_graphics_Shader.cpp @@ -1,8 +1,7 @@ #include -#include +#include #include -#include #include @@ -45,16 +44,16 @@ JNIEXPORT jlong JNICALL Java_org_jsfml_graphics_Shader_nativeCreate (JNIEnv *env /* * Class: org_jsfml_graphics_Shader * Method: nativeLoadFromSource1 - * Signature: (Ljava/lang/String;Lorg/jsfml/graphics/Shader/Type;)Z + * Signature: (Ljava/lang/String;I)Z */ JNIEXPORT jboolean JNICALL Java_org_jsfml_graphics_Shader_nativeLoadFromSource1 - (JNIEnv *env, jobject obj, jstring source, jobject type) { + (JNIEnv *env, jobject obj, jstring source, jint type) { const char *utf8 = env->GetStringUTFChars(source, NULL); jboolean result = THIS(sf::Shader)->loadFromMemory( std::string(utf8), - (sf::Shader::Type)JavaEnum::ordinal(env, type)); + (sf::Shader::Type)type); env->ReleaseStringUTFChars(source, utf8); return result; @@ -82,10 +81,10 @@ JNIEXPORT jboolean JNICALL Java_org_jsfml_graphics_Shader_nativeLoadFromSource2 /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterFloat * Signature: (Ljava/lang/String;F)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2F +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterFloat (JNIEnv *env, jobject obj, jstring name, jfloat x) { const char *utf8 = env->GetStringUTFChars(name, NULL); @@ -95,10 +94,10 @@ JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_ /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterVec2 * Signature: (Ljava/lang/String;FF)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2FF +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterVec2 (JNIEnv *env, jobject obj, jstring name, jfloat x, jfloat y) { const char *utf8 = env->GetStringUTFChars(name, NULL); @@ -108,10 +107,10 @@ JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_ /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterVec3 * Signature: (Ljava/lang/String;FFF)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2FFF +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterVec3 (JNIEnv *env, jobject obj, jstring name, jfloat x, jfloat y, jfloat z) { const char *utf8 = env->GetStringUTFChars(name, NULL); @@ -121,10 +120,10 @@ JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_ /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterVec4 * Signature: (Ljava/lang/String;FFFF)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2FFFF +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterVec4 (JNIEnv *env, jobject obj, jstring name, jfloat x, jfloat y, jfloat z, jfloat w) { const char *utf8 = env->GetStringUTFChars(name, NULL); @@ -134,26 +133,26 @@ JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_ /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter - * Signature: (Ljava/lang/String;Lorg/jsfml/graphics/Transform;)V + * Method: nativeSetParameterMat4 + * Signature: (Ljava/lang/String;Ljava/nio/Buffer;)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2Lorg_jsfml_graphics_Transform_2 +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterMat4 (JNIEnv *env, jobject obj, jstring name, jobject xform) { const char *utf8 = env->GetStringUTFChars(name, NULL); THIS(sf::Shader)->setParameter( std::string(utf8), - JSFML::Transform::ToSFML(env, xform)); + JSFML::Intercom::decodeTransform(env, xform)); env->ReleaseStringUTFChars(name, utf8); } /* * Class: org_jsfml_graphics_Shader - * Method: nativeSetParameter + * Method: nativeSetParameterSampler2d * Signature: (Ljava/lang/String;Lorg/jsfml/graphics/Texture;)V */ -JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameter__Ljava_lang_String_2Lorg_jsfml_graphics_Texture_2 +JNIEXPORT void JNICALL Java_org_jsfml_graphics_Shader_nativeSetParameterSampler2d (JNIEnv *env, jobject obj, jstring name, jobject texture) { const char *utf8 = env->GetStringUTFChars(name, NULL); diff --git a/src/java/org/jsfml/graphics/Shader.java b/src/java/org/jsfml/graphics/Shader.java index 65d703a..4323e9d 100644 --- a/src/java/org/jsfml/graphics/Shader.java +++ b/src/java/org/jsfml/graphics/Shader.java @@ -1,14 +1,12 @@ package org.jsfml.graphics; -import org.jsfml.internal.SFMLErrorCapture; -import org.jsfml.internal.SFMLNative; -import org.jsfml.internal.SFMLNativeObject; -import org.jsfml.internal.StreamUtil; +import org.jsfml.internal.*; import org.jsfml.system.Vector2f; import org.jsfml.system.Vector3f; import java.io.IOException; import java.io.InputStream; +import java.nio.Buffer; import java.nio.file.Path; import java.util.Objects; @@ -45,7 +43,8 @@ private CurrentTextureType() { *

* This is required only if you wish to use JSFML shaders in custom OpenGL code. * - * @param shader the shader to activate. + * @param shader the shader to activate, or {@code null} to indicate that no shader + * is to be used. */ public static native void bind(ConstShader shader); @@ -94,7 +93,7 @@ protected void nativeSetExPtr() { @SuppressWarnings("deprecation") protected native void nativeDelete(); - private native boolean nativeLoadFromSource1(String source, Type shaderType); + private native boolean nativeLoadFromSource1(String source, int shaderType); private native boolean nativeLoadFromSource2(String vertSource, String fragSource); @@ -119,8 +118,7 @@ public void loadFromSource(String source, Type shaderType) SFMLErrorCapture.start(); final boolean result = nativeLoadFromSource1( - Objects.requireNonNull(source), - Objects.requireNonNull(shaderType)); + Objects.requireNonNull(source), shaderType.ordinal()); final String msg = SFMLErrorCapture.finish(); @@ -214,7 +212,7 @@ public void loadFromFile(Path vertexShaderFile, Path fragmentShaderFile) new String(StreamUtil.readFile(fragmentShaderFile))); } - private native void nativeSetParameter(String name, float x); + private native void nativeSetParameterFloat(String name, float x); /** * Sets a float parameter ({@code float}) value in the shader. @@ -223,10 +221,10 @@ public void loadFromFile(Path vertexShaderFile, Path fragmentShaderFile) * @param value the parameter's value. */ public void setParameter(String name, float value) { - nativeSetParameter(Objects.requireNonNull(name), value); + nativeSetParameterFloat(Objects.requireNonNull(name), value); } - private native void nativeSetParameter(String name, float x, float y); + private native void nativeSetParameterVec2(String name, float x, float y); /** * Sets a 2-component-float ({@code vec2}) parameter value in the shader. @@ -236,7 +234,7 @@ public void setParameter(String name, float value) { * @param y the parameter's value. */ public void setParameter(String name, float x, float y) { - nativeSetParameter(Objects.requireNonNull(name), x, y); + nativeSetParameterVec2(Objects.requireNonNull(name), x, y); } /** @@ -249,7 +247,7 @@ public void setParameter(String name, Vector2f v) { setParameter(name, v.x, v.y); } - private native void nativeSetParameter(String name, float x, float y, float z); + private native void nativeSetParameterVec3(String name, float x, float y, float z); /** * Sets a 3-component-float ({@code vec3}) parameter value in the shader. @@ -260,7 +258,7 @@ public void setParameter(String name, Vector2f v) { * @param z the parameter's value. */ public void setParameter(String name, float x, float y, float z) { - nativeSetParameter(Objects.requireNonNull(name), x, y, z); + nativeSetParameterVec3(Objects.requireNonNull(name), x, y, z); } /** @@ -273,7 +271,7 @@ public void setParameter(String name, Vector3f v) { setParameter(name, v.x, v.y, v.z); } - private native void nativeSetParameter(String name, float x, float y, float z, float w); + private native void nativeSetParameterVec4(String name, float x, float y, float z, float w); /** * Sets a 4-component-float ({@code vec4}) parameter value in the shader. @@ -285,7 +283,7 @@ public void setParameter(String name, Vector3f v) { * @param w the parameter's value. */ public void setParameter(String name, float x, float y, float z, float w) { - nativeSetParameter(Objects.requireNonNull(name), x, y, z, w); + nativeSetParameterVec4(Objects.requireNonNull(name), x, y, z, w); } /** @@ -302,7 +300,7 @@ public void setParameter(String name, Color color) { (float) color.a / 255.0f); } - private native void nativeSetParameter(String name, Transform xform); + private native void nativeSetParameterMat4(String name, Buffer xform); /** * Sets a matrix (mat4) parameter value in the shader. @@ -311,10 +309,12 @@ public void setParameter(String name, Color color) { * @param xform the parameter's value. */ public void setParameter(String name, Transform xform) { - nativeSetParameter(Objects.requireNonNull(name), Objects.requireNonNull(xform)); + nativeSetParameterMat4( + Objects.requireNonNull(name), + IntercomHelper.encodeTransform(xform)); } - private native void nativeSetParameter(String name, Texture texture); + private native void nativeSetParameterSampler2d(String name, Texture texture); /** * Sets a texture (sampler2D) parameter value in the shader. @@ -323,7 +323,7 @@ public void setParameter(String name, Transform xform) { * @param texture the parameter's value. */ public void setParameter(String name, ConstTexture texture) { - nativeSetParameter(Objects.requireNonNull(name), (Texture) Objects.requireNonNull(texture)); + nativeSetParameterSampler2d(Objects.requireNonNull(name), (Texture) Objects.requireNonNull(texture)); } private native void nativeSetParameterCurrentTexture(String name);