背景
问题:
源码:
以下是DXVA2解码源代码。
static int dxva2_retrieve_data(AVCodecContext *s, AVFrame *frame)
{
LPDIRECT3DSURFACE9 surface = (LPDIRECT3DSURFACE9)frame->data[3];
InputStream *ist = (InputStream *)s->opaque;
DXVA2Context *ctx = (DXVA2Context*)ist->hwaccel_ctx;
D3DSURFACE_DESC surfaceDesc;
D3DLOCKED_RECT LockedRect;
HRESULT hr;
int ret;
IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, D3DLOCK_READONLY);
if (FAILED(hr)) {
av_log(NULL, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");
return AVERROR_UNKNOWN;
}
picture->data[0] = (uint8_t*)LockedRect.pBits;
picture->data[1] = (uint8_t*)LockedRect.pBits + LockedRect.Pitch * surfaceDesc.Height;
frameWidth = frame->width;
frameHeight = frame->height;
//glFinish() <---- commentee suggestion
DWORD start = GetTickCount();//test time
Draw();//opengl draw
//glFinish() <---- commentee suggestion
DWORD end = GetTickCount();//test time
printf("draw time:%d\n", end - start);//test time
start = end - start;
picture->data[0] = nullptr;
picture->data[1] = nullptr;
IDirect3DSurface9_UnlockRect(surface);
return 0;
fail:
return ret;
}
下面是Draw函数的代码。
void Draw()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
glClearColor(0.0, 255, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(g_program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, g_texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, frameWidth, frameHeight, 0, GL_RED, GL_UNSIGNED_BYTE, picture->data[0]);
glUniform1i(y, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, g_texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, frameWidth / 2, frameHeight / 2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, picture->data[1]);
glUniform1i(uv, 1);
DrawHorizontal();
glBindVertexArray(0);
glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0);
}
问题:
谁能告诉我为什么相同的代码在不同的PC上有不同的结果? 或者给我一些建议?