68 lines
1.6 KiB
C
68 lines
1.6 KiB
C
|
|
// GLESRenderer.h
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <GLES3/gl3.h>
|
||
|
|
#include <SDL2/SDL.h>
|
||
|
|
#include <vector>
|
||
|
|
#include <map>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
class GLESRenderer
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
GLESRenderer(SDL_Window *window);
|
||
|
|
~GLESRenderer();
|
||
|
|
|
||
|
|
bool Initialize();
|
||
|
|
void Clear();
|
||
|
|
void Present();
|
||
|
|
|
||
|
|
// 模拟 SDL_RenderCopy 功能
|
||
|
|
void RenderCopy(GLuint texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect);
|
||
|
|
void RenderCopyEx(GLuint texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect,
|
||
|
|
double angle, const SDL_Point *center, SDL_RendererFlip flip);
|
||
|
|
|
||
|
|
// // 纹理管理
|
||
|
|
// GLuint CreateTexture(const std::string &path);
|
||
|
|
// GLuint CreateTextureFromSurface(SDL_Surface *surface);
|
||
|
|
// void DestroyTexture(GLuint texture);
|
||
|
|
|
||
|
|
// // 设置渲染状态
|
||
|
|
// void SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||
|
|
|
||
|
|
private:
|
||
|
|
SDL_Window *m_window;
|
||
|
|
SDL_GLContext m_glContext;
|
||
|
|
|
||
|
|
// 着色器程序
|
||
|
|
GLuint m_shaderProgram;
|
||
|
|
GLuint m_vertexShader;
|
||
|
|
GLuint m_fragmentShader;
|
||
|
|
|
||
|
|
// 顶点缓冲区对象
|
||
|
|
GLuint m_vbo;
|
||
|
|
GLuint m_vao;
|
||
|
|
|
||
|
|
// 批处理系统
|
||
|
|
struct RenderCommand
|
||
|
|
{
|
||
|
|
GLuint texture;
|
||
|
|
SDL_Rect dstrect;
|
||
|
|
double angle;
|
||
|
|
SDL_Point center;
|
||
|
|
SDL_RendererFlip flip;
|
||
|
|
int z_order;
|
||
|
|
};
|
||
|
|
|
||
|
|
std::vector<RenderCommand> m_renderBatch;
|
||
|
|
|
||
|
|
// 编译着色器
|
||
|
|
bool CompileShader(const char *source, GLenum type, GLuint &shader);
|
||
|
|
bool LinkProgram(GLuint program);
|
||
|
|
|
||
|
|
// 创建着色器程序
|
||
|
|
bool CreateShaderProgram();
|
||
|
|
|
||
|
|
// 设置正交投影矩阵
|
||
|
|
void SetOrthographicProjection(int width, int height);
|
||
|
|
};
|