Wire up window position in the playground.
This commit is contained in:
@@ -82,8 +82,8 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
|
||||
|
||||
static constexpr auto kSampledImage{{camel_case(sampled_image.name)}} = SampledImageSlot { // {{sampled_image.name}}
|
||||
"{{sampled_image.name}}", // name
|
||||
{{sampled_image.msl_res_0}}u, // auto primary
|
||||
{{sampled_image.msl_res_1}}u, // auto secondary
|
||||
{{sampled_image.msl_res_0}}u, // texture
|
||||
{{sampled_image.msl_res_1}}u, // sampler
|
||||
};
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "impeller/geometry/scalar.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -627,6 +629,15 @@ struct Color {
|
||||
static constexpr Color YellowGreen() {
|
||||
return {154.0 / 255.0, 205.0 / 255.0, 50.0 / 255.0, 1.0};
|
||||
}
|
||||
|
||||
static Color Random() {
|
||||
return {
|
||||
static_cast<Scalar>((std::rand() % 255) / 255.0), //
|
||||
static_cast<Scalar>((std::rand() % 255) / 255.0), //
|
||||
static_cast<Scalar>((std::rand() % 255) / 255.0), //
|
||||
1.0 //
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,10 @@ class Playground : public ::testing::Test {
|
||||
|
||||
~Playground();
|
||||
|
||||
Point GetCursorPosition() const;
|
||||
|
||||
ISize GetWindowSize() const;
|
||||
|
||||
std::shared_ptr<Context> GetContext() const;
|
||||
|
||||
bool OpenPlaygroundHere(Renderer::RenderCallback render_callback);
|
||||
@@ -25,6 +29,9 @@ class Playground : public ::testing::Test {
|
||||
|
||||
private:
|
||||
Renderer renderer_;
|
||||
Point cursor_position_;
|
||||
|
||||
void SetCursorPosition(Point pos);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Playground);
|
||||
};
|
||||
|
||||
@@ -58,6 +58,18 @@ static std::string GetWindowTitle(const std::string& test_name) {
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
Point Playground::GetCursorPosition() const {
|
||||
return cursor_position_;
|
||||
}
|
||||
|
||||
ISize Playground::GetWindowSize() const {
|
||||
return {1024, 768};
|
||||
}
|
||||
|
||||
void Playground::SetCursorPosition(Point pos) {
|
||||
cursor_position_ = pos;
|
||||
}
|
||||
|
||||
bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
if (!render_callback) {
|
||||
return true;
|
||||
@@ -79,13 +91,20 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
::glfwWindowHint(GLFW_RESIZABLE, false);
|
||||
|
||||
auto window_title = GetWindowTitle(flutter::testing::GetCurrentTestName());
|
||||
auto window = ::glfwCreateWindow(1024, 768, window_title.c_str(), NULL, NULL);
|
||||
auto window =
|
||||
::glfwCreateWindow(GetWindowSize().width, GetWindowSize().height,
|
||||
window_title.c_str(), NULL, NULL);
|
||||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
::glfwSetWindowUserPointer(window, this);
|
||||
::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
|
||||
::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x,
|
||||
double y) {
|
||||
reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window))
|
||||
->SetCursorPosition({static_cast<Scalar>(x), static_cast<Scalar>(y)});
|
||||
});
|
||||
|
||||
fml::ScopedCleanupClosure close_window(
|
||||
[window]() { ::glfwDestroyWindow(window); });
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
uniform FrameInfo {
|
||||
float current_time;
|
||||
vec2 cursor_position;
|
||||
vec2 window_size;
|
||||
} frame;
|
||||
|
||||
in vec4 color;
|
||||
@@ -18,5 +19,5 @@ uniform sampler2D contents2_texture;
|
||||
void main() {
|
||||
vec4 tex1 = texture(contents1_texture, interporlated_texture_coordinates);
|
||||
vec4 tex2 = texture(contents2_texture, interporlated_texture_coordinates);
|
||||
frag_color = mix(tex1, tex2, frame.cursor_position.x);
|
||||
frag_color = mix(tex1, tex2, clamp(frame.cursor_position.x / frame.window_size.x, 0.0, 1.0));
|
||||
}
|
||||
|
||||
@@ -69,6 +69,10 @@ TEST_F(PrimitivesTest, CanCreateBoxPrimitive) {
|
||||
|
||||
BoxFragmentShader::FrameInfo frame_info;
|
||||
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
|
||||
frame_info.cursor_position = GetCursorPosition();
|
||||
frame_info.window_size.x = GetWindowSize().width;
|
||||
frame_info.window_size.y = GetWindowSize().height;
|
||||
|
||||
cmd.fragment_bindings
|
||||
.buffers[BoxFragmentShader::kUniformFrameInfo.binding] =
|
||||
pass.GetTransientsBuffer().EmplaceUniform(frame_info);
|
||||
|
||||
Reference in New Issue
Block a user