-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.添加背景图渲染 2.添加播放次数逻辑
- Loading branch information
zengjiale2
committed
Oct 12, 2022
1 parent
13dbfbd
commit 67f321c
Showing
21 changed files
with
372 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// Created by zengjiale on 2022/10/11. | ||
// | ||
|
||
#include "bgrender.h" | ||
|
||
BgRender::BgRender() { | ||
initRender(); | ||
} | ||
|
||
BgRender::~BgRender() { | ||
vertexArray = nullptr; | ||
rgbaArray = nullptr; | ||
} | ||
|
||
void BgRender::setBgImage(unsigned char *bitmap, AndroidBitmapInfo *bitmapInfo) { | ||
textureId = TextureLoadUtil::loadTexture(bitmap, bitmapInfo); | ||
} | ||
|
||
|
||
void BgRender::initRender() { | ||
char VERTEX_SHADER[] = "attribute vec4 vPosition;\n" | ||
"attribute vec4 vTexCoordinate;\n" | ||
"varying vec2 v_TexCoordinate;\n" | ||
"\n" | ||
"void main() {\n" | ||
" v_TexCoordinate = vec2(vTexCoordinate.x, vTexCoordinate.y);\n" | ||
" gl_Position = vPosition;\n" | ||
"}"; | ||
|
||
char FRAGMENT_SHADER[] = "precision mediump float;\n" | ||
"uniform sampler2D texture;\n" | ||
"varying vec2 v_TexCoordinate;\n" | ||
"\n" | ||
"void main () {\n" | ||
" gl_FragColor = texture2D(texture, v_TexCoordinate);\n" | ||
// " gl_FragColor = vec4(1.0,0.2,0.5,1.0);\n" | ||
"}"; | ||
shaderProgram = ShaderUtil::createProgram(VERTEX_SHADER, FRAGMENT_SHADER); | ||
uTextureLocation = glGetUniformLocation(shaderProgram, "texture"); | ||
positionLocation = glGetAttribLocation(shaderProgram, "vPosition"); | ||
textureLocation = glGetAttribLocation(shaderProgram, "vTexCoordinate"); | ||
} | ||
|
||
void BgRender::renderFrame() { | ||
if (surfaceSizeChanged && surfaceWidth > 0 && surfaceHeight > 0) { | ||
surfaceSizeChanged = false; | ||
glViewport(0, 0, surfaceWidth, surfaceHeight); | ||
} | ||
draw(); | ||
} | ||
|
||
void BgRender::clearFrame() { | ||
glClearColor(0, 0, 0, 0); | ||
|
||
glClear(GL_COLOR_BUFFER_BIT); | ||
// glClearColor(1.0, 0, 0.5, 1.0); | ||
} | ||
|
||
void BgRender::destroyRender() { | ||
releaseTexture(); | ||
} | ||
|
||
void BgRender::setAnimeConfig(EvaAnimeConfig *config) { | ||
vertexArray->setArray(VertexUtil::create(config->width, config->height, new PointRect(0, 0, config->width, config->height), vertexArray->array)); | ||
float* rgba = TexCoordsUtil::create(config->width, config->height, new PointRect(0, 0, config->width, config->height), rgbaArray->array); | ||
rgbaArray->setArray(rgba); | ||
} | ||
|
||
GLuint BgRender::getExternalTexture() { | ||
return textureId; | ||
} | ||
|
||
void BgRender::releaseTexture() { | ||
glDeleteTextures(1, &textureId); | ||
} | ||
|
||
void BgRender::swapBuffers() { | ||
|
||
} | ||
|
||
void BgRender::updateViewPort(int width, int height) { | ||
if (width <= 0 || height <= 0) return; | ||
surfaceSizeChanged = true; | ||
surfaceWidth = width; | ||
surfaceHeight = height; | ||
} | ||
|
||
void BgRender::draw() { | ||
if (textureId != -1) { | ||
glUseProgram(shaderProgram); | ||
vertexArray->setVertexAttribPointer(positionLocation); | ||
glActiveTexture(GL_TEXTURE0); | ||
glBindTexture(GL_TEXTURE_2D, textureId); | ||
//加载纹理 | ||
glUniform1i(uTextureLocation, 0); | ||
rgbaArray->setVertexAttribPointer(textureLocation); | ||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Created by zengjiale on 2022/10/11. | ||
// | ||
|
||
#include <android/log.h> | ||
#include <engine/irender.h> | ||
#include <egl/eglcore.h> | ||
#include <util/shaderutil.h> | ||
#include <util/glfloatarray.h> | ||
#include <GLES2/gl2.h> | ||
#include <GLES2/gl2ext.h> | ||
#include <util/vertexutil.h> | ||
#include <util/texcoordsutil.h> | ||
#include <util/textureloadutil.h> | ||
#include <android/bitmap.h> | ||
|
||
#ifndef YYEVA_BGRENDER_H | ||
#define YYEVA_BGRENDER_H | ||
|
||
#define LOG_TAG "BgRender" | ||
#define ELOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) | ||
#define ELOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) | ||
|
||
|
||
using namespace std; | ||
class BgRender: public IRender { | ||
public: | ||
BgRender(); | ||
~BgRender(); | ||
void initRender(); | ||
void setBgImage(unsigned char *bitmap, AndroidBitmapInfo *bitmapInfo); | ||
void renderFrame(); | ||
void clearFrame(); | ||
void destroyRender(); | ||
void setAnimeConfig(EvaAnimeConfig* config); | ||
GLuint getExternalTexture(); | ||
void releaseTexture(); | ||
void swapBuffers(); | ||
void updateViewPort(int width, int height); | ||
void draw(); | ||
|
||
private: | ||
GlFloatArray *vertexArray = new GlFloatArray(); | ||
GlFloatArray *rgbaArray = new GlFloatArray(); | ||
|
||
GLuint shaderProgram; | ||
//shader | ||
GLuint textureId; | ||
//顶点位置 | ||
GLint uTextureLocation; | ||
//纹理位置 | ||
GLint positionLocation; | ||
//纹理位置 | ||
GLint textureLocation; | ||
|
||
int surfaceWidth = 0; | ||
int surfaceHeight = 0; | ||
bool surfaceSizeChanged = false; | ||
}; | ||
|
||
|
||
#endif //YYEVA_BGRENDER_H |
Oops, something went wrong.