Skip to content

Commit f6c0709

Browse files
committed
Merge branch 'master' of https://github.com/raysan5/raylib
2 parents 2724f07 + fe8c83b commit f6c0709

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

examples/shaders/resources/shaders/glsl330/palette_switch.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ out vec4 finalColor;
1717
void main()
1818
{
1919
// Texel color fetching from texture sampler
20-
// NOTE: The texel is actually the a GRAYSCALE index color
20+
// NOTE: The texel is actually the GRAYSCALE index color
2121
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
2222

2323
// Convert the (normalized) texel color RED component (GB would work, too)

examples/textures/textures_polygon_drawing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ int main(void)
115115
// without crossing perimeter, points must be in anticlockwise order
116116
void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint)
117117
{
118+
rlSetTexture(texture.id);
118119
rlBegin(RL_TRIANGLES);
119120

120-
rlSetTexture(texture.id);
121121

122122
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
123123

src/platforms/rcore_android.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include <android_native_app_glue.h> // Required for: android_app struct and activity management
5050
#include <android/window.h> // Required for: AWINDOW_FLAG_FULLSCREEN definition and others
5151
//#include <android/sensor.h> // Required for: Android sensors functions (accelerometer, gyroscope, light...)
52-
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL()]
52+
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL() and GetCurrentMonitor()]
5353

5454
#include <EGL/egl.h> // Native platform windowing system interface
5555

@@ -446,8 +446,32 @@ int GetMonitorCount(void)
446446
// Get current monitor where window is placed
447447
int GetCurrentMonitor(void)
448448
{
449-
TRACELOG(LOG_WARNING, "GetCurrentMonitor() not implemented on target platform");
450-
return 0;
449+
int displayId = -1;
450+
JNIEnv* env = NULL;
451+
JavaVM* vm = platform.app->activity->vm;
452+
(*vm)->AttachCurrentThread(vm, &env, NULL);
453+
454+
jobject activity = platform.app->activity->clazz;
455+
jclass activityClass = (*env)->GetObjectClass(env, activity);
456+
457+
jmethodID getDisplayMethod = (*env)->GetMethodID(env, activityClass, "getDisplay", "()Landroid/view/Display;");
458+
459+
jobject display = (*env)->CallObjectMethod(env, activity, getDisplayMethod);
460+
461+
if (display == NULL) {
462+
TRACELOG(LOG_ERROR, "GetCurrentMonitor() couldn't get the display object");
463+
} else {
464+
jclass displayClass = (*env)->FindClass(env, "android/view/Display");
465+
jmethodID getDisplayIdMethod = (*env)->GetMethodID(env, displayClass, "getDisplayId", "()I");
466+
displayId = (int) (*env)->CallIntMethod(env, display, getDisplayIdMethod);
467+
(*env)->DeleteLocalRef(env, displayClass);
468+
}
469+
470+
(*env)->DeleteLocalRef(env, activityClass);
471+
(*env)->DeleteLocalRef(env, display);
472+
473+
(*vm)->DetachCurrentThread(vm);
474+
return displayId;
451475
}
452476

453477
// Get selected monitor position

src/rlgl.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ typedef struct rlglData {
10671067
Matrix stack[RL_MAX_MATRIX_STACK_SIZE];// Matrix stack for push/pop
10681068
int stackCounter; // Matrix stack counter
10691069

1070+
unsigned int currentTextureId; // Current texture id to be used on glBegin
10701071
unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader)
10711072
unsigned int activeTextureId[RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS]; // Active texture ids to be enabled on batch drawing (0 active by default)
10721073
unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program)
@@ -1485,8 +1486,8 @@ void rlBegin(int mode)
14851486
if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch);
14861487

14871488
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode;
1488-
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0;
1489-
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId;
1489+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.currentTextureId;
1490+
RLGL.State.currentTextureId = RLGL.State.defaultTextureId;
14901491
}
14911492
}
14921493

@@ -1651,13 +1652,15 @@ void rlSetTexture(unsigned int id)
16511652
{
16521653
rlDrawRenderBatch(RLGL.currentBatch);
16531654
}
1655+
RLGL.State.currentTextureId = RLGL.State.defaultTextureId;
16541656
#endif
16551657
}
16561658
else
16571659
{
16581660
#if defined(GRAPHICS_API_OPENGL_11)
16591661
rlEnableTexture(id);
16601662
#else
1663+
RLGL.State.currentTextureId = id;
16611664
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId != id)
16621665
{
16631666
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
@@ -1676,6 +1679,9 @@ void rlSetTexture(unsigned int id)
16761679
RLGL.State.vertexCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment;
16771680

16781681
RLGL.currentBatch->drawCounter++;
1682+
1683+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 2].mode;
1684+
16791685
}
16801686
}
16811687

@@ -2257,6 +2263,7 @@ void rlglInit(int width, int height)
22572263
// Init default white texture
22582264
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
22592265
RLGL.State.defaultTextureId = rlLoadTexture(pixels, 1, 1, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
2266+
RLGL.State.currentTextureId = RLGL.State.defaultTextureId;
22602267

22612268
if (RLGL.State.defaultTextureId != 0) TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture loaded successfully", RLGL.State.defaultTextureId);
22622269
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to load default texture");

src/rmodels.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4261,9 +4261,10 @@ static void BuildPoseFromParentJoints(BoneInfo *bones, int boneCount, Transform
42614261
continue;
42624262
}
42634263
transforms[i].rotation = QuaternionMultiply(transforms[bones[i].parent].rotation, transforms[i].rotation);
4264+
transforms[i].scale = Vector3Multiply(transforms[i].scale, transforms[bones[i].parent].scale);
4265+
transforms[i].translation = Vector3Multiply(transforms[i].translation, transforms[bones[i].parent].scale);
42644266
transforms[i].translation = Vector3RotateByQuaternion(transforms[i].translation, transforms[bones[i].parent].rotation);
42654267
transforms[i].translation = Vector3Add(transforms[i].translation, transforms[bones[i].parent].translation);
4266-
transforms[i].scale = Vector3Multiply(transforms[i].scale, transforms[bones[i].parent].scale);
42674268
}
42684269
}
42694270
}
@@ -6238,6 +6239,20 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
62386239
*animCount = (int)data->animations_count;
62396240
animations = (ModelAnimation *)RL_CALLOC(data->animations_count, sizeof(ModelAnimation));
62406241

6242+
Transform worldTransform;
6243+
{
6244+
cgltf_float cgltf_worldTransform[16];
6245+
cgltf_node* node = skin.joints[0];
6246+
cgltf_node_transform_world(node->parent, cgltf_worldTransform);
6247+
Matrix worldMatrix = {
6248+
cgltf_worldTransform[0], cgltf_worldTransform[4], cgltf_worldTransform[8], cgltf_worldTransform[12],
6249+
cgltf_worldTransform[1], cgltf_worldTransform[5], cgltf_worldTransform[9], cgltf_worldTransform[13],
6250+
cgltf_worldTransform[2], cgltf_worldTransform[6], cgltf_worldTransform[10], cgltf_worldTransform[14],
6251+
cgltf_worldTransform[3], cgltf_worldTransform[7], cgltf_worldTransform[11], cgltf_worldTransform[15]
6252+
};
6253+
MatrixDecompose(worldMatrix, &(worldTransform.translation), &(worldTransform.rotation), &(worldTransform.scale));
6254+
}
6255+
62416256
for (unsigned int i = 0; i < data->animations_count; i++)
62426257
{
62436258
animations[i].bones = LoadBoneInfoGLTF(skin, &animations[i].boneCount);
@@ -6356,6 +6371,13 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
63566371
};
63576372
}
63586373

6374+
Transform* root = &animations[i].framePoses[j][0];
6375+
root->rotation = QuaternionMultiply(worldTransform.rotation, root->rotation);
6376+
root->scale = Vector3Multiply(root->scale, worldTransform.scale);
6377+
root->translation = Vector3Multiply(root->translation, worldTransform.scale);
6378+
root->translation = Vector3RotateByQuaternion(root->translation, worldTransform.rotation);
6379+
root->translation = Vector3Add(root->translation, worldTransform.translation);
6380+
63596381
BuildPoseFromParentJoints(animations[i].bones, animations[i].boneCount, animations[i].framePoses[j]);
63606382
}
63616383

0 commit comments

Comments
 (0)